1 // ----------------------------------------
2 // ---------- mussa_class.cc -----------
3 // ----------------------------------------
5 #include "mussa_class.hh"
7 // doesn't do neg ints...
21 remainder = an_int % 10;
24 converted_int = "0" + converted_int;
25 else if (remainder == 1)
26 converted_int = "1" + converted_int;
27 else if (remainder == 2)
28 converted_int = "2" + converted_int;
29 else if (remainder == 3)
30 converted_int = "3" + converted_int;
31 else if (remainder == 4)
32 converted_int = "4" + converted_int;
33 else if (remainder == 5)
34 converted_int = "5" + converted_int;
35 else if (remainder == 6)
36 converted_int = "6" + converted_int;
37 else if (remainder == 7)
38 converted_int = "7" + converted_int;
39 else if (remainder == 8)
40 converted_int = "8" + converted_int;
41 else if (remainder == 9)
42 converted_int = "9" + converted_int;
56 Mussa::parse_args(int argc, char **argv)
63 thres_override = false;
64 // minimal arg reading structure, not very robust to errors
79 else if (an_arg == "-n")
81 para_file_path = * ++argv;
85 else if (an_arg == "-w")
87 window = atoi(* ++argv);
91 else if (an_arg == "-t")
93 threshold = atoi(* ++argv);
95 thres_override = true;
96 cout << thres_override << endl;
100 para_file_path = an_arg;
112 string file_data_line;
113 string param, value, annot_file;
114 int split_index, fasta_index;
115 int sub_seq_start, sub_seq_end;
116 bool seq_params, did_seq;
121 thres_append = false;
123 fasta_indices.clear();
125 sub_seq_starts.clear();
126 sub_seq_ends.clear();
128 para_file.open(para_file_path.c_str(), ios::in);
130 getline(para_file,file_data_line);
131 split_index = file_data_line.find(" ");
132 param = file_data_line.substr(0,split_index);
133 value = file_data_line.substr(split_index+1);
136 while (!para_file.eof())
139 if (param == "ANA_NAME")
141 else if (param == "APPEND_WIN")
143 else if (param == "APPEND_THRES")
145 else if (param == "SEQUENCE_NUM")
146 seq_num = atoi(value.c_str());
147 else if (param == "WINDOW")
150 window = atoi(value.c_str());
152 else if (param == "THRESHOLD")
155 threshold = atoi(value.c_str());
157 else if (param == "SEQUENCE")
159 seq_files.push_back(value);
166 while ((!para_file.eof()) && seq_params)
168 getline(para_file,file_data_line);
169 split_index = file_data_line.find(" ");
170 param = file_data_line.substr(0,split_index);
171 value = file_data_line.substr(split_index+1);
173 if (param == "FASTA_INDEX")
174 fasta_index = atoi(value.c_str());
175 else if (param == "ANNOTATION")
177 else if (param == "SEQ_START")
178 sub_seq_start = atoi(value.c_str());
179 else if (param == "SEQ_END")
181 cout << "hey! " << atoi(value.c_str()) << endl;
182 sub_seq_end = atoi(value.c_str());
184 //ignore empty lines or that start with '#'
185 else if ((param == "") || (param == "#")) {}
186 else seq_params = false;
190 fasta_indices.push_back(fasta_index);
191 annot_files.push_back(annot_file);
192 sub_seq_starts.push_back(sub_seq_start);
193 sub_seq_ends.push_back(sub_seq_end);
197 //ignore empty lines or that start with '#'
198 else if ((param == "") || (param == "#")) {}
201 cout << "Illegal/misplaced mussa parameter in file\n";
202 cout << param << "\n";
207 getline(para_file,file_data_line);
208 split_index = file_data_line.find(" ");
209 param = file_data_line.substr(0,split_index);
210 value = file_data_line.substr(split_index+1);
217 cout << "ana_name = " << ana_name << win_append << win_append << "\n";
218 cout << "window = " << window << " threshold = " << threshold << "\n";
221 // if (!((param == "") || (param == "#")))
222 // cout << value << " = " << param << endl;
227 list<string>::iterator seq_files_i, annot_files_i;
228 list<int>::iterator fasta_indices_i, seq_starts_i, seq_ends_i;
231 seq_files_i = seq_files.begin();
232 fasta_indices_i = fasta_indices.begin();
233 annot_files_i = annot_files.begin();
234 seq_starts_i = sub_seq_starts.begin();
235 seq_ends_i = sub_seq_ends.begin();
238 while (seq_files_i != seq_files.end())
239 /* it should be guarenteed that each of the following exist
241 (fasta_indices_i != fasta_indices.end()) &&
242 (annot_files_i != annot_files.end()) &&
243 (seq_starts_i != sub_seq_starts.end()) &&
244 (seq_ends_i != sub_seq_ends.end()) )
247 aSeq.load_fasta(*seq_files_i, *fasta_indices_i,*seq_starts_i,*seq_ends_i);
248 if (*annot_files_i != "")
249 aSeq.load_annot(*annot_files_i);
250 the_Seqs.push_back(aSeq);
251 cout << aSeq.hdr() << endl;
252 //cout << aSeq.seq() << endl;
272 int i, i2; // loop vars over sequences to analyze
273 vector<int> seq_lens;
274 vector<FLPs> empty_FLP_vector;
276 string save_file_string;
278 empty_FLP_vector.clear();
279 for(i = 0; i < seq_num; i++)
281 all_comps.push_back(empty_FLP_vector);
282 for(i2 = 0; i2 < seq_num; i2++)
283 all_comps[i].push_back(dummy_comp);
286 for(i = 0; i < seq_num; i++)
287 seq_lens.push_back(the_Seqs[i].len());
289 for(i = 0; i < seq_num; i++)
290 for(i2 = i+1; i2 < seq_num; i2++)
292 all_comps[i][i2].setup("m", window, threshold, seq_lens[i],seq_lens[i2]);
293 all_comps[i][i2].seqcomp(the_Seqs[i].seq(), the_Seqs[i2].seq(), false);
294 all_comps[i][i2].seqcomp(the_Seqs[i].seq(),the_Seqs[i2].rev_comp(),true);
296 all_comps[i][i2].file_save(save_file_string);
305 the_paths.setup(seq_num, window, threshold);
306 the_paths.find_paths_r(all_comps);
307 the_paths.simple_refine();
313 string save_path_base, save_path;
317 // gotta do bit with adding win & thres if to be appended - need itos
319 // not sure why, but gotta close file each time since can't pass file streams
321 save_path_base = ana_name;
324 save_path_base += "_w" + int_to_str(window);
327 save_path_base += "_t" + int_to_str(threshold);
329 // save sequence and annots to a special mussa file
330 save_path = save_path_base + ".museq";
331 save_file.open(save_path.c_str(), ios::out);
332 save_file << "<Mussa_Sequence>" << endl;
335 for(i = 0; i < seq_num; i++)
336 the_Seqs[i].save(save_file);
338 //save_file.open(save_path.c_str(), ios::app);
339 save_file << "</Mussa_Sequence>" << endl;
342 // save nway paths to its mussa save file
343 save_path = save_path_base + ".muway";
344 the_paths.save(save_path);
351 string load_file_path;
355 load_file_path = ana_name + ".muway";
356 seq_num = the_paths.load(load_file_path);
358 load_file_path = ana_name + ".museq";
359 for (i = 1; i <= seq_num; i++)
362 tmp_seq.load_museq(load_file_path, i);
363 the_Seqs.push_back(tmp_seq);
369 // In Memorial to Everything that's gone wrong in the last week
370 // and Everything that will go wrong in the next 2 weeks 03/02/2004 - Tristan
372 Mussa::FuckingPieceOfShit(int x_max, int y_max)
374 Fl_Window *conn_window = new Fl_Window(x_max, y_max, "Mussa Connections");
375 ConnView *conn_box = new ConnView(0, 0, x_max, y_max);
376 conn_box->setup(ana_name, seq_num, window, &the_Seqs, &the_paths);
377 conn_box->scale_paths();
399 save_file.open(ana_name.c_str(), ios::out);
401 for(i = 0; i < seq_num; i++)
402 save_file << the_Seqs[i].seq() << endl;
404 save_file << window << endl;
406 //note more complex eventually since ana_name may need to have
407 //window size, threshold and other stuff to modify it...
408 the_paths.save_old(ana_name);
413 Mussa::load_old(char * load_file_path, int s_num)
416 string file_data_line;
417 int i, space_split_i, comma_split_i;
418 vector<int> loaded_path;
419 string node_pair, node;
423 the_paths.setup(seq_num, 0, 0);
424 save_file.open(load_file_path, ios::in);
426 // currently loads old mussa format
429 for(i = 0; i < seq_num; i++)
431 getline(save_file, file_data_line);
432 a_seq.set_seq(file_data_line);
433 the_Seqs.push_back(a_seq);
437 getline(save_file, file_data_line);
438 window = atoi(file_data_line.c_str());
441 while (!save_file.eof())
444 getline(save_file, file_data_line);
445 if (file_data_line != "")
446 for(i = 0; i < seq_num; i++)
448 space_split_i = file_data_line.find(" ");
449 node_pair = file_data_line.substr(0,space_split_i);
450 //cout << "np= " << node_pair;
451 comma_split_i = node_pair.find(",");
452 node = node_pair.substr(comma_split_i+1);
453 //cout << "n= " << node << " ";
454 loaded_path.push_back(atoi (node.c_str()));
455 file_data_line = file_data_line.substr(space_split_i+1);
458 the_paths.add_path(loaded_path);
462 //the_paths.save("tmp.save");