[project @ 9]
authorDiane Trout <diane@caltech.edu>
Wed, 21 Sep 2005 23:17:51 +0000 (23:17 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 21 Sep 2005 23:17:51 +0000 (23:17 +0000)
mussa009

Makefile
mussa_class.cc
mussa_nway.cc
mussa_nway.hh
mussa_nway_other.cc [new file with mode: 0644]

index 5ccf03eaa3c38a6feba2998f185a23466195c771..c9e9962e9124907c59f23a78a00b378715431328 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,13 @@
 # may the coders of gcc be infested with the fleas of ten thousand camels...
 
-CFLAGS=-ftemplate-depth-20
-
-#for development
-#CFLAGS= -Winline -ftemplate-depth-25 -ggdb
+CFLAGS=-ftemplate-depth-25
+#CFLAGS= -ftemplate-depth-25 -ggdb
+#-Winline 
 
 OFLAG= -O
 
 # this is sufficient on debian machines
-LDFLAGS= -lfltk
+#LDFLAGS= -lfltk
 
 # this is what's needed on redhat machines
 #LDFLAGS= -lfltk -L/usr/X11R6/lib -lX11
@@ -17,11 +16,11 @@ LDFLAGS= -lfltk
 #LDFLAGS= -lfltk -L/usr/X11R6/lib -lX11 -lXft
 
 # this is what's needed on gentoo machines
-#LDFLAGS= -L/usr/lib/fltk-1.1/ -lfltk -L/usr/X11R6/lib -lX11 -lXft
-
+LDFLAGS= -L/usr/lib/fltk-1.1/ -lfltk -L/usr/X11R6/lib -lX11 -lXft
 # needed for apple/OS X
 #LDFLAGS= -framework Carbon -framework ApplicationServices -lfltk
-
 
 # to check for memory leaks
 MEMFLAG= -lefence
@@ -48,6 +47,9 @@ seqcomp : seqcomp.cc flp.o flp_seqcomp.o sequence.o
 mussa_nway.o : mussa_nway.cc mussa_nway.hh
        $(CC) $(CFLAGS) $(OFLAG) -c mussa_nway.cc
 
+mussa_nway_other.o : mussa_nway_other.cc mussa_nway.hh
+       $(CC) $(CFLAGS) $(OFLAG) -c mussa_nway_other.cc
+
 mussa_class.o : mussa_class.cc mussa_class.hh
        $(CC) $(CFLAGS) -c mussa_class.cc
 
@@ -71,16 +73,18 @@ mussa_gui_conn_view.o : mussa_gui_conn_view.cc mussa_gui_conn_view.hh
 mussa_gui_conn_window.o : mussa_gui_conn_window.cc mussa_gui_conn_window.hh
        $(CC) $(CFLAGS) -c mussa_gui_conn_window.cc
 
-mussa : sequence.o flp.o flp_seqcomp.o mussa_nway.o mussa_class.o \
+mussa : sequence.o flp.o flp_seqcomp.o \
+               mussa_nway.o mussa_nway_other.o mussa_class.o \
                mussa_gui_seq.o mussa_gui_seq_view.o \
                mussa_gui_motif_window.o \
-               mussa_gui_conn_view.o mussa_gui_conn_window.o  \
+               mussa_gui_conn_view.o mussa_gui_conn_window.o \
                mussa.cc  
        $(CC) $(CFLAGS) -o mussa mussa.cc \
                mussa_gui_conn_view.o mussa_gui_conn_window.o \
                mussa_gui_motif_window.o \
                mussa_gui_seq.o mussa_gui_seq_view.o \
-               mussa_class.o mussa_nway.o flp_seqcomp.o flp.o sequence.o  $(LDFLAGS)
+               mussa_class.o mussa_nway.o mussa_nway_other.o \
+               flp_seqcomp.o flp.o sequence.o $(LDFLAGS)
 
 
 clean :
index a86afe1e66e51dc29ad8e73e1ea134090f46463d..f1ab4f08241fe2f313c89f674b773ea2d0fd4dba 100644 (file)
@@ -339,7 +339,9 @@ void
 Mussa::nway()
 {
   the_paths.setup(seq_num, window, threshold);
-  the_paths.find_paths_r(all_comps);
+  //the_paths.find_paths_r(all_comps);
+  the_paths.trans_path_search(all_comps);
+  //the_paths.radiate_path_search(all_comps);
   the_paths.simple_refine();
 }
 
index 5c67ac92456f7a466330119602cb83acf60dafa2..710b04786b8a96baf24fa1056a729e29077bc444 100644 (file)
@@ -40,9 +40,9 @@ Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path,
   {
     //cout << "    * species " << depth << " node: " << *new_nodes_i << endl;
     // check transitivity with previous nodes in path
+    trans_check_good = true;
     for(i = 0; i < depth - 1; i++)
     {
-      trans_check_good = true;
       trans_check_nodes = all_comparisons[i][depth].matches(path[i]);
       if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
                                             trans_check_nodes.end(),
@@ -127,6 +127,7 @@ Nway_Paths::simple_refine()
 
   refined_pathz.clear();
 
+  cout << "path number is: " << pathz.size() << endl;
   pathz_i = pathz.begin();
   ext_path = *pathz_i; 
   while(pathz_i != pathz.end())
@@ -141,7 +142,8 @@ Nway_Paths::simple_refine()
     extending = true;
     for(i2 = 0; i2 < species_num; i2++)
     {
-      //cout << cur_path[i2] << " vs " << next_path[i2] << endl; 
+      //cout << cur_path[i2] << " vs " << endl;
+      //cout << next_path[i2] << endl; 
       if (cur_path[i2] + 1 != next_path[i2])
         extending = false;
     }
@@ -170,6 +172,7 @@ Nway_Paths::simple_refine()
       ext_path = next_path;
     }
   }
+  cout << "r_path number is: " << refined_pathz.size() << endl;
 }
 
 
