samtools view by chromosome region chr:1000-1001000 creates "unknown reference name" error
1
1
Entering edit mode
7.6 years ago
ariel.balter ▴ 260

I'm trying to create truncated versions of my bams for testing. The samtools docs say:

REGIONS:

Regions can be specified as: RNAME[:STARTPOS[-ENDPOS]] and all position coordinates are 1-based.

Important note: when multiple regions are given, some alignments may be output multiple times if they overlap more than one of the
  

specified regions.

Examples of region specifications:

chr1

    Output all alignments mapped to the reference sequence named `chr1' (i.e. @SQ SN:chr1). 
chr2:1000000

    The region on chr2 beginning at base position 1,000,000 and ending at the end of the chromosome. 
chr3:1000-2000

    The 1001bp region on chr3 beginning at base position 1,000 and ending at base position 2,000 (including both end positions).
  

This is what I'm trying:

for i in *.bam; do echo $i; name=${i%%.*}; echo $name; samtools view -b -h -1 -@ 4 $i chr2:1000-1001000 > $name_chr2-1000000-2000000.bam; done

I get the error:

[main_samview] region "chr2:1000-1001000" specifies an unknown reference name. Continue anyway.
samtools • 11k views
ADD COMMENT
9
Entering edit mode
7.6 years ago

there is no such chromosome "chr2" in the bam. try "2".

To get the list of chromosomes, try:

samtools view -H your.bam
ADD COMMENT
0
Entering edit mode

Yup! That did it. I thought I had tried that... Thanks!

ADD REPLY

Login before adding your answer.

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