This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split BAM file.

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

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.

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.

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

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

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?

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.

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

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

1 answer

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.

Log in to answer this question.