Skip to content

Instantly share code, notes, and snippets.

@adamrp
Created March 5, 2015 19:44
Show Gist options
  • Save adamrp/ccb08c74778bea2f7f1c to your computer and use it in GitHub Desktop.
Save adamrp/ccb08c74778bea2f7f1c to your computer and use it in GitHub Desktop.
Adds taxonomy level prefixes smilar to Greengenes' to RDP output
#!/usr/bin/env python
from sys import argv
prefixes = ['k__', 'p__', 'c__', 'o__', 'f__', 'g__', 's__']
with open(argv[1], 'U') as input_f, open(argv[2], 'w') as output_f:
for line in input_f:
otu_id, tax, p = line.strip().split('\t')
tax = '; '.join([''.join(x) for x in zip(prefixes, tax.split(';'))])
output_f.write('\t'.join([otu_id, tax, p]) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment