def annotate_orfs(fa, seqs, threads, threshold = <NUM_LIT>):
db = '<STR_LIT>' % os.environ['<STR_LIT>']<EOL>base = fa.rsplit('<STR_LIT:.>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>out = '<STR_LIT>' % (base)<EOL>tblout = '<STR_LIT>' % (base)<EOL>orf2pfam = {} <EOL>if os.path.exists(tblout) is False:<EOL><INDENT>p = subprocess.Popen('<STR_LIT>'% (threads, tblout, out, db, fa), shell = True)<EOL>p.communicate()<EOL><DEDENT>for line in open(tblout):<EOL><INDENT>if line.startswith('<STR_LIT:#>'):<EOL><INDENT>continue<EOL><DEDENT>line = line.strip().split()<EOL>hit, id, e, inc = line[<NUM_LIT:0>], line[<NUM_LIT:2>], float(line[<NUM_LIT:4>]), int(line[<NUM_LIT>])<EOL>contig = id.split('<STR_LIT:_>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if e > threshold:<EOL><INDENT>continue<EOL><DEDENT>if contig not in orf2pfam:<EOL><INDENT>orf2pfam[contig] = {}<EOL><DEDENT>if id not in orf2pfam[contig]:<EOL><INDENT>orf2pfam[contig][id] = hit<EOL><DEDENT><DEDENT>for seq, info in list(seqs.items()):<EOL><INDENT>for insertion in info[<NUM_LIT:2>]:<EOL><INDENT>annotations = {}<EOL>for orf in insertion[<NUM_LIT:4>]:<EOL><INDENT>orf  = orf[<NUM_LIT:0>].split('<STR_LIT:>>')[<NUM_LIT:1>].split()[<NUM_LIT:0>]<EOL>contig = orf.split('<STR_LIT:_>', <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if contig in orf2pfam and orf in orf2pfam[contig]:<EOL><INDENT>annotations[orf] = orf2pfam[contig][orf]<EOL><DEDENT>else:<EOL><INDENT>annotations[orf] = '<STR_LIT>'<EOL><DEDENT><DEDENT>insertion.append(annotations)<EOL><DEDENT><DEDENT>return seqs<EOL>
search orfs against pfam
# seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, iseq, [orfs], [introns], orfs?, introns?, {orf: annotations}], ...]]