-
Notifications
You must be signed in to change notification settings - Fork 0
/
best_match.py
33 lines (27 loc) · 956 Bytes
/
best_match.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
import argparse
from collections import defaultdict
parser = argparse.ArgumentParser()
parser.add_argument("-n", help = "please give an output name, eg. ENCFF758RQJ", required = True)
parser.add_argument("-input_file", help = "fimo out results", required = True)
parser.add_argument("-output", help = "output dir", required = True)
args = parser.parse_args()
biosample = args.n
input_file = args.input_file
output = args.output
dic = defaultdict(list)
with open(input_file) as f:
for line in f:
line = line.strip()
pos = line.split('\t')[2]
dic[pos].append(line)
new = open(output + '/' + biosample + '_best.txt', 'w')
for pos in dic:
max_score = float(dic[pos][0].split('\t')[6])
max_mess = dic[pos][0]
for message in dic[pos]:
score = float(message.split('\t')[6])
if score > max_score:
max_score = score
max_mess = message
new.write(max_mess + '\n')
new.close()