This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Entire Sequence from Bam File using Python Pysam Module

Hello there,

Is there away to be able to extract the entire chromosome sequence from the bam file using the Pysam Python module? I am trying to analyze the entire aligned sequence of some chromosome for instance chr1 from NGS.

Thanks a lot in advance.

alignment python pysam ngs

if you mean extracting the reads aligned to chr1 you can use

import pysam
samfile = pysam.AlignmentFile("your.bam", "rb")
for read in samfile.fetch('chr1', chr_beginning, chr_end):
          print read
samfile.close()

and if you want extract your chromosome in bam format using samtools

samtools index your.bam
samtools view -bh your.bam chr1  > small.bam

0 answers

No answers yet.

Log in to answer this question.