-
Notifications
You must be signed in to change notification settings - Fork 0
/
concatenate_scores_for_R_graph.py
executable file
·60 lines (47 loc) · 1.62 KB
/
concatenate_scores_for_R_graph.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
53
54
55
56
57
58
59
60
#! /usr/bin/python
"""
User's Commands
\033[1mDESCRIPTION\033[0m
Concatenates score columns from 2 different files in
a single file that will be used to produce R graphs.
\033[1mUSAGE\033[0m
%program <scores_host> <score_comparison> <out_file>
\033[1mCREDITS\033[0m
DOC FUCKING PANTS \m/ 2013
"""
import sys
try:
in_host = sys.argv[1]
in_comparison = sys.argv[2]
out_file = sys.argv[3]
except:
print __doc__
sys.exit(2)
scores = {}
both_present = set()
with open(in_host, "rU") as in_f1:
with open(in_comparison, "rU") as in_f2:
for line in in_f1:
protein = line.split()[0]
scores[protein] = {}
line = line.strip()
score1 = line.split()[-1]
scores[protein]["species1"] = score1
print len(scores)
for line in in_f2:
protein = line.split()[0]
if protein in sorted(scores):
both_present.add(protein)
line = line.strip()
score2 = line.split()[-1]
scores[protein]["species2"] = score2
with open(out_file, "w") as out_f:
start = 0
for protein in sorted(scores):
if protein in both_present:
if start == 0:
out_f.write(protein + "\t" + scores[protein]["species1"] + "\t" + scores[protein]["species2"])
elif start > 0:
out_f.write("\n" + protein + "\t" + scores[protein]["species1"] + "\t" + scores[protein]["species2"])
start += 1
print "\n\033[1mJob done\n\033[0m"