Skip to content

Instantly share code, notes, and snippets.

@florin-chelaru
Created November 7, 2013 02:12
Show Gist options
  • Save florin-chelaru/7347794 to your computer and use it in GitHub Desktop.
Save florin-chelaru/7347794 to your computer and use it in GitHub Desktop.
import org.umd.assemblytest.readcoverage.samfile as sam
# Parse a file into a SamFile instance
samfile = sam.SamFile.read('../../../../../../tutorial/read_coverage/influenza-A.sam')
# In the background, the SamFile class partitions the alignments in the file
# by reference sequence, and organizes them in an IntervalTree, used for quick
# retrieval of overlaps.
# Compute the coverage of reference sequence '1' within the interval 1-100, and
# get all reads overlapping with it.
alns = samfile.coverage('1', 1, 100)
print 'Found {0} alignments overlapping with the given reference sequence. Here they are:'.format(len(alns))
for aln in alns:
print '{0}\t{1}\t{2}\t{3}'.format(aln.reference(), aln.start(), aln.end(), aln.qname())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment