Skip to content

Instantly share code, notes, and snippets.

@nickloman
Last active December 31, 2015 19:09
Show Gist options
  • Save nickloman/8031817 to your computer and use it in GitHub Desktop.
Save nickloman/8031817 to your computer and use it in GitHub Desktop.
make_blobolog_file.py
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