This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Reconstruct reference sequence from SAM file?

I am aligning a consensus sequence to a reference genome using Bowtie2 and I am interested in the nucleotide sequence of the reference where the consensus sequence aligned. Is it possible to infer the reference sequence using only information in the SAM file such as the CIGAR and MD strings? Thanks!

sam

1 answer

Based on your alignment you can get the chromosome, start and end of where your consensus sequence aligns. You can use these coordinates with samtools faidx

samtools faidx yourgenome.fa chr1:123456-789101

I think OP only want the sequence from the BAM, not the REF.

I am looking for the sequence in the reference that the query aligned to

Thank you, this is what I am looking for. Would this be faster than building an indexed BLAST database and then using blastdbcmd to accomplish the same task?

Log in to answer this question.