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
| import sys
f1 = open(sys.argv[1], 'r')
fannot = open('annot2.txt', 'w')
df1 = {}
for line in f1:
if line.startswith('#'): continue
tmp = line.replace('\n', '').split('\t')
# print tmp[8].split(';')
ch, feat, a, b = tmp[0], tmp[2], int(tmp[3]), int(tmp[4])
id = ''
pacid = ''
name = ''
parent = ''
for i in tmp[8].split(';'):
if 'ID' in i:
id = i[3:]
if 'pacid' in i:
pacid = i[6:]
if 'Name' in i:
name = i[5:]
if 'Parent' in i:
parent = i[7:]
df1.setdefault(ch,[]).append((id, feat, a, b, pacid, name, parent))
f2=open(sys.argv[2],'r')
for line in f2:
tmp = line.split('\t')
tr, ch, c, d = tmp[0], tmp[1], int(tmp[8]), int(tmp[9])
for id, feat, a, b, pacid, name, parent in df1.get(ch,()):
if a >= c and b <= d or a <= d and b >= d:
print '\t'.join((tr,id,feat,pacid,name,parent))
fannot.write('\t'.join((tr,id,feat,pacid,name,parent))) |
Partager