Skip to content

Instantly share code, notes, and snippets.

@meren
Created October 1, 2012 20:11
Show Gist options
  • Save meren/3814127 to your computer and use it in GitHub Desktop.
Save meren/3814127 to your computer and use it in GitHub Desktop.
Generate ENVIRONMENT from VAMPS Matrix that was converted from BIOM format...
import sys
matrix = open(sys.argv[1])
env = open(sys.argv[1] + '.ENV', 'w')
matrix.readline()
samples = matrix.readline().strip().split('\t')[1:]
for line in matrix.readlines():
fields = line.strip().split('\t')
taxon = fields[0].strip()
counts = [int(float(x)) for x in fields[1:]]
for i in range(0, len(counts)):
if counts[i]:
env.write('%s\t%s\t%d\n' % (taxon, samples[i], counts[i]))
env.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment