Last active
December 31, 2015 19:09
-
-
Save nickloman/8031817 to your computer and use it in GitHub Desktop.
make_blobolog_file.py
This file contains hidden or 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
import sys | |
from collections import defaultdict | |
from itertools import izip_longest | |
def grouper(n, iterable, fillvalue=None): | |
args = [iter(iterable)] * n | |
return izip_longest(fillvalue=fillvalue, *args) | |
contigs = defaultdict(dict) | |
for ln in open(sys.argv[1]): | |
cols = ln.rstrip().split("\t") | |
if len(cols) > 1: | |
taxon = cols[0] | |
for level, tax, ignore in grouper(3, cols[1:]): | |
contigs[taxon][level] = tax | |
for ln in open(sys.argv[2]): | |
cols = ln.rstrip().split("\t") | |
if cols[1] in contigs and sys.argv[3] in contigs[cols[1]]: | |
cols.append(contigs[cols[1]][sys.argv[3]]) | |
else: | |
cols.append("Not annotated") | |
print "\t".join(cols) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment