-
-
Save walterst/71b587c1eb7a90a69297 to your computer and use it in GitHub Desktop.
Use this script to add taxonomy strings to feature importance scores from OTU level data (see https://gist.github.com/walterst/2222618976a66b3fc8dd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# USAGE: python get_matching_taxa.py tab_sep_OTU_table feature_importance_file > feature_imp_with_taxa.txt | |
from sys import argv | |
otu_table = open(argv[1], "U") | |
otu_taxa = {} | |
for line in otu_table: | |
if line.startswith("#"): | |
continue | |
if len(line.strip()) == 0: | |
continue | |
curr_line = line.split("\t") | |
otu = curr_line[0] | |
taxa = curr_line[-1].strip() | |
otu_taxa[otu] = taxa | |
importance_table = open(argv[2], "U") | |
for line in importance_table: | |
curr_line = line.strip().replace('"', '').split('\t') | |
if line.startswith('"CCD"'): | |
print '%s\tTaxonomy' % line.strip() | |
continue | |
try: | |
print "%s\t%s" % ("\t".join(curr_line), otu_taxa[curr_line[0]].replace(" ", "")) | |
except KeyError: | |
print "%s\tNA" % "\t".join(curr_line) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment