how to split forward and reverse reads from sam file
1
0
Entering edit mode
4.1 years ago
Bioinfo ▴ 20

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

assembly alignment sequencing • 2.3k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Thank you very much for your answer i did this command to obtain unmapped reads

samtools view -h -f 4 nom_de_souche_Resultat.bam > nom_de_souche_Unmapped_reads.bam

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

ADD REPLY
1
Entering edit mode

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 bbmap software, that you can specificly configure to write out all kinds of read mapping results

ADD REPLY
0
Entering edit mode

Okay , thank you very much

ADD REPLY
0
Entering edit mode

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:

101010 Button

ADD REPLY
1
Entering edit mode
4.1 years ago
GenoMax 141k

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.
ADD COMMENT

Login before adding your answer.

Traffic: 2550 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