index 9ff63f4c405fa72e8125bf4916ee689537d17eab..b736a50bd84004af20220f73e843a2c983c710b9 100644 (file)
@@ -22,6 +22,10 @@ class Nway_Paths
     void setup(int sp_num, int w, int t);
     void find_paths_r(vector<vector<FLPs> > all_comparisons);
     void path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth);
+    void radiate_path_search(vector<vector<FLPs> > all_comparisons);
+    void trans_path_search(vector<vector<FLPs> > all_comparisons);
+
+
     void simple_refine();
     void save(string save_file_path);
     string load(string load_file_path);
diff --git a/mussa_nway_other.cc b/mussa_nway_other.cc
new file mode 100644 (file)
index 0000000..d54d644
--- /dev/null
@@ -0,0 +1,354 @@
+#include "mussa_nway.hh"
+
+void
+Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
+{
+  vector<int> path;
+  int win_i, sp_i, sp_depth, window_num;
+  bool some_matches, still_paths, not_advanced;
+  list<int> new_nodes;
+  vector<list<int> > all_matches;
+  vector<list<int>::iterator> sp_nodes, sp_nodes_end;
+  list<int>::iterator debug_i;
+
+  pathz.clear();
+  window_num = all_comparisons[0][1].win_num();
+  cout << window_num << endl;    // just a sanity check
+
+  sp_nodes.reserve(species_num);
+  sp_nodes_end.reserve(species_num);
+
+  // loop thru all windows in first species
+  for (win_i = 0; win_i < window_num; win_i++)
+  {
+    // first we see if the first seq has matches to all other seqs at this win
+    some_matches = true;
+    sp_i = 1;
+    all_matches.clear();
+    while ( (sp_i < species_num) && (some_matches) )
+    {
+      new_nodes.clear();
+      new_nodes = all_comparisons[0][sp_i].matches(win_i);
+      if (new_nodes.empty())
+       some_matches = false;
+
+      all_matches.push_back(new_nodes);
+      sp_i++;
+    }
+    //cout << "fee\n";
+    /*
+    if (some_matches)
+    {
+      cout << win_i << " plrf" << endl;
+      for (sp_i = 0; sp_i < species_num-1; sp_i++)
+      {
+       debug_i = all_matches[sp_i].begin();
+       while (debug_i != all_matches[sp_i].end())
+       {
+         cout << *debug_i << " ";
+         debug_i++;
+       }
+       cout << "plrfff"<< endl;
+      }
+    }
+    */
+    // if 1st seq does match to all others, make all possible paths
+    // out of all these matches
+    if (some_matches)
+    {
+      sp_nodes.clear();
+      sp_nodes_end.clear();
+      // set each species list of matches to beginning
+      for (sp_i = 0; sp_i < species_num-1; sp_i++)
+      {
+       sp_nodes.push_back(all_matches[sp_i].begin());
+       sp_nodes_end.push_back(all_matches[sp_i].end());
+      }
+
+      still_paths = true;
+      sp_depth = species_num - 2;       // this roves up & down species list
+      //cout << "fie\n";
+      while (still_paths) 
+      {
+       // add path that each species iterator is pointing to
+       path.clear();
+       path.push_back(win_i);
+       
+       //cout << win_i;
+       for (sp_i = 0; sp_i < species_num-1; sp_i++)
+       {
+         //cout  << ", " << *(sp_nodes[sp_i]);
+         path.push_back(*(sp_nodes[sp_i]));
+       }
+       //cout << endl;
+       
+       pathz.push_back(path);
+
+       // now advance the right iterator
+       not_advanced = true;
+       while ( (not_advanced) && (sp_depth != -1) )
+       {
+         //cout << "foe\n";
+          //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
+          (sp_nodes[sp_depth])++;   // advance iter at current depth
+          //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
+
+         // if we reached the end of the list, reset iter & go up one depth
+         if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
+         {
+           //cout << "fum\n";
+           sp_nodes[sp_depth] = all_matches[sp_depth].begin();
+           sp_depth--;
+           //cout << "depth = " << sp_depth << endl;
+         }
+         else
+           not_advanced = false;
+       }
+
+       if (sp_depth == -1)   // jumped up to first species, all paths searched
+         still_paths = false;
+       else                 // otherwise just reset to max depth and continue
+         sp_depth = species_num - 2;
+      }
+    }
+  }
+}
+
+
+
+
+void
+Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
+{
+  vector<int> path;
+  int win_i, sp_i, sp_depth, window_num, i, cur_node;
+  bool some_matches, still_paths, not_advanced, trans_good;
+  list<int> new_nodes, trans_check_nodes;
+  vector<list<int> > all_matches;
+  vector<list<int>::iterator> sp_nodes, sp_nodes_end;
+  list<int>::iterator debug_i;
+
+  pathz.clear();
+  window_num = all_comparisons[0][1].win_num();
+  cout << window_num << endl;    // just a sanity check
+
+  sp_nodes.reserve(species_num);
+  sp_nodes_end.reserve(species_num);
+
+  // loop thru all windows in first species
+  for (win_i = 0; win_i < window_num; win_i++)
+  {
+    // first we see if the first seq has matches to all other seqs at this win
+    some_matches = true;
+    sp_i = 1;
+    all_matches.clear();
+    while ( (sp_i < species_num) && (some_matches) )
+    {
+      new_nodes.clear();
+      new_nodes = all_comparisons[0][sp_i].matches(win_i);
+      if (new_nodes.empty())
+       some_matches = false;
+
+      all_matches.push_back(new_nodes);
+      sp_i++;
+    }
+    //cout << "fee\n";
+    /*
+    if (some_matches)
+    {
+      cout << win_i << " plrf" << endl;
+      for (sp_i = 0; sp_i < species_num-1; sp_i++)
+      {
+       debug_i = all_matches[sp_i].begin();
+       while (debug_i != all_matches[sp_i].end())
+       {
+         cout << *debug_i << " ";
+         debug_i++;
+       }
+       cout << "plrfff"<< endl;
+      }
+    }
+    */
+    // if 1st seq does match to all others, make all possible paths
+    // out of all these matches
+    if (some_matches)
+    {
+      sp_nodes.clear();
+      sp_nodes_end.clear();
+      // set each species list of matches to beginning
+      for (sp_i = 0; sp_i < species_num-1; sp_i++)
+      {
+       sp_nodes.push_back(all_matches[sp_i].begin());
+       sp_nodes_end.push_back(all_matches[sp_i].end());
+      }
+
+      still_paths = true;
+      //cout << "fie\n";
+      while (still_paths) 
+      {
+       // add path that each species iterator is pointing to
+       path.clear();
+       path.push_back(win_i);
+       
+       //cout << win_i;
+       for (sp_i = 0; sp_i < species_num-1; sp_i++)
+       {
+         //cout  << ", " << *(sp_nodes[sp_i]);
+         path.push_back(*(sp_nodes[sp_i]));
+       }
+       //cout << endl;
+       // check transitivity
+       sp_depth = 1;
+       trans_good = true;
+       while ( (sp_depth != species_num-1) && (trans_good) )
+       {
+         cur_node = path[sp_depth];
+         for(i = sp_depth+1; i < species_num; i++)
+         {
+           trans_check_nodes = all_comparisons[sp_depth][i].matches(cur_node);
+           if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
+                                                 trans_check_nodes.end(),
+                                                 path[i]) ) &&
+                (trans_check_nodes.end() == find(trans_check_nodes.begin(),
+                                                 trans_check_nodes.end(),
+                                                 path[i] * -1) ) )
+             trans_good = false;
+         }
+         
+         sp_depth++;
+       }
+
+       if (trans_good)
+         pathz.push_back(path);
+
+       // now advance the right iterator
+       not_advanced = true;
+       sp_depth = species_num - 2;       // this roves up & down species list
+       while ( (not_advanced) && (sp_depth != -1) )
+       {
+         //cout << "foe\n";
+          //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
+          (sp_nodes[sp_depth])++;   // advance iter at current depth
+          //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
+
+         // if we reached the end of the list, reset iter & go up one depth
+         if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
+         {
+           //cout << "fum\n";
+           sp_nodes[sp_depth] = all_matches[sp_depth].begin();
+           sp_depth--;
+           //cout << "depth = " << sp_depth << endl;
+         }
+         else
+           not_advanced = false;
+       }
+
+       if (sp_depth == -1)   // jumped up to first species, all paths searched
+         still_paths = false;
+       else                 // otherwise just reset to max depth and continue
+         sp_depth = species_num - 2;
+      }
+    }
+  }
+}
+
+
+
+
+
+
+
+/*
+  // loop thru all windows in first species
+  for (win_i = 0; win_i < window_num; win_i++)
+  {
+    path.clear();
+    path.push_back(win_i);
+    cur_nodes = all_comparisons[0][1].matches(path[0]);
+    cur_nodes_i = cur_nodes.begin();
+    cur_nodes_end = cur_nodes.end();
+    path.push_back(0);
+    for (sp_i = 2; sp_i < species_num; sp_i++)
+    {
+      new_nodes = all_comparisons[0][sp_i].matches(path[0]);
+      new_nodes_i = new_nodes.begin();
+      new_nodes_end = new_nodes.end();
+
+      while(cur_nodes_i != cur_nodes_end)
+      {
+        intersect_bad = false;
+        if ( (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
+                                      *cur_nodes_i) ) &&
+             (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
+                                      *cur_nodes_i * -1) ) )
+          intersect_bad = true;
+
+       // if no matches to this sequence, we don't need to check this node
+       // against any of the remaining ones
+        if (intersect_bad)
+         cur_nodes_i = cur_nodes.erase(cur_nodes_i); // this advances the iter
+       else
+         ++cur_nodes_i;  // just advance normally
+
+      }
+    }
+
+  }
+*/
+
+
+/*
+    while(new_nodes_i != new_nodes_end)
+
+
+      path[1] = *new_nodes_i;
+      path_search(all_comparisons, path, 2);
+
+*/
+    //if (new_nodes_i != new_nodes_end)
+    //cout << "* species 0 node: " << win_i << endl;
+    //  cout << "foookin hell\n";
+
+     //cout << "  * species 1 node: " << *new_nodes_i << endl;
+
+    //cout << "    * species " << depth << " node: " << *new_nodes_i << endl;
+    // check transitivity with previous nodes in path
+
+/*
+void
+Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
+{
+  list<int> new_nodes, trans_check_nodes;
+  list<int>::iterator new_nodes_i, new_nodes_end;
+  int i;
+
+  new_nodes = all_comparisons[depth - 1][depth].matches(path[depth-1]);
+  new_nodes_i = new_nodes.begin();
+  new_nodes_end = new_nodes.end();
+
+    if (trans_check_good)
+    {
+      // this makes sure path nodes are recorded with RC status relative to
+      // the base species
+      if ( path[depth-1] >= 0)
+        path.push_back(*new_nodes_i);
+      else
+        path.push_back(*new_nodes_i * -1);
+
+      if (depth < species_num - 1)
+        path_search(all_comparisons, path, depth + 1);
+      else
+        pathz.push_back(path);
+      path.pop_back();
+    } 
+    ++new_nodes_i;
+  }
+} 
+*/
+//          cout << "    ****I have the power...\n";
+
+/* use this if I ever get the friggin seqcomp match lists to sort...
+      if (binary_search(trans_check_nodes.begin(), trans_check_nodes.end(), 
+                        *new_nodes_i))
+*/