Question: Extracting Reads by position
1
gravatar for michael.madans94
4.7 years ago by
michael.madans9410 wrote:

I have an alignment file for a protein encoded by about ~3000 bases (I have both bam and sam files), and I am looking to extract all the reads that from bases 877-981. Is there any way to do this with samtools?

I tried using this command:

samtools view 8.2alnCorrected.bam "877-981" > filteredreads.bam

However I got this message with an empty file:

region "877-981" specifies an unknown reference name. Continue anyway.
bam sam alignment • 3.2k views
ADD COMMENTlink modified 2.2 years ago by RamRS30k • written 4.7 years ago by michael.madans9410
1

Take a look at the manual to correctly specify the region (RNAME[:STARTPOS[-ENDPOS]]): http://www.htslib.org/doc/samtools.html

ADD REPLYlink written 4.7 years ago by genomax92k
1
gravatar for Chris Miller
4.7 years ago by
Chris Miller21k
Washington University in St. Louis, MO
Chris Miller21k wrote:

You need to specify the chromosome or contig as well. Your bam will have lines that look like:

chr1     12345    ...

So for reads are mapped to that chromosome or contig, you want:

samtools view 8.2alnCorrected.bam chr1:877-981
ADD COMMENTlink modified 2.2 years ago by RamRS30k • written 4.7 years ago by Chris Miller21k

It worked out.  Thanks Chris! 

ADD REPLYlink written 4.7 years ago by michael.madans9410

Glad to hear it!  Consider hitting the "Accept" button next to the answer - that lets anyone else who stumbles across this question find the solution easily.

ADD REPLYlink written 4.7 years ago by Chris Miller21k
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: 1299 users visited in the last hour