Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
chrosome sizes
#!/usr/bin/env python
import os
import sys
if len(sys.argv) != 2:
print "Usage %s: samtools_index" % os.path.basename(sys.argv[0])
samtools_index = sys.argv[1]
with open(samtools_index) as f:
prev_chrom = None
prev_size = 0
for line in f:
cols = line.split('\t')
chrom = cols[0]
chrom_size = int(cols[1])
if chrom[-1].isdigit():
if prev_size:
length_diff = prev_size - chrom_size
if length_diff < 0:
print "%s longer than %s by %d bases!" % (chrom, prev_chrom, -length_diff)
prev_chrom = chrom
prev_size = chrom_size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment