forked from bio-ontology-research-group/phenogocon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
177 lines (158 loc) · 4.41 KB
/
main.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <deque>
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <sstream>
#include <utility>
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
using namespace std;
int main()
{
int num_threads = 48;
string original = "sim_original/";
string combined = "sim_combined/";
string solo = "sim_solo/";
vector<string> folders = { original, combined, solo };
string line;
stringstream ss;
map<string, map<int, vector<pair<double, int> > > > file_to_matrix;
// maps filename to matrix
// matrix maps omim to vector of pairs of (score, gene)
map<string, set<pair<int, int> > > file_to_set;
// maps filename to set of (gene, disease) pairs
// read morbid map
map<int, int> morbid_gene_to_disease;
cout << "Reading morbidmap..." << endl;
ifstream morbidmap("morbidmap.txt", ios::in);
while (getline(morbidmap, line))
{
// check if comment
if (line[0] == '!' || line[0] == '#')
continue;
// read tab-separated line into tokens
istringstream iss(line);
string token;
vector<string> tokens;
while (getline(iss, token, '\t'))
tokens.push_back(token);
// read disease OMIM
size_t pos1 = tokens[0].rfind(',');
size_t pos2 = tokens[0].rfind('(');
ss = stringstream(tokens[0].substr(pos1 + 1, pos2));
int disease;
ss >> disease;
// read gene OMIM
int gene;
ss = stringstream(tokens[2]);
ss >> gene;
// add gene, diease to map
morbid_gene_to_disease[gene] = disease;
}
morbidmap.close();
// map symbols to omims
map<string, int> symbol_to_omim;
cout << "Mapping symbols to omims..." << endl;
ifstream mousehumanseq("HOM_MouseHumanSequence.rpt", ios::in);
while (getline(mousehumanseq, line))
{
// read tab-separated line into tokens
istringstream iss(line);
string token;
vector<string> tokens;
while (getline(iss, token, '\t'))
tokens.push_back(token);
if (tokens[1].find("human") != string::npos)
{
string symbol = tokens[3];
int gene;
ss = stringstream(tokens[7]);
ss >> gene;
symbol_to_omim[symbol] = gene;
}
}
mousehumanseq.close();
//table = dict()
//table_width = 0
//
//print "Building queue of tasks..."
//q = multiprocessing.JoinableQueue()
//out_q = multiprocessing.Queue()
//
//for root, dirs, filenames in os.walk(solo) :
// for filename in filenames :
//q.put(filename)
//
//print "Queue has %d tasks" % q.qsize()
//
//def worker(q, output_queue) :
// while True :
// filename = q.get()
// if q.qsize() % 500 == 0 :
// print "%d omim's left in queue" % q.qsize()
// with open(indir + filename) as f :
//omim = filename.strip(".txt")
//row = []
//for line in f :
//tabs = line.strip().split('\t')
//if len(tabs) < 2 :
// continue
// name = tabs[0].split()[0] # in case of weird duplication in first column
// if "ENTREZ" in name :
//name = name.replace("ENTREZ:", "")
// else:
// if name in human_symbol_to_entrez :
// name = human_symbol_to_entrez[name]
// else :
// continue
// score = float(tabs[1])
// row.append((score, name))
// closed = set()
// temp = []
// for pair in row :
// if pair[1] in closed :
// continue
// closed.add(pair[1])
// temp.append(pair)
// temp.sort(reverse = True)
// output_queue.put((omim, temp))
// q.task_done()
//
// lock = multiprocessing.Lock()
// manager = multiprocessing.Manager()
// for i in range(num_procs) :
// t = multiprocessing.Process(target = worker, args = (q, out_q, ))
// t.daemon = True
// t.start()
// q.join()
//
// print "Tasks completed"
// while out_q.qsize() > 0:
// (omim, row) = out_q.get()
// table_width = max(table_width, len(row))
// table[omim] = row
//
//
// print "Calculating rates..."
// true_pos_rate = 0.0
// with open("output.txt", 'w') as g :
// for rank in range(table_width) :
// total = 0
// true_pos = 0
// for omim in table :
// if len(table[omim]) < rank + 1 :
// continue
// total += 1
// entrez = table[omim][rank][1]
// if omim in morbid_omim_to_entrez and entrez == morbid_omim_to_entrez[omim] :
// true_pos += 1
// # print omim, entrez
// true_pos_rate += (float(true_pos) / total)
// result = "%d\t%f\n" % (rank + 1, true_pos_rate)
// # print result
// g.write(result)
return 0;
}