[project @ 13]
[mussa.git] / mussa_gui_conn_window.cc
index a5ba5e904ff912e96240d112bdd59629cdbb4c7d..0b3e3741aeae3be0e86366c20f23bfc8a8626661 100644 (file)
+//  This file is part of the Mussa source distribution.
+//  http://mussa.caltech.edu/
+//  Contact author: Tristan  De Buysscher, tristan@caltech.edu
+
+// This program and all associated source code files are Copyright (C) 2005
+// the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
+// under the GNU Public License; please see the included LICENSE.txt
+// file for more information, or contact Tristan directly.
+
+
 #include "mussa_gui_conn_window.hh"
 
-ConnWindow::ConnWindow(int w, int h, const char* title, Mussa *the_ana):
+
+void
+load_ana_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_load_ana_cb();
+}
+
+
+void
+ConnWindow::real_load_ana_cb()
+{
+  char *picked_file;
+  string a_file_path;
+  string err_msg;
+
+  cout << "Load!  Load!  Load, ye yellow-bellied seadogs!\n";
+  //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
+  picked_file = fl_dir_chooser("Find an Analysis", "", 1);
+  if (picked_file != NULL)
+  {
+    a_file_path = picked_file;
+    cout << "doo wah diddy diddy dum diddy doo\n";
+    cout << a_file_path << endl;
+
+    // load the analysis
+    an_analysis = new Mussa();
+    err_msg = an_analysis->load(a_file_path);
+    //.substr(0,a_file_path.find(".mu")));
+
+    if (err_msg == "")
+    {
+      // relabel window with the analysis name
+      window_name = "Mussa: " + an_analysis->ana_name;
+      label((const char*)window_name.c_str());
+      // show the user the analysis
+      conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
+                     an_analysis->window, &(an_analysis->the_Seqs), 
+                     &(an_analysis->the_paths));
+      conn_box->scale_paths();
+    }
+    else
+    {
+      fl_alert(err_msg.c_str());
+      cout << err_msg << endl;
+    }
+  }
+}
+
+
+void
+do_ana_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_do_ana_cb();
+}
+
+
+void
+ConnWindow::real_do_ana_cb()
+{
+  char *picked_file;
+  string a_file_path;
+  string err_msg;
+
+  picked_file = fl_file_chooser("Analysis Config File", "", "", 1);
+  if (picked_file != NULL)
+  {
+    a_file_path = picked_file;
+
+    an_analysis = new Mussa();
+    err_msg = an_analysis->load_mupa_file(a_file_path);
+
+    if (err_msg == "")
+    {
+      err_msg = an_analysis->analyze(0, 0, 't', 0.0);
+    }
+
+    if (err_msg == "")
+    {
+      // relabel window with the analysis name
+      window_name = "Mussa: " + an_analysis->ana_name;
+      label((const char*)window_name.c_str());
+      // show the user the analysis
+      conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
+                     an_analysis->window, &(an_analysis->the_Seqs), 
+                     &(an_analysis->the_paths));
+      conn_box->scale_paths();
+    }
+    else
+    {
+      fl_alert(err_msg.c_str());
+      cout << err_msg;
+    }
+  }
+}
+
+
+void
+setup_ana_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_setup_ana_cb();
+}
+
+void
+ConnWindow::real_setup_ana_cb()
+{
+  an_analysis = new Mussa();
+  setup_win = new SetupWindow(650,700,"Analysis Setup", an_analysis);
+
+  while(setup_win->visible())
+    Fl::wait(.1);
+  cout << "Like a warm summer day\n";
+
+  if (setup_win->done())
+  {
+    // relabel window with the analysis name
+    window_name = "Mussa: " + an_analysis->ana_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, 
+                   an_analysis->window, &(an_analysis->the_Seqs), 
+                   &(an_analysis->the_paths));
+
+    conn_box->scale_paths();
+  }
+}
+
+
+void
+subana_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_subana_cb();
+}
+
+void
+ConnWindow::real_subana_cb()
+{
+  string subana_name;
+
+  sub_analysis = new Mussa();
+  subana_win = new SubanaWindow(500,400,"Sub Analysis Setup", sub_analysis,
+                               an_analysis->the_Seqs);
+
+  while(subana_win->visible())
+    Fl::wait(.1);
+  cout << "Like a warm summer day\n";
+
+  if (subana_win->done())
+  {
+    subana_name = "SubMussa: " + sub_analysis->ana_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);
+    //Fl::visual(FL_DOUBLE|FL_INDEX);
+    //sub_conn_box->show();
+  }
+}
+
+
+void
+seq_show_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_seq_show_cb();
+}
+
+void
+ConnWindow::real_seq_show_cb()
+{
+  show_seq_win = new SeqTextWin(500,400,"Seq Show", an_analysis->the_Seqs);
+}
+
+void
+seq_win_spawn_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_seq_win_spawn_cb();
+}
+
+void
+ConnWindow::real_seq_win_spawn_cb()
+{
+  conn_box->spawnSeq();
+}
+
+void
+motif_find_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_motif_find_cb();
+}
+
+void
+ConnWindow::real_motif_find_cb()
+{
+  conn_box->find_motifs();
+}
+
+void
+annot_win_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_annot_win_cb();
+}
+
+void
+ConnWindow::real_annot_win_cb()
+{
+  conn_box->annot_win();
+}
+
+
+// all the crap needed for dealing with the scale bars
+void
+toggle_scale_bars_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_toggle_bars_cb();
+}
+
+void
+ConnWindow::real_toggle_bars_cb()
+{
+  conn_box->toggle_bars();
+}
+
+void
+set_bar_len_cb(Fl_Input* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  cout << "WAAAAAAAAA\n";
+  T->real_set_bar_len_cb(o);
+}
+
+void
+ConnWindow::real_set_bar_len_cb(Fl_Input* o)
+{
+  int new_bar_len;
+  new_bar_len = atoi(o->value());
+  cout << "new bar len = " << new_bar_len << endl;
+  conn_box->set_bar_interval(new_bar_len);
+}
+
+
+// all the crap needed for dealing with the scale lines
+void
+toggle_scale_lines_cb(Fl_Button* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  T->real_toggle_lines_cb();
+}
+
+void
+ConnWindow::real_toggle_lines_cb()
+{
+  conn_box->toggle_lines();
+}
+
+void
+set_line_len_cb(Fl_Input* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  cout << "WAAAAAAAAA\n";
+  T->real_set_line_len_cb(o);
+}
+
+void
+ConnWindow::real_set_line_len_cb(Fl_Input* o)
+{
+  int new_line_len;
+  new_line_len = atoi(o->value());
+  cout << "new line len = " << new_line_len << endl;
+  conn_box->set_line_interval(new_line_len);
+}
+
+
+// setting new soft threshold
+
+void
+set_soft_thres_cb(Fl_Input* o, void* v)
+{
+  ConnWindow* T=(ConnWindow*)v;
+  cout << "WAAAAAAAAA\n";
+  T->real_set_soft_thres_cb(o);
+}
+
+void
+ConnWindow::real_set_soft_thres_cb(Fl_Input* o)
+{
+  int new_soft_thres;
+  new_soft_thres = atoi(o->value());
+  cout << "new soft thres = " << new_soft_thres << endl;
+
+  an_analysis->set_soft_thres(new_soft_thres);
+  an_analysis->set_ana_mode('t');
+  an_analysis->nway();
+  conn_box->scale_paths();
+  conn_box->redraw();
+
+  // hacked in stuff to save muway files at different thresholds
+  string save_path;
+  ostringstream append_info;
+
+  save_path = an_analysis->ana_name + "/"
+    + an_analysis->ana_name.substr(0,an_analysis->ana_name.find("_t"));
+  append_info.str("");
+  append_info << "_t" << new_soft_thres << ".muway";
+  //<<  "_w" << an_analysis->window
+  save_path += append_info.str();
+  cout << "saving as: " << save_path << endl;
+  an_analysis->save_muway(save_path);
+}
+
+
+
+
+ConnWindow::ConnWindow(int w, int h, const char* title):
   Fl_Double_Window(w,h,title)
 {
-  an_analysis = the_ana;
+  int button_len = 120;
+  Fl_Color a_color = fl_rgb_color(150, 200, 255);
+
   padding = 5;
 
   begin();
   //fl_color(150,200,255);
-  color(FL_BLUE);
+  color(FL_WHITE);
   resizable(this);
-  ConnView *conn_box = new ConnView(padding, padding, w-2*padding, 
-                                    h-2*padding);
-  conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
-                  an_analysis->window, &(an_analysis->the_Seqs), 
-                  &(an_analysis->the_paths));
-  conn_box->scale_paths();
+
+  // create file menu button
+  file_menu = new Fl_Menu_Button(padding, 2, button_len, 30, "Analysis");
+  file_menu->color(FL_WHITE,a_color);
+  file_menu->box(FL_BORDER_BOX);
+  file_menu->clear();
+
+  // add menu items
+  file_menu->add("Do Analysis", 0, (Fl_Callback *) do_ana_cb, this);
+  file_menu->add("Load Analysis", 0, (Fl_Callback *) load_ana_cb, this);
+  file_menu->add("Setup Analysis", 0, (Fl_Callback *) setup_ana_cb, this);
+  file_menu->add("Sub Analysis", 0, (Fl_Callback *) subana_cb, this);
+
+
+  view_menu = new Fl_Menu_Button(padding+button_len,2, button_len, 30, "View");
+  view_menu->color(FL_WHITE,a_color);
+  view_menu->box(FL_BORDER_BOX);
+  view_menu->clear();
+  view_menu->add("Sequence Zoom", 0, (Fl_Callback*) seq_win_spawn_cb, this);
+  view_menu->add("Motif Finder", 0, (Fl_Callback*) motif_find_cb, this);
+  view_menu->add("Annotations", 0, (Fl_Callback*) annot_win_cb, this);
+  view_menu->add("Copy Seq", 0, (Fl_Callback*) seq_show_cb, this);
+  view_menu->add("Toggle Bars", 0, (Fl_Callback*) toggle_scale_bars_cb, this, 
+                FL_MENU_TOGGLE|FL_MENU_VALUE);
+  view_menu->add("Toggle Lines", 0, (Fl_Callback*) toggle_scale_lines_cb, this,
+                FL_MENU_TOGGLE|FL_MENU_VALUE);
+
+  bar_input = new Fl_Input(padding+3*button_len, 2, button_len, 30, "Bar Length (bp)");
+  bar_input->value("");
+  bar_input->when(FL_WHEN_ENTER_KEY);
+  bar_input->callback((Fl_Callback*)set_bar_len_cb, this);
+
+  line_input = new Fl_Input(padding+5*button_len, 2, button_len, 30, "Line Interval (bp)");
+  line_input->value("");
+  line_input->when(FL_WHEN_ENTER_KEY);
+  line_input->callback((Fl_Callback*)set_line_len_cb, this);
+
+
+  thres_input = new Fl_Input(padding+7*button_len, 2, button_len, 30, "Threshold");
+  thres_input->value("");
+  thres_input->when(FL_WHEN_ENTER_KEY);
+  thres_input->callback((Fl_Callback*)set_soft_thres_cb, this);
+
+
+  // create the connections box
+  conn_box = new ConnView(padding, padding + 30, w-2*padding, h-2*padding-30);
+  //conn_box = new ConnView(padding, padding, w-2*padding, h-2*padding);
+
   end();
   show();
 }
@@ -24,3 +401,18 @@ ConnWindow::ConnWindow(int w, int h, const char* title, Mussa *the_ana):
 ConnWindow::~ConnWindow()
 {}
 
+
+void
+ConnWindow::add_ana(Mussa *the_ana)
+{
+  an_analysis = the_ana;
+
+  // relabel window with the analysis name
+  window_name = "Mussa: " + an_analysis->ana_name;
+  label((const char*)window_name.c_str());
+
+  conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
+                  an_analysis->window, &(an_analysis->the_Seqs), 
+                  &(an_analysis->the_paths));
+  conn_box->scale_paths();
+}