This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error samtools: AssertionError: chromosome not in SAM references:

Hello,

I have an error when running my code: AssertionError: chromosome not in SAM references: >gi|11|ref|E1E2J6

However, when I opened the sam file the reference is clearly there:

@SQ SN:gi|11|ref|E1E2J6 LN:1677

@PG ID:bwa  PN:bwa  VN:0.7.17-r1188 CL:bwa mem -t 4 -v 1 E1E2J6.fasta HCV-19-108_S7_L001_R1_001_val_1.fq.gz HCV-19-108_S7_L001_R2_001_val_2.fq.gz

This is my code:

import pysam
import pysamstats

bamfile = pysam.AlignmentFile('picared.bam')
print("P"),
print ("A"),
print ("C"),
print ("G"),
print ("T"),
print ("I"),
print ("D")
for record in pysamstats.stat_variation(bamfile, chrom='>gi|11|ref|E1E2J6', fafile="E1E2J6.fasta"):
    print(record['pos']),
    print(record['A']),
    print(record['C']),
    print(record['G']),
    print(record['T']),
    print(record['insertions']),
    print(record['deletions'])

Does anyone have an experience with this?

Thank you

next-gen

1 answer

I think you want

 chrom='gi|11|ref|E1E2J6'

not

 chrom='>gi|11|ref|E1E2J6'

Log in to answer this question.