Skip to content

Instantly share code, notes, and snippets.

@davmlaw
Created June 2, 2014 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davmlaw/b9bd7eb729a6eb240d99 to your computer and use it in GitHub Desktop.
Save davmlaw/b9bd7eb729a6eb240d99 to your computer and use it in GitHub Desktop.
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])
sys.exit(1)
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