Question: How to extract reads from bam file?
0
gravatar for silas008
12 months ago by
silas008100
Brazil
silas008100 wrote:

Hi, guys!

I am trying to extract some reads that aligned in specific regions of the mitochondrial genome. I want to know what is the length of these reads, so I need to extract them before to measure, to avoid the measurement of other reads the aligned in other regions.

I did it by different ways, the last one was:

samtools view -bh original_sorted.bam chrM:1-55 > output.bam

(many times for different regions)

Then:

samtools merge merged.bam *.bam
samtools sort merged.bam > sorted.bam
samtools index sorted.bam

But I can't open the sorted.bam file on genome browser and when I try to transform it into a fastq I see this message:

[M::bam2fq_mainloop] processed 0 reads

The original_sorted.bam is ok. I can visualize the data and there are a lot of reads in the regions that I want to do the measurement.

Thanks, guys!!!

rna-seq alignment • 730 views
ADD COMMENTlink modified 12 months ago by RamRS23k • written 12 months ago by silas008100

Hi, did you check if there is reads on your output.bam ?

ADD REPLYlink written 12 months ago by Titus890

Now i am using -L option and a bed file and the output.bam is ok. There are a lot of reads.

Thanks

ADD REPLYlink written 12 months ago by silas008100
samtools merge merged.bam *.bam

*.bam may pickup merged.bam as well. Try outputting some where outside the current directory @ silas008

ADD REPLYlink written 12 months ago by cpad011211k

I really didn't know why this was not working. I will try your suggestion.

Thanks

ADD REPLYlink written 12 months ago by silas008100
2
gravatar for finswimmer
12 months ago by
finswimmer12k
Germany
finswimmer12k wrote:

Hello silas008,

some questions and hints about this:

  • What version of samtools are you using?
  • If you want to extract multiple regions, you can define those regions in a bed file and use the -L option for samtools view. So there is no need to merge many file afterwards.
  • How should your desired output look like? Depending on this there is a good chance that you don't have to make in intermediate bam file.
  • Please use the formatting bar (especially the code option) to present your post better. I've done it for you this time.
    code_formatting

Thank you!

fin swimmer

ADD COMMENTlink modified 12 months ago • written 12 months ago by finswimmer12k

First of all, thank you for helpping.

I am sorry for the formatting, I am not so familiar with Biostars. I didn't know there is a code formatting bar. I will use it in next posts.

I am using Samtools version 1.4 and the option -L worked very well for me. I didn't know what I was doing wrong before but with -L option the output.bam is perfect.

Thank you very much

ADD REPLYlink written 12 months ago by silas008100
1

Hello again,

there's no need to say sorry. There are a lot of people who aren't aware of the formatting bar. That's why I'm pointing to it.

If you can do, I would recommend update samtools to the current version (v1.9).

fin swimmer

ADD REPLYlink written 12 months ago by finswimmer12k

I will do that.

Thanks again

ADD REPLYlink written 12 months ago by silas008100
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: 1603 users visited in the last hour