how to split forward and reverse reads from sam file
Hello everyone,
I have question please
I have bam file containing unmapped reads that I want to assemble.
I tried samtools fastq to obtain the two files forward and reverse
I did this command
samtools fastq -1 wPru_1_Unmapped_reads.fastq -2 wPru_2_Unmapped_reads.fastq wPru_Unmapped_reads.bam
but when I wanted to perform the assembly (shovill) it didn't work it shows that the number of forward is larger than the number of reverse reads
The number of left read-pairs is larger than the number of right read-pairs
my objective now is how to extract forward and reverse reads from bam file
Thank you very much
• 3,274 views
•
link
1 answer
As noted by @lieven you could use reformat.sh from BBMap suite..
reformat.sh in=your.sam out1=R1.fq out2=R2.fq
Consider following additional options to add :
mappedonly=f Toss unmapped reads.
unmappedonly=f Toss mapped reads.
pairedonly=f Toss reads that are not mapped as proper pairs.
unpairedonly=f Toss reads that are mapped as proper pairs.
primaryonly=f Toss secondary alignments. Set this to true for sam to fastq conversion.
• 0 views
•
link
Log in to answer this question.
How did you obtain the bam file with unmapped reads?
What I suspect is that in the unaligned bam file there will be reads pairs for which one is mapped and the other not , and if the bam was created not taking this into account it might not work the split them in equal numbers.
Thank you very much for your answer i did this command to obtain unmapped reads
i save all the files so i can fix the error in any step i mapped my reads against the eference using bowtie2 after that i ransfer the sam file to bam file and i extracted the unmapped reads from bam file then ai tranformed bam file to two fastq files using the command in the question
A small educational note: I added (code) markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:
don't know the specifics from the top of my head but I don't think that the samtools cmdline will do this correctly. If will process all reads as separate entities (so not taking the PE info into account).
alternatively have a look at the
bbmapsoftware, that you can specificly configure to write out all kinds of read mapping resultsOkay , thank you very much