Split BAM file.
1
0
Entering edit mode
6.4 years ago
jaqx008 ▴ 110

Hello all. I am new to bioinformatics and needing some help. I have a Bam file generated from fastq, In the command I used, a sorted bam file is supposed to be created but I keep getting errors. I am trying to split the BAM file (about 50GB) into several Bam files so I can sort it separately. But I don't know how to go about this. (I am a beginner ). Any help would be appreciated, Thanks (Peter).

next-gen alignment • 6.5k views
ADD COMMENT
2
Entering edit mode

Please provide details of exactly what programs you have run, what error messages you are getting, and what you have attempted. It is very difficult to assist without details.

ADD REPLY
0
Entering edit mode

Thanks Samantha. here is the command I Ran.

bowtie2 -x /Users/jay/Desktop/pavelAssemblyBowtieIndex/pavelAssembly \
    -1 /Volumes/500GB/Illumina_Run_814/Run_814/Project_klimov/Sample_28017/28017_GTCCGC_L006_R1.fastq \
    -2 /Volumes/500GB/Illumina_Run_814/Run_814/Project_klimov/Sample_28017/28017_GTCCGC_L006_R2.fastq \
    -S dustMapping.sam && \
samtools view -b dustMapping.sam -o dustMapping.bam && \
samtools sort dustMapping.bam -o dustMapping.sorted.bam && \
samtools index dustMapping.sorted.bam dustMapping.sorted.bam.bai && \
rm dustMapping.sam && dustMapping.bam

the error message I can't recall exactly but it always can't sort the bam when it gets to that step.

ADD REPLY
0
Entering edit mode

Hi,

As recommended by Cameron, you should also provide the details of the error message you gets during your process.

You can look for this SAM to BAM conversion command, I believe that your bowtie2 process is generating SAM file in proper format. The command mentioned below should generate a proper BAM file for your sorting process.

samtools view -bS dustMapping.sam -o dustMapping.bam

Thanks

ADD REPLY
0
Entering edit mode

Thank you samantha. all this is still new to me. so if I run the command $ samtools view -bS dustMapping.sam -o dustMapping.bam will the sorted bam file be generated? or just the BAM? another thing is that my sam file is huge (100+ GB) and this might not be good for generating the sorted BAM file. please suggest a command I can use to split the SAM into smaller sam files and also a command to convert all sam files into sorted bam and merge this into one BAM file. please if this is not too much trouble for you, help me. Thanks

ADD REPLY
0
Entering edit mode

the -S of samtools is not necessary: input type is detected automatically.

To generate a sorted bam from the file alignment.bam:

samtools sort -o sortedalignment.bam alignment.bam

Samfiles are pretty big, but that shouldn't be a problem.

And who is Samantha?

ADD REPLY
0
Entering edit mode

My bad. I was referring to a reader above named Samarth. Do you mean I should use the .BAM I have? and if yes, the command above don't specify input. and thats a little confusing. (Im a beginner). Thanks Wouter.

ADD REPLY
0
Entering edit mode

I don't understand what you mean with command doesn't specify input.

ADD REPLY
0
Entering edit mode

There are introductions to bam-files and SAM-tools:

https://www.ncbi.nlm.nih.gov/tools/gbench/tutorial6/

http://samtools.github.io/hts-specs/SAMv1.pdf

Here you will find how to split your file (read the whole post and pay attention to the right panel - there may be similar

posts there ):

How Can I Split Bam Into Chromosome (In A Loop) Using Samtools?

A post about sorting:

Is My Bam File Sorted ?

ADD REPLY
0
Entering edit mode

Thank you Natasha. will look and get back with you if it helped.

ADD REPLY
1
Entering edit mode
6.4 years ago

Hi, You can also explore BamTools toolkit with "split" option.

usage: bamtools [--help] COMMAND [ARGS]

Available bamtools commands:

convert              Converts between BAM and a number of other formats
count                Prints number of alignments in BAM file(s)
coverage             Prints coverage statistics from the input BAM file
filter               Filters BAM file(s) by user-specified criteria
header               Prints BAM header information
index                Generates index for BAM file
merge                Merge multiple BAM files into single file
random               Select random alignments from existing BAM file(s), intended more as a testing tool.
resolve             Resolves paired-end reads (marking the IsProperPair flag as needed)
revert              Removes duplicate marks and restores original base qualities
sort                Sorts the BAM file according to some criteria
***split             Splits a BAM file on user-specified property, creating a new BAM output file for each value found***
stats            Prints some basic statistics from input BAM file(s)

Hope this helps.

ADD COMMENT

Login before adding your answer.

Traffic: 2254 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6