1 | #include <arbdb.h> |
---|
2 | #include <PT_com.h> |
---|
3 | #include <client.h> |
---|
4 | |
---|
5 | #include <iostream> |
---|
6 | |
---|
7 | using std::cerr; |
---|
8 | using std::endl; |
---|
9 | |
---|
10 | void help() { |
---|
11 | cerr << |
---|
12 | "Executes a probe match on a running PT server\n" |
---|
13 | "\n" |
---|
14 | "Parameters:\n" |
---|
15 | "\n" |
---|
16 | " --db <FILE> ARB file\n" |
---|
17 | " --port <PORT> port of PT server\n" |
---|
18 | " --sequence <SEQUENCE> probe\n" |
---|
19 | " --reversed reverse probe before matching\n" |
---|
20 | " --complement complement probe before matching\n" |
---|
21 | " --max-hits <N> maximum number of hits on db (1,000,000)\n" |
---|
22 | " --weighted use weighted matching\n" |
---|
23 | " --weighted-pos use weighted matching with pos&strength\n" |
---|
24 | " --n-matches <N> consider N occurrences of 'N' as match (2)\n" |
---|
25 | " --n-match-bound <N> abover N occurancse of 'N', consider all as mismatch (5)\n" |
---|
26 | " --mismatches <N> allowed mismatches (0)\n" |
---|
27 | |
---|
28 | << endl; |
---|
29 | } |
---|
30 | |
---|
31 | enum SORT_BY_TYPE { |
---|
32 | SORT_BY_MISMATCHES = 0, |
---|
33 | SORT_BY_WEIGHTED_MISMATCHES = 1, |
---|
34 | SORT_BY_WEIGHTED_MISMATCHES_W_POS_AND_STRENGTH = 2 |
---|
35 | }; |
---|
36 | |
---|
37 | int ARB_main(int argc, char ** argv) { |
---|
38 | const char* port = NULp; |
---|
39 | const char* sequence = NULp; |
---|
40 | int reversed = 0; |
---|
41 | int complement = 0; |
---|
42 | int max_hits = 1000000; |
---|
43 | SORT_BY_TYPE sort_by = SORT_BY_MISMATCHES; |
---|
44 | int n_accept = 2; |
---|
45 | int n_limit = 5; |
---|
46 | int max_mismatches = 0; |
---|
47 | |
---|
48 | GB_shell shell; |
---|
49 | |
---|
50 | if (argc<2) { |
---|
51 | help(); |
---|
52 | return 0; |
---|
53 | } |
---|
54 | |
---|
55 | for (int i = 1; i < argc; i++) { |
---|
56 | int err = 0; |
---|
57 | if (!strcmp(argv[i], "--help")) { |
---|
58 | help(); |
---|
59 | return 0; |
---|
60 | } else if (!strcmp(argv[i], "--reversed")) { |
---|
61 | reversed = 1; |
---|
62 | } else if (!strcmp(argv[i], "--complement")) { |
---|
63 | complement = 1; |
---|
64 | } else if (!strcmp(argv[i], "--weighted")) { |
---|
65 | sort_by = SORT_BY_WEIGHTED_MISMATCHES; |
---|
66 | } else if (!strcmp(argv[i], "--weighted-pos")) { |
---|
67 | sort_by = SORT_BY_WEIGHTED_MISMATCHES_W_POS_AND_STRENGTH; |
---|
68 | } else if (argc > i+1) { |
---|
69 | if (!strcmp(argv[i], "--port")) { |
---|
70 | port = argv[++i]; |
---|
71 | } else if (!strcmp(argv[i], "--sequence")) { |
---|
72 | sequence = argv[++i]; |
---|
73 | } else if (!strcmp(argv[i], "--max-hits")) { |
---|
74 | max_hits = atoi(argv[++i]); |
---|
75 | } else if (!strcmp(argv[i], "--n-matches")) { |
---|
76 | n_accept = atoi(argv[++i]); |
---|
77 | } else if (!strcmp(argv[i], "--n-match-bound")) { |
---|
78 | n_limit = atoi(argv[++i]); |
---|
79 | } else if (!strcmp(argv[i], "--mismatches")) { |
---|
80 | max_mismatches = atoi(argv[++i]); |
---|
81 | } else { |
---|
82 | err = 1; |
---|
83 | } |
---|
84 | } else { |
---|
85 | err = 1; |
---|
86 | } |
---|
87 | if (err) { |
---|
88 | cerr << "Error: Did not understand argument '" << argv[i] |
---|
89 | << "'." << endl << endl; |
---|
90 | help(); |
---|
91 | return 1; |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | bool err = false; |
---|
96 | |
---|
97 | if (!port) { |
---|
98 | cerr << "need '--port' parameter" << endl; |
---|
99 | err = true; |
---|
100 | } |
---|
101 | if (!sequence) { |
---|
102 | cerr << "need '--sequence' parameter" << endl; |
---|
103 | err = true; |
---|
104 | } |
---|
105 | if (max_mismatches < 0 || max_mismatches > 10) { |
---|
106 | cerr << "mismatches must be between 0 and 10" << endl; |
---|
107 | err = true; |
---|
108 | } |
---|
109 | if (err) { |
---|
110 | help(); |
---|
111 | return 1; |
---|
112 | } |
---|
113 | |
---|
114 | T_PT_LOCS locs; |
---|
115 | T_PT_MAIN com; |
---|
116 | GB_ERROR error = NULp; |
---|
117 | aisc_com *link = aisc_open(port, com, AISC_MAGIC_NUMBER, &error); |
---|
118 | if (!link) { |
---|
119 | cerr << "Cannot contact PT server (" << error << ')' << endl; |
---|
120 | return 1; |
---|
121 | } |
---|
122 | |
---|
123 | if (aisc_create(link, PT_MAIN, com, |
---|
124 | MAIN_LOCS, PT_LOCS, locs, |
---|
125 | NULp)) { |
---|
126 | cerr << "Cannot create PT LOCS structure" << endl; |
---|
127 | return 1; |
---|
128 | } |
---|
129 | |
---|
130 | if (aisc_nput(link, PT_LOCS, locs, |
---|
131 | LOCS_MATCH_REVERSED, (long)reversed, |
---|
132 | LOCS_MATCH_COMPLEMENT, (long)complement, |
---|
133 | LOCS_MATCH_MAX_HITS, (long)max_hits, |
---|
134 | LOCS_MATCH_SORT_BY, (long)sort_by, |
---|
135 | LOCS_MATCH_N_ACCEPT, (long)n_accept, |
---|
136 | LOCS_MATCH_N_LIMIT, (long)n_limit, |
---|
137 | LOCS_MATCH_MAX_MISMATCHES, (long)max_mismatches, |
---|
138 | LOCS_SEARCHMATCH, sequence, |
---|
139 | NULp)) { |
---|
140 | cerr << "Connection to PT server lost" << endl; |
---|
141 | return 1; |
---|
142 | } |
---|
143 | |
---|
144 | T_PT_MATCHLIST match_list; |
---|
145 | |
---|
146 | long match_list_cnt = 0; |
---|
147 | long matches_truncated = 0; |
---|
148 | |
---|
149 | bytestring bs; |
---|
150 | bs.data = NULp; |
---|
151 | |
---|
152 | char *locs_error = NULp; |
---|
153 | |
---|
154 | aisc_get(link, PT_LOCS, locs, |
---|
155 | LOCS_MATCH_LIST, match_list.as_result_param(), |
---|
156 | LOCS_MATCH_LIST_CNT, &match_list_cnt, |
---|
157 | LOCS_MATCH_STRING, &bs, |
---|
158 | LOCS_MATCHES_TRUNCATED, &matches_truncated, |
---|
159 | LOCS_ERROR, &locs_error, |
---|
160 | NULp); |
---|
161 | if (locs_error) { |
---|
162 | cerr << "received error: " << locs_error << endl; |
---|
163 | free(locs_error); |
---|
164 | } |
---|
165 | |
---|
166 | if (matches_truncated) { |
---|
167 | std::cout << "match list was truncated!" << endl; |
---|
168 | } |
---|
169 | |
---|
170 | std::cout << "acc \t" |
---|
171 | << "start\t" |
---|
172 | << "stop\t" |
---|
173 | << "pos\t" |
---|
174 | << "mis\t" |
---|
175 | << "wmis\t" |
---|
176 | << "nmis\t" |
---|
177 | << "dt\t" |
---|
178 | << "rev\t" |
---|
179 | << "seq" |
---|
180 | << std::endl; |
---|
181 | |
---|
182 | while (match_list.exists()) { |
---|
183 | char *m_acc, *m_sequence; |
---|
184 | long m_start, m_stop, m_pos, m_mismatches, m_n_mismatches; |
---|
185 | long m_reversed; |
---|
186 | double m_wmismatches, m_dt; |
---|
187 | |
---|
188 | aisc_get(link, PT_MATCHLIST, match_list, |
---|
189 | MATCHLIST_FIELD_ACC, &m_acc, |
---|
190 | MATCHLIST_FIELD_START, &m_start, |
---|
191 | MATCHLIST_FIELD_STOP, &m_stop, |
---|
192 | MATCHLIST_POS, &m_pos, |
---|
193 | MATCHLIST_MISMATCHES, &m_mismatches, |
---|
194 | MATCHLIST_WMISMATCHES, &m_wmismatches, |
---|
195 | MATCHLIST_N_MISMATCHES, &m_n_mismatches, |
---|
196 | MATCHLIST_DT, &m_dt, |
---|
197 | MATCHLIST_OVERLAY, &m_sequence, |
---|
198 | MATCHLIST_REVERSED, &m_reversed, |
---|
199 | MATCHLIST_NEXT, match_list.as_result_param(), |
---|
200 | NULp); |
---|
201 | |
---|
202 | std::cout << m_acc << "\t" |
---|
203 | << m_start << "\t" |
---|
204 | << m_stop << "\t" |
---|
205 | << m_pos << "\t" |
---|
206 | << m_mismatches << "\t" |
---|
207 | << m_wmismatches << "\t" |
---|
208 | << m_n_mismatches << "\t" |
---|
209 | << m_dt << "\t" |
---|
210 | << m_reversed << "\t" |
---|
211 | << m_sequence << "\t" |
---|
212 | << std::endl; |
---|
213 | fflush(stdout); |
---|
214 | |
---|
215 | free(m_acc); |
---|
216 | free(m_sequence); |
---|
217 | } |
---|
218 | |
---|
219 | free(bs.data); |
---|
220 | aisc_close(link, com); |
---|
221 | return 0; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | /* |
---|
226 | Local Variables: |
---|
227 | mode:c++ |
---|
228 | c-file-style:"stroustrup" |
---|
229 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . 0)) |
---|
230 | indent-tabs-mode:nil |
---|
231 | fill-column:99 |
---|
232 | End: |
---|
233 | */ |
---|
234 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
---|