also add some getters, reformat the parse_args if/else tree.
Change using character flags for analysis mode to using an enumeration.
void
Mussa::clear()
{
- ana_name = "";
+ analysis_name = "";
+ ana_mode = TransitiveNway;
seq_num = 0;
window = 0;
threshold = 0;
void
Mussa::set_name(string a_name)
{
- ana_name = a_name;
+ analysis_name = a_name;
+}
+
+string Mussa::get_name()
+{
+ return analysis_name;
}
void
window = a_window;
}
+int Mussa::get_window()
+{
+ return window;
+}
+
void
Mussa::set_threshold(int a_threshold)
{
//soft_thres = a_threshold;
}
+int Mussa::get_threshold()
+{
+ return threshold;
+}
+
void
Mussa::set_soft_thres(int sft_thres)
{
}
void
-Mussa::set_ana_mode(char new_ana_mode)
+Mussa::set_analysis_mode(enum analysis_modes new_ana_mode)
{
ana_mode = new_ana_mode;
}
+enum Mussa::analysis_modes Mussa::get_analysis_mode()
+{
+ return ana_mode;
+}
+
// takes a string and sets it as the next seq - no AGCTN checking atm
void
Mussa::add_a_seq(string a_seq)
{
did_seq = false;
if (param == "ANA_NAME")
- ana_name = value;
+ analysis_name = value;
else if (param == "APPEND_WIN")
win_append = true;
else if (param == "APPEND_THRES")
para_file.close();
soft_thres = threshold;
- cout << "nway mupa: ana_name = " << ana_name << " seq_num = " << seq_num;
+ cout << "nway mupa: analysis_name = " << analysis_name << " seq_num = " << seq_num;
cout << " window = " << window << " threshold = " << threshold << endl;
return "";
string
-Mussa::analyze(int w, int t, char the_ana_mode, double new_ent_thres)
+Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new_ent_thres)
{
string err_msg;
time_t t1, t2, begin, end;
vector<string> some_Seqs;
int i;
-
- cout << "nway: ana mode = " << ana_mode << endl;
- cout << "nway: seq_num = " << seq_num << endl;
-
the_paths.set_soft_thres(soft_thres);
- if (ana_mode == 't')
+ if (ana_mode == TransitiveNway)
the_paths.trans_path_search(all_comps);
- else if (ana_mode == 'r')
+ else if (ana_mode == RadialNway)
the_paths.radiate_path_search(all_comps);
- else if (ana_mode == 'e')
+ else if (ana_mode == EntropyNway)
{
//unlike other methods, entropy needs to look at the sequence at this stage
some_Seqs.clear();
}
// old recursive transitive analysis function
- else if (ana_mode == 'o')
+ else if (ana_mode == RecursiveNway)
the_paths.find_paths_r(all_comps);
the_paths.simple_refine();
// not sure why, but gotta close file each time since can't pass file streams
- save_name = ana_name;
+ save_name = analysis_name;
// gotta do bit with adding win & thres if to be appended
if (win_append)
parsing_path = false;
}
- ana_name = ana_path.substr(dir_index);
- cout << "mu class: ana_name = " << ana_name << endl;
+ analysis_name = ana_path.substr(dir_index);
+ cout << "mu class: analysis_name = " << analysis_name << endl;
file_path_base = ana_path + "/" + ana_path.substr(dir_index);
a_file_path = file_path_base + ".muway";
err_msg = the_paths.load(a_file_path);
fstream save_file;
int i;
- save_file.open(ana_name.c_str(), ios::out);
+ save_file.open(analysis_name.c_str(), ios::out);
for(i = 0; i < seq_num; i++)
save_file << the_Seqs[i].seq() << endl;
save_file << window << endl;
save_file.close();
- //note more complex eventually since ana_name may need to have
+ //note more complex eventually since analysis_name may need to have
//window size, threshold and other stuff to modify it...
- the_paths.save_old(ana_name);
+ the_paths.save_old(analysis_name);
}
class Mussa
{
- friend class MussaOverlord;
friend class ConnWindow;
-
- private:
- // Private variables
- // parameters needed for a mussa analysis
- std::string ana_name, file_path_base;
- int seq_num, window, threshold, soft_thres;
- char ana_mode;
- double ent_thres;
- std::list<std::string> seq_files, annot_files;
- std::list<int> fasta_indices, sub_seq_starts, sub_seq_ends;
- bool win_override, thres_override;
- bool win_append, thres_append;
-
- //! sequence data
- std::vector<Sequence> the_Seqs;
- //! the seqcomp data
- std::vector<std::vector<FLPs> > all_comps;
- //! N-way data, ie the mussa results
- Nway_Paths the_paths;
-
-
- // Private methods
- std::string get_Seqs();
- void seqcomp();
- /*! actually run the nway comparison
- * it appears there are 4 modes, t (trans_path_search),
- * r (radiate_path_search), e (entropy_path_search), and
- * o, (find_paths_r (old recursive analysis))
- */
- void nway();
-
-
public:
+ enum analysis_modes { TransitiveNway, RadialNway, EntropyNway,
+ RecursiveNway };
+
Mussa();
// parameters need to be set before calling this
// w & t are for command line override functionality, set to 0 to ignore
- std::string analyze(int w, int t, char ana_mode, double ent_thres);
+ std::string analyze(int w=0,
+ int t=0,
+ enum analysis_modes ana_mode=TransitiveNway,
+ double ent_thres=0.0);
void save();
void save_muway(std::string save_path);
std::string load(std::string ana_file);
- // clear parameters and initialize data lists
+ //! clear parameters and initialize data lists
void clear();
// set parameters from a file - 'mupa' ~ mussa parameters
std::string load_mupa_file(std::string para_file_path);
// set parameters individually (eg from user input into gui classes)
+ //! set analysis name
void set_name(std::string a_name);
+ //! return name for this analysis
+ std::string get_name();
+
void set_seq_num(int a_num);
+ //! set number of bases for this window size
void set_window(int a_window);
+ //! get number of bases for the sliding window
+ int get_window();
+ //! set number of bases that must match for a window to be saved
void set_threshold(int a_threshold);
+ //! get number of bases that must match for a window to be saved
+ int get_threshold();
void set_soft_thres(int sft_thres);
- void set_ana_mode(char new_ana_mode);
+
+ void set_analysis_mode(enum analysis_modes new_ana_mode);
+ enum analysis_modes get_analysis_mode();
+
// sets an individual sequence to a string (no ATCGN checking atm)
void add_a_seq(std::string a_seq);
// sets info to load a seq and annotations from a fasta file
// these save & load from the old file format
void save_old();
void load_old(char * load_file_path, int s_num);
+
+ private:
+ // Private variables
+ // parameters needed for a mussa analysis
+ std::string analysis_name;
+ std::string file_path_base;
+ int seq_num, window, threshold, soft_thres;
+ enum analysis_modes ana_mode;
+ double ent_thres;
+ std::list<std::string> seq_files, annot_files;
+ std::list<int> fasta_indices, sub_seq_starts, sub_seq_ends;
+ bool win_override, thres_override;
+ bool win_append, thres_append;
+
+ //! sequence data
+ std::vector<Sequence> the_Seqs;
+ //! the seqcomp data
+ std::vector<std::vector<FLPs> > all_comps;
+ //! N-way data, ie the mussa results
+ Nway_Paths the_paths;
+
+ // Private methods
+ std::string get_Seqs();
+ void seqcomp();
+ /*! actually run the nway comparison
+ * it appears there are 4 modes, t (trans_path_search),
+ * r (radiate_path_search), e (entropy_path_search), and
+ * o, (find_paths_r (old recursive analysis))
+ */
+ void nway();
+
};
#endif
annot_color new_annot;
- ana_name = name;
+ analysis_name = name;
seq_num = sq_num;
window = win_len;
S = some_seqs;
// give 50 pixels of height per sequence
y_max = seq_num * 50;
- window_name = "Mussa Sequence: " + ana_name;
+ window_name = "Mussa Sequence: " + analysis_name;
a_seq_win = new SeqWindow(800, y_max, (const char*) window_name.c_str(),
seq_num,
private:
- std::string ana_name;
+ std::string analysis_name;
int seq_num, window, threshold;
bool win_append, thres_append;
if (err_msg == "")
{
// relabel window with the analysis name
- window_name = "Mussa: " + an_analysis->ana_name;
+ window_name = "Mussa: " + an_analysis->analysis_name;
label((const char*)window_name.c_str());
// show the user the analysis
- conn_box->setup(an_analysis->ana_name, an_analysis->seq_num,
+ conn_box->setup(an_analysis->analysis_name, an_analysis->seq_num,
an_analysis->window, &(an_analysis->the_Seqs),
&(an_analysis->the_paths));
conn_box->scale_paths();
if (err_msg == "")
{
- err_msg = an_analysis->analyze(0, 0, 't', 0.0);
+ err_msg = an_analysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
}
if (err_msg == "")
{
// relabel window with the analysis name
- window_name = "Mussa: " + an_analysis->ana_name;
+ window_name = "Mussa: " + an_analysis->analysis_name;
label((const char*)window_name.c_str());
// show the user the analysis
- conn_box->setup(an_analysis->ana_name, an_analysis->seq_num,
+ conn_box->setup(an_analysis->analysis_name, an_analysis->seq_num,
an_analysis->window, &(an_analysis->the_Seqs),
&(an_analysis->the_paths));
conn_box->scale_paths();
if (setup_win->done())
{
// relabel window with the analysis name
- window_name = "Mussa: " + an_analysis->ana_name;
+ window_name = "Mussa: " + an_analysis->analysis_name;
label((const char*)window_name.c_str());
// is it this easy? what if setup window encounters an error...??
- conn_box->setup(an_analysis->ana_name, an_analysis->seq_num,
+ conn_box->setup(an_analysis->analysis_name, an_analysis->seq_num,
an_analysis->window, &(an_analysis->the_Seqs),
&(an_analysis->the_paths));
if (subana_win->done())
{
- subana_name = "SubMussa: " + sub_analysis->ana_name;
+ subana_name = "SubMussa: " + sub_analysis->analysis_name;
sub_conn_win = new ConnWindow(w(), h(), (const char*) subana_name.c_str());
cout << "Like a warm day in may\n";
sub_conn_win->add_ana(sub_analysis);
cout << "new soft thres = " << new_soft_thres << endl;
an_analysis->set_soft_thres(new_soft_thres);
- an_analysis->set_ana_mode('t');
+ an_analysis->set_analysis_mode(Mussa::TransitiveNway);
an_analysis->nway();
conn_box->scale_paths();
conn_box->redraw();
string save_path;
ostringstream append_info;
- save_path = an_analysis->ana_name + "/"
- + an_analysis->ana_name.substr(0,an_analysis->ana_name.find("_t"));
+ save_path = an_analysis->analysis_name + "/"
+ + an_analysis->analysis_name.substr(0,an_analysis->analysis_name.find("_t"));
append_info.str("");
append_info << "_t" << new_soft_thres << ".muway";
//<< "_w" << an_analysis->window
an_analysis = the_ana;
// relabel window with the analysis name
- window_name = "Mussa: " + an_analysis->ana_name;
+ window_name = "Mussa: " + an_analysis->analysis_name;
label((const char*)window_name.c_str());
- conn_box->setup(an_analysis->ana_name, an_analysis->seq_num,
+ conn_box->setup(an_analysis->analysis_name, an_analysis->seq_num,
an_analysis->window, &(an_analysis->the_Seqs),
&(an_analysis->the_paths));
conn_box->scale_paths();
list<vector<int> >::iterator pathz_i;
- ana_name = name;
+ analysis_name = name;
seq_num = sq_num;
S = some_seqs;
P = some_paths;
void toggle_motifs();
private:
- std::string ana_name;
+ std::string analysis_name;
int seq_num;
int base_window_len;
// make the view of the sequence
seq_box = new SeqView(0, 34, w, h-34);
- seq_box->setup(ana_name, seq_num, S, P, seq_lens, the_motifs);
+ seq_box->setup(analysis_name, seq_num, S, P, seq_lens, the_motifs);
//real_set_align_cb(2);
end();
class SeqWindow : public Fl_Double_Window
{
private:
- std::string ana_name;
+ std::string analysis_name;
int base_window_len;
//this data is passed as pointers to the instantiated classes
// <-- need a check here to make sure all vars have a valid value
an_analysis->clear();
- an_analysis->set_name(ana_name);
+ an_analysis->set_name(analysis_name);
an_analysis->set_seq_num(seq_num);
an_analysis->set_window(window);
an_analysis->set_threshold(threshold);
an_analysis->set_seq_info(seq_files[i], annot_files[i], fasta_indices[i],
sub_seq_starts[i], sub_seq_ends[i]);
- err_msg = an_analysis->analyze(0,0, 't', 0.0);
+ err_msg = an_analysis->analyze();
//cout << "Feel the tribal beat\n";
if (!(err_msg == ""))
{
void
SetupWindow::real_set_ana_name_cb(Fl_Input* o)
{
- ana_name = o->value();
+ analysis_name = o->value();
}
// *** input window size
void SetupWindow::print_cb_real(Fl_Button* , void*)
{
- cout << "ana_name: " << ana_name << endl;
+ cout << "analysis_name: " << analysis_name << endl;
cout << "win: " << window << endl;
cout << "thres: " << threshold << endl;
cout << "seq_num: " << seq_num << endl;
private:
Mussa *an_analysis;
- std::string ana_name;
+ std::string analysis_name;
int window, threshold, seq_num;
std::vector<std::string> seq_files, annot_files;
std::vector<int> fasta_indices, sub_seq_starts, sub_seq_ends;
// <-- need a check here to make sure all vars have a valid value
an_analysis->clear();
- an_analysis->set_name(ana_name);
+ an_analysis->set_name(analysis_name);
an_analysis->set_seq_num(seq_num);
an_analysis->set_window(window);
an_analysis->set_threshold(threshold);
an_analysis->add_a_seq(a_sequence);
}
- err_msg = an_analysis->analyze(0,0, 't', 0.0);
+ err_msg = an_analysis->analyze();
cout << "Feel the tribal beat\n";
if (!(err_msg == ""))
void
SubAnalysisWindow::real_set_ana_name_cb(Fl_Input* o)
{
- ana_name = o->value();
+ analysis_name = o->value();
}
// *** input window size
all_done = false;
// initialize parameters
- ana_name = "";
+ analysis_name = "";
window = -1;
threshold = -1;
void SubAnalysisWindow::print_cb_real(Fl_Button* , void*)
{
- cout << "ana_name: " << ana_name << endl;
+ cout << "analysis_name: " << analysis_name << endl;
cout << "win: " << window << endl;
cout << "thres: " << threshold << endl;
cout << "seq_num: " << seq_num << endl;
// sequence data
std::vector<Sequence> the_Seqs;
Mussa *an_analysis;
- std::string ana_name;
+ std::string analysis_name;
int window, threshold, seq_num;
std::vector<int> sub_seq_starts, sub_seq_ends;
bool win_append, thres_append;
#include "gui/ConnWindow.hh"
+#include "alg/mussa_class.hh"
#include <iostream>
using namespace std;
char
parse_args(int argc, char **argv, string *a_file_path, int *window,
- int *threshold, char *ana_mode, float *ent_thres);
+ int *threshold, enum Mussa::analysis_modes *ana_mode, float *ent_thres);
int main(int argc, char **argv)
char * picked_file;
int window, threshold;
float ent_thres;
- char run_mode, ana_mode;
+ char run_mode;
+ enum Mussa::analysis_modes ana_mode;
int x_max=1000;
int y_max=500;
string err_msg;
// minimal arg reading function, not very robust to errors
char
parse_args(int argc, char **argv, string *a_file_path, int *window,
- int *threshold, char *ana_mode, float *ent_thres)
+ int *threshold, enum Mussa::analysis_modes *ana_mode, float *ent_thres)
{
int i, else_i;
string an_arg;
*threshold = 0;
*ent_thres = 0.0;
run_mode = 'e'; //error default if no run mode set implicitly or explicitly
- *ana_mode = 't'; // default to transitivie analyses mode
-
+ *ana_mode = Mussa::TransitiveNway; // default to transitivie analyses mode
// no args means gui only mode
if (argc == 1)
run_mode = 'g';
- // 1 arg means its a mupa file and run in full mode
- /*
- else if (argc == 2)
- {
- }
- */
else
{
else_i = 0;
// see what alternate mode the user wants to run in
if (an_arg == "-m")
{
- an_arg = * ++argv;
- i++;
- if ( (an_arg == "v") || (an_arg == "n") ) //only 2 valid modes so far
- run_mode = an_arg[0];
- else
- {
- cout << "Error: \'" << an_arg;
- cout << "\' is not a valid analysis mode for -a argument" << endl;
+ an_arg = * ++argv;
+ i++;
+ if ( (an_arg == "v") || (an_arg == "n") ) //only 2 valid modes so far
+ run_mode = an_arg[0];
+ else
+ {
+ cout << "Error: \'" << an_arg;
+ cout << "\' is not a valid analysis mode for -a argument" << endl;
throw ParseError("not valid -a argument");
- }
- *a_file_path = * ++argv;
- i++;
+ }
+ *a_file_path = * ++argv;
+ i++;
}
// alternate analyses modes
else if (an_arg == "-a")
{
- an_arg = * ++argv;
- i++;
- // t = transitive, r = radial, e = entropy
- if ( (an_arg == "t") || (an_arg == "r") || (an_arg == "e") )
- *ana_mode = an_arg[0];
- else
- {
- cout << "Error: \'" << an_arg;
- cout << "\' is not a valid run mode for -m argument" << endl;
- throw ParseError("bad argument -m");
- }
-
+ an_arg = * ++argv;
+ i++;
+ // t = transitive, r = radial, e = entropy
+ if (an_arg == "t") *ana_mode = Mussa::TransitiveNway;
+ else if (an_arg == "r") *ana_mode = Mussa::RadialNway;
+ else if (an_arg == "e") *ana_mode = Mussa::EntropyNway;
+ else
+ {
+ cout << "Error: \'" << an_arg;
+ cout << "\' is not a valid run mode for -m argument" << endl;
+ throw ParseError("bad argument -m");
+ }
}
else if (an_arg == "-w") // alternate window size arg
{
- *window = atoi(* ++argv);
- i++;
+ *window = atoi(* ++argv);
+ i++;
}
else if (an_arg == "-t") // alternate threshold arg
{
- *threshold = atoi(* ++argv);
- i++;
+ *threshold = atoi(* ++argv);
+ i++;
}
else if (an_arg == "-et") // alternate entropy threshold arg
{
- *ent_thres = atof(* ++argv);
- i++;
+ *ent_thres = atof(* ++argv);
+ i++;
}
else
{
- if (else_i == 0)
- {
- *a_file_path = an_arg;
- run_mode = 'f';
- else_i++;
- }
- else
- {
- //cout << "Error, unknown arg: \'" << an_arg << "\'" << endl;
- cout << "Error, too many filenames: \'" << an_arg << "\'" << endl;
- run_mode == 'e';
- }
+ if (else_i == 0)
+ {
+ *a_file_path = an_arg;
+ run_mode = 'f';
+ else_i++;
+ }
+ else
+ {
+ //cout << "Error, unknown arg: \'" << an_arg << "\'" << endl;
+ cout << "Error, too many filenames: \'" << an_arg << "\'" << endl;
+ run_mode == 'e';
+ }
}
}
}