Question: Split BAM file.
0
gravatar for jaqx008
20 months ago by
jaqx00850
jaqx00850 wrote:

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).

alignment next-gen • 1.6k views
ADD COMMENTlink modified 20 months ago by Samarth Kulshrestha190 • written 20 months ago by jaqx00850
2

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 REPLYlink written 20 months ago by d-cameron2.1k

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 REPLYlink modified 4 months ago by RamRS23k • written 20 months ago by jaqx00850

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 REPLYlink modified 4 months ago by RamRS23k • written 20 months ago by Samarth Kulshrestha190

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 REPLYlink written 20 months ago by jaqx00850

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 REPLYlink written 20 months ago by WouterDeCoster40k

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 REPLYlink written 20 months ago by jaqx00850

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

ADD REPLYlink written 20 months ago by WouterDeCoster40k

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 REPLYlink modified 20 months ago • written 20 months ago by natasha.sernova3.5k

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

ADD REPLYlink written 20 months ago by jaqx00850
0
gravatar for Samarth Kulshrestha
20 months ago by
India
Samarth Kulshrestha190 wrote:

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 COMMENTlink modified 20 months ago • written 20 months ago by Samarth Kulshrestha190
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1461 users visited in the last hour