Question: Retrieve The Reads And Fastq From Bam File
5
gravatar for rehma.ar
7.7 years ago by
rehma.ar240
rehma.ar240 wrote:

hello everyone!

i am using this command

samtools view -bh -F 2 FILE.bam mt > out.bam

to get the discordant reads(one end aligns to mitochondria and the other to chromosome) and also those reads that align to (both ends) mitochondria only. out put file is a bam file. but when i want get fastq out of this bam file using command

bamToFastq -i out.bam -fq out.1.fq -fq2 out.2.fq

it shows that there are so many reads that are marked as pairs but the but the other pair is not in the bam file. the error looks like this

*WARNING: Query HWI-ST170_235:2:22:12110:179082#0 is marked as paired, but it's mate does not occur next to it in your BAM file. Skipping.

can anyone plz tell what,s going wrong.

samtools • 11k views
ADD COMMENTlink modified 17 days ago by millerh130 • written 7.7 years ago by rehma.ar240

I had this issue and it turned out to just be multimapped reads which produced the error.

ADD REPLYlink modified 17 days ago • written 17 days ago by millerh130
4
gravatar for thomas.wentworth
5.2 years ago by
thomas.wentworth40 wrote:

I also had this error message, and the problem in my case was that my bam file wasn't sorted by read names.  To fix the issue I did the following:
 

1. Sort your bam file by read names:

samtools sort -n myBamFile.bam myBamFile.sortedByName

note: if you now examine your new bam file ( samtools view myBamFile.sortedByName | less -S ), you should see that it is sorted by read names and that read pairs are next to each other.

2. Run bamtofastq on your new bam file

bamToFastq -i myBamFile.sortedByName.bam -fq out.1.fq -fq2 out.2.fq


 

 

ADD COMMENTlink written 5.2 years ago by thomas.wentworth40

Hi, I sorted my unmapped .bam files using samtools and got the my_file_unmapped.qsort files using the command $ samtools sort -n my_file_unmapped.bam -o my_file_unmapped.qsort -O BAM But, now when I am trying to run bedtools bamtofastq, it is returning similar warning, WARNING: Query is marked as paired, but its mate does not occur next to it in your BAM file.

ADD REPLYlink written 3.9 years ago by mirza110

I am getting this same warning message on namesorted BAM file. I think the issue has to do with multi-mapping reads. bedtools seems to be giving a warning for any multi-mapping read that isn't immediately adjacent to its paired read (like a multi-mapper next to another line with itself mapped to another genomic location). It does look like the reads are ending up in the FASTQ file when both pairs are present, but these warning messages are pretty annoying. I'm guessing this is a bug (/feature) in bedtools.

ADD REPLYlink written 3.8 years ago by mstoiber0

Not sure this has to do with multi-mapping reads. I've tried filtering out multimapping reads from bwa-generated bams (samtools view -bq 1 bam_file) but the issue recurs regardless.

ADD REPLYlink written 3.7 years ago by Srihari30

This answer is wrong and doesn't work. Don't use it.

ADD REPLYlink written 3.6 years ago by SmallChess510
1
gravatar for Ido Tamir
7.7 years ago by
Ido Tamir5.1k
Austria
Ido Tamir5.1k wrote:

bamToFastq wants paired end reads to be adjacent to each other. Otherwise either the rows in the fastq files don't match or the program would have to memoize all the reads it encountered until the pair closes or it would have to reread the file multiple times.

If you don't have each read followed by its pair (the bam file is sorted by name) because you have discordant pairs filtered then you have write your own program or find one that does not have this restrictions and produces either 2 unpaired fastq files or inserts some placeholder read where the pair is absent.

ADD COMMENTlink modified 7.7 years ago • written 7.7 years ago by Ido Tamir5.1k

thanks a lot for the suggestion, i have used Hydra to get fastq from bam. seems works perfectly.

ADD REPLYlink written 7.7 years ago by rehma.ar240
1
gravatar for swbarnes2
7.7 years ago by
swbarnes27.9k
United States
swbarnes27.9k wrote:

samtools view -bh -F 2 FILE.bam mt > out.bam

I would worry about that getting all kinds of discordant reads, not just the ones you want.

You can filter for -F12 with samtools, Then filter with awk, or some script, for reads where either the mapped chromsoome or the mate chromosome is MT.

ADD COMMENTlink written 7.7 years ago by swbarnes27.9k

but don't you think using "mt" would only get those discordant reads where either the mapped chromsoome or the mate chromosome is MT. i also need those reads where "$3 = MT" and "$7 eq =". i think this command would work perfectly. if you don't agree plz tell me how?

ADD REPLYlink written 7.7 years ago by rehma.ar240
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: 1098 users visited in the last hour