-
Notifications
You must be signed in to change notification settings - Fork 15
/
rexp_annot.py
executable file
·52 lines (41 loc) · 1.02 KB
/
rexp_annot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import sys
from Bio import SeqIO
print "Usage: rexp_annot.py RexpFastaFile AnnotationFile [Unknown]"
try:
ff = sys.argv[1]
except:
ff = raw_input("Introduce FASTA file from RepeatExplorer assembly: ")
try:
aa = sys.argv[2]
except:
aa = raw_input("Introduce Annotation File: ")
try:
uu = sys.argv[3]
except:
uu = ""
annots = open(aa).readlines()
annotations = {}
for annot in annots:
annot = annot.split()
if len(annot) > 0:
cl = annot[0]
try:
fam = annot[1]
annotations[cl] = fam
except:
pass
if uu == "Unknown":
out = open(ff+".annot.unknown", "w")
else:
out = open(ff+".annot", "w")
seqs = SeqIO.parse(open(ff), "fasta")
for s in seqs:
name = s.id
cluster = name.split("Contig")
cluster = cluster[0]
if cluster in annotations:
out.write(">%s#%s\n%s\n" % (name,annotations[cluster],str(s.seq)))
elif uu == "Unknown":
out.write(">%s#Unknown\n%s\n" % (name,str(s.seq)))
out.close()