cleanup nway code
authorDiane Trout <diane@caltech.edu>
Wed, 1 Mar 2006 02:44:43 +0000 (02:44 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 1 Mar 2006 02:44:43 +0000 (02:44 +0000)
Purged the sp_num variable and replaced it with either a .size() call, or
a call to a new member function sequence_count()
Renamed Nway_Paths to NwayPaths
Used vector<>::size_type in a number of places
Reflowed some blocks.

alg/flp.cxx
alg/mussa_class.cxx
alg/mussa_class.hh
alg/nway_entropy.cxx
alg/nway_other.cxx
alg/nway_paths.cxx
alg/nway_paths.hh
alg/test/test_nway.cxx
gui/ConnView.cxx
gui/ConnView.hh
qui/PathScene.cxx

index 88a0d824a6aafa6be0c326df6c320b427aaf9049..9f6a1ff06ab3b4cf0708abcf368de3739ee43a2b 100644 (file)
@@ -23,9 +23,9 @@
 using namespace std;
 
 FLPs::FLPs() :
-  all_matches(0),
   window_size(0),
-  hard_threshold(0)
+  hard_threshold(0),
+  all_matches(0)
 {
 }
 
@@ -47,7 +47,7 @@ void FLPs::alloc_matches(string::size_type len1)
   all_matches = new std::vector<list<match> >;
 
   list<match> empty_match_list;
-  int window_count; 
+  std::vector<list<match> >::size_type window_count; 
   if (len1 > 0) {
     // we actually know how much to preallocate
     window_count = len1 - window_size+1;
@@ -56,7 +56,7 @@ void FLPs::alloc_matches(string::size_type len1)
     window_count = 0;
   }
 
-  for (int i=0; i < window_count; ++i) {
+  for (std::vector<list<match> >::size_type i=0; i < window_count; ++i) {
     all_matches->push_back(empty_match_list);
   }
   assert (all_matches->size() == window_count);
@@ -148,8 +148,6 @@ FLPs::save(string save_file_path)
     throw runtime_error("please call FLPs.seqcomp first");
 
   fstream save_file;
-  int i;
-
   save_file.open(save_file_path.c_str(), ios::out);
 
   save_file << "<Seqcomp win=" << window_size
@@ -181,12 +179,10 @@ FLPs::load(string file_path)
 {
   fstream data_file;
   string file_data, file_data_line, pair_data, index_data, score_data;
-  int type, window, hard_thres;
   match a_match;
   string::size_type split_index, comma_index;
   bool tag_open = false;
   list<match> a_match_list;
-  int i;
   // initialize our all_matches pointer
   alloc_matches();
 
index c69b97757b124ef877e587178399412c1fb27fc0..bdc6dd4ada6b0dad033ddc28ca60be79fce55152 100644 (file)
@@ -126,7 +126,7 @@ string Mussa::get_analysis_mode_name() const
   }
 }
 
-const Nway_Paths& Mussa::paths() const
+const NwayPaths& Mussa::paths() const
 {
   return the_paths;
 }
@@ -335,7 +335,7 @@ Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new
 
 
   t1 = time(NULL);
-  the_paths.setup(the_seqs.size(), window, threshold);
+  the_paths.setup(window, threshold);
   nway();
   t2 = time(NULL);
   nwaytime = difftime(t2, t1);
@@ -581,14 +581,14 @@ Mussa::load(string ana_file)
 
   if (err_msg == "")
   {
-    int seq_num = the_paths.seq_num();
+    int seq_num = the_paths.sequence_count();
 
     cout << "No BAM\n";
 
     a_file_path = file_path_base + ".museq";
 
     // this is a bit of a hack due to C++ not acting like it should with files
-    for (i = 1; i <= the_paths.seq_num(); i++)
+    for (i = 1; i <= seq_num; i++)
     {
       tmp_seq.clear();
       cout << "mussa_class: loading museq frag...\n";
@@ -660,7 +660,7 @@ Mussa::load_old(char * load_file_path, int s_num)
   Sequence a_seq;
 
   int seq_num = s_num;
-  the_paths.setup(seq_num, 0, 0);
+  the_paths.setup(0, 0);
   save_file.open(load_file_path, ios::in);
 
   // currently loads old mussa format
index 428001c12e1a058f8f76f32521434a295dd8ca65..685f441709b320d43da5e305b43703b722d7237a 100644 (file)
@@ -66,7 +66,7 @@ class Mussa
     std::string get_analysis_mode_name() const;
 
     //! return the refined paths found by the nway analysis.
-    const Nway_Paths& paths() const;
+    const NwayPaths& paths() const;
 
     //! run seqcomp and the nway filtering algorithm.
     /*!analyze will run seqcomp and then the nway algorithm
@@ -113,7 +113,7 @@ class Mussa
     //! the seqcomp data
     std::vector<std::vector<FLPs> > all_comps;
     //! N-way data, ie the mussa results  
-    Nway_Paths the_paths;
+    NwayPaths the_paths;
 
     // Private methods
     //! loads sequence and annotations from fasta and annotation file
index 2490cbfeb9f12ea8f1463c56361582eb9632e646..3ef4600510499431783acd6b131d623e3fad1062 100644 (file)
@@ -20,90 +20,92 @@ using namespace std;
 
 
 void
-Nway_Paths::setup_ent(double new_entropy_thres, vector<string> some_Seqs)
+NwayPaths::setup_ent(double new_entropy_thres, vector<string> some_seqs)
 {
-  int i;
-
   ent_thres = new_entropy_thres;
 
   c_sequences.clear();
-  for (i = 0; i < species_num; i++)
-    c_sequences.push_back((char *)some_Seqs[i].c_str());
+  for (vector<string>::size_type i = 0; i < some_seqs.size(); i++)
+    c_sequences.push_back((char *)some_seqs[i].c_str());
 }
 
 
 double
-Nway_Paths::path_entropy(vector<int> path)
+NwayPaths::path_entropy(vector<int> path)
 {
   int bp_occurences[5];
   double bp_prob, frac_ent, avg_entropy;
   vector<double> entropies;
-  int i, seq_i, i2;
+  int i, i2;
   int window = win_size;
-  int seq_num = species_num;
-
 
   for(i = 0; i < window; i++)     // loop thru all bp positions
   {
     for(i2 = 0; i2 < 5; i2++)     // clear old occurences
       bp_occurences[i2] = 0;
 
-    for(seq_i = 0; seq_i < seq_num; seq_i++) //loop thru all sequences at pos i
-      if (path[seq_i] > -1) 
-       switch (c_sequences[seq_i][i+path[seq_i]])
-       {
+    //loop thru all sequences at pos i
+    for(vector<int>::size_type seq_i = 0; seq_i != path.size(); seq_i++)
+    {
+      if (path[seq_i] > -1)
+      {
+        switch (c_sequences[seq_i][i+path[seq_i]])
+        {
           case 'A':
-           ++bp_occurences[0];
-           break;
+            ++bp_occurences[0];
+            break;
           case 'T':
-           ++bp_occurences[1];
-           break;
+            ++bp_occurences[1];
+            break;
           case 'G':
-           ++bp_occurences[2];
-           break;
+            ++bp_occurences[2];
+            break;
           case 'C':
-           ++bp_occurences[3];
-           break;
+            ++bp_occurences[3];
+            break;
           case 'N':
-           ++bp_occurences[4];
-           break;
+            ++bp_occurences[4];
+            break;
           default:
-           cout << "error, nonAGCTN on seq: " << seq_i << " at index: ";
-           cout << i+path[seq_i] << endl;
-       }
+            cout << "error, nonAGCTN on seq: " << seq_i << " at index: ";
+            cout << i+path[seq_i] << endl;
+        }
+      }
       else
-       switch (c_sequences[seq_i][-1 * (i + path[seq_i] - window + 1) ])
-       {
+      {
+        switch (c_sequences[seq_i][-1 * (i + path[seq_i] - window + 1) ])
+        {
           case 'A':
-           ++bp_occurences[1];
-           break;
+            ++bp_occurences[1];
+            break;
           case 'T':
-           ++bp_occurences[0];
-           break;
+            ++bp_occurences[0];
+            break;
           case 'G':
-           ++bp_occurences[3];
-           break;
+            ++bp_occurences[3];
+            break;
           case 'C':
-           ++bp_occurences[2];
-           break;
+            ++bp_occurences[2];
+            break;
           case 'N':
-           ++bp_occurences[4];
-           break;
+            ++bp_occurences[4];
+            break;
           default:
-           cout << "error, nonAGCTN on seq: " << seq_i << " at index: ";
-           cout << (i + path[seq_i] - window + 1) << endl;
-       }
-       
-
+            cout << "error, nonAGCTN on seq: " << seq_i << " at index: ";
+            cout << (i + path[seq_i] - window + 1) << endl;
+        }
+      }
+    }
+    
     entropies.push_back(0.000);
     for(i2 = 0; i2 < 5; i2++)    //calculate entropies
     {
-      bp_prob = (double) bp_occurences[i2] / (double) seq_num;
+      bp_prob = (double) bp_occurences[i2] / (double) path.size();
       //cout << bp_prob << "::";
       if (bp_prob == 0.0000)
-       frac_ent = 0.0000;
+        frac_ent = 0.0000;
       else
-       frac_ent = bp_prob * ( log10(bp_prob) / log10(2.0) );
+        frac_ent = bp_prob * ( log10(bp_prob) / log10(2.0) );
       //cout << frac_ent << "  ";
       entropies[i] += frac_ent;
     }
@@ -122,17 +124,14 @@ Nway_Paths::path_entropy(vector<int> path)
   return avg_entropy;
 }
 
-
-
-
-
 void
-Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
+NwayPaths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
 {
   vector<int> path;
   double avg_entropy;
-  int win_i, sp_i, sp_depth, window_num, i, cur_node;
-  bool some_matches, still_paths, not_advanced, trans_good;
+  int win_i, sp_depth, window_num;
+  unsigned int sp_i;
+  bool some_matches, still_paths, not_advanced;
   list<int> new_nodes, trans_check_nodes;
   vector<list<int> > all_matches;
   vector<list<int>::iterator> sp_nodes, sp_nodes_end;
@@ -143,8 +142,8 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
   window_num = all_comparisons[0][1].size();
   cout << window_num << endl;    // just a sanity check
 
-  sp_nodes.reserve(species_num);
-  sp_nodes_end.reserve(species_num);
+  sp_nodes.reserve(all_comparisons.size());
+  sp_nodes_end.reserve(all_comparisons.size());
 
   // loop thru all windows in first species
   for (win_i = 0; win_i < window_num; win_i++)
@@ -153,12 +152,12 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
     some_matches = true;
     sp_i = 1;
     all_matches.clear();
-    while ( (sp_i < species_num) && (some_matches) )
+    while ( (sp_i < all_comparisons.size()) && (some_matches) )
     {
       new_nodes.clear();
       new_nodes = all_comparisons[0][sp_i].matches(win_i);
       if (new_nodes.empty())
-       some_matches = false;
+        some_matches = false;
 
       all_matches.push_back(new_nodes);
       sp_i++;
@@ -172,10 +171,10 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
       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++)
+      for (sp_i = 0; sp_i < all_comparisons.size()-1; sp_i++)
       {
-       sp_nodes.push_back(all_matches[sp_i].begin());
-       sp_nodes_end.push_back(all_matches[sp_i].end());
+        sp_nodes.push_back(all_matches[sp_i].begin());
+        sp_nodes_end.push_back(all_matches[sp_i].end());
       }
 
       still_paths = true;
@@ -187,7 +186,7 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
        path.push_back(win_i);
        
        //cout << win_i;
-       for (sp_i = 0; sp_i < species_num-1; sp_i++)
+       for (sp_i = 0; sp_i < all_comparisons.size()-1; sp_i++)
        {
          //cout  << ", " << *(sp_nodes[sp_i]);
          path.push_back(*(sp_nodes[sp_i]));
@@ -201,13 +200,13 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
 
        // now advance the right iterator
        not_advanced = true;
-       sp_depth = species_num - 2;       // this roves up & down species list
+       sp_depth = all_comparisons.size()- 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;
+    //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])
@@ -224,7 +223,7 @@ Nway_Paths::entropy_path_search(vector<vector<FLPs> > all_comparisons)
        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;
+         sp_depth = all_comparisons.size() - 2;
       }
     }
   }
index 51e9622240ca44ab0cb467292cd2233b7d915f93..288af56a49420a16160887a531074bdd470ed811 100644 (file)
 using namespace std;
 
 //! dump the matches for a particular window
-void dump_matches_win(int win_i, int species_num, vector<list<int> > all_matches)
+void dump_matches_win(int win_i, vector<list<int> > all_matches)
 {    
   cout << "<win_debug win=" << win_i << ">" << endl;
-  for (int sp_i = 0; sp_i < species_num-1; sp_i++)
+  for (vector<list<int> >::const_iterator sp_i = all_matches.begin(); 
+      sp_i != all_matches.end(); 
+      ++sp_i)
   {
-    cout << "sp " << sp_i << ": ";
-    for(list<int>::iterator debug_i = all_matches[sp_i].begin();
-        debug_i != all_matches[sp_i].end();
+    for(list<int>::const_iterator debug_i = sp_i->begin();
+        debug_i != sp_i->end();
         ++debug_i)
     {
       cout << *debug_i << " ";
@@ -136,7 +137,7 @@ bool advance_sp_itor_track(vector<list<int>::iterator>& sp_itor_begin,
 }
 
 void
-Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
+NwayPaths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
 {
   vector<int> path;
   int win_i, window_num;
@@ -156,7 +157,7 @@ Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
     // paths out of all these matches (in all_matches)
     if(make_all_seq_win_matches(all_comparisons, all_matches, win_i, soft_thres))
     {
-      //debug dump_matches_win(win_i, species_num, all_matches);
+      //debug dump_matches_win(win_i, all_matches);
       reset_species_iterators(all_matches, sp_itor_begin, sp_itor_end);
 
       still_paths = true;
@@ -207,9 +208,8 @@ bool is_transitive_path(const vector<int>& path,
 }
 
 void
-Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
+NwayPaths::trans_path_search(vector<vector<FLPs> > all_comparisons)
 {
-  assert (species_num == all_comparisons.size());
   vector<int> path;
   int win_i, window_num;
   bool still_paths;
@@ -225,7 +225,7 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
   pathz.clear();
   window_num = all_comparisons[0][1].size();
   cout << "window number = " << window_num << endl;   // just a sanity check
-  cout << "trans: species_num = " << species_num << endl;
+  cout << "trans: comparison size= " << all_comparisons.size() << endl;
   // loop thru all windows in first species
   for (win_i = 0; win_i < window_num; win_i++)
   {
@@ -233,7 +233,7 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
     // then make all possible paths out of all these matches (in all_matches)
     if(make_all_seq_win_matches(all_comparisons, all_matches, win_i, soft_thres))
     {
-      //debug? //dump_matches_win(win_i, species_num, all_matches);
+      //debug? //dump_matches_win(win_i, all_matches);
       reset_species_iterators(all_matches, sp_itor_begin, sp_itor_end);
       still_paths = true;
       while (still_paths) 
@@ -242,10 +242,10 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
         // advanced.
         set_path_to_cur_sp_itor_track(path, win_i, sp_itor_begin);
 
-
         // if the path is transitive, save the path
         if (is_transitive_path(path, all_comparisons, soft_thres))
           pathz.push_back(path);
+
         // now advance the right iterator
         still_paths = advance_sp_itor_track(sp_itor_begin, 
                                             sp_itor_end, 
@@ -253,101 +253,8 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
       }
     }
   }
+  clog << "all_cmp=" << all_comparisons.size() 
+       << " path_size=" << pathz.begin()->size() << endl;
+  assert (   (pathz.begin()->size() == 0) 
+          || (all_comparisons.size() == pathz.begin()->size()));
 }
-
-
-
-
-/*
-  // 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))
-*/
index 50e85d9c7622c77c487ac0b9899a3b40529e1d66..502a842afae6f65000106e107287ebc67fdffc10 100644 (file)
 
 using namespace std;
 
-Nway_Paths::Nway_Paths()
+NwayPaths::NwayPaths()
 {
 }
 
 void
-Nway_Paths::setup(int sp_num, int w, int t)
+NwayPaths::setup(int w, int t)
 {
-  species_num = sp_num;
   threshold = t;
   soft_thres = threshold;
   win_size = w;
   pathz.clear();
 
-  cout << "nway: species_num = " << species_num << ", thres = " << threshold
-       << ", softo = " << soft_thres << endl;
+  cout << "nway: thres = " << threshold
+       << ", soft threo = " << soft_thres << endl;
 }
 
 void
-Nway_Paths::set_soft_thres(int sft_thres)
+NwayPaths::set_soft_thres(int sft_thres)
 {
   soft_thres = sft_thres;
 }
@@ -47,15 +46,13 @@ Nway_Paths::set_soft_thres(int sft_thres)
 // dumbly goes thru and combines path windows exactly adjacent (ie + 1 index)
 // doesn't deal with interleaved adjacency
 void
-Nway_Paths::simple_refine()
+NwayPaths::simple_refine()
 {
   // ext_path remembers the first window set in an extending path
   vector<int> ext_path, cur_path, next_path, new_path;
   list<vector<int> >::iterator pathz_i;
-  int i2, win_ext_len = 0;
+  int win_ext_len = 0;
   bool extending, end = false;
-  int count_loop = 0;
-
 
   refined_pathz.clear();
 
@@ -78,7 +75,7 @@ Nway_Paths::simple_refine()
       // if node for each seq is equal to the next node+1 then for all
       // sequences then we are extending
       extending = true;
-      for(i2 = 0; i2 < species_num; i2++)
+      for(vector<int>::size_type i2 = 0; i2 != pathz_i->size(); i2++)
       {
         //cout << cur_path[i2] << " vs " << endl;
         //cout << next_path[i2] << endl; 
@@ -99,7 +96,7 @@ Nway_Paths::simple_refine()
       // add the extend window length as first element and add as refined
       new_path = ext_path;
       new_path.insert(new_path.begin(),win_size + win_ext_len);
-      for(i2 = 1; i2 <= species_num; i2++)
+      for(vector<int>::size_type i2 = 1; i2 <= pathz_i->size(); i2++)
       {
         if (new_path[i2] < 0)
         {
@@ -119,23 +116,23 @@ Nway_Paths::simple_refine()
 
 
 void
-Nway_Paths::add_path(vector<int> loaded_path)
+NwayPaths::add_path(vector<int> loaded_path)
 {
   pathz.push_back(loaded_path);
 }
 
 
 void
-Nway_Paths::save(string save_file_path)
+NwayPaths::save(string save_file_path)
 {
   fstream save_file;
   list<vector<int> >::iterator path_i, paths_end;
   vector<int> a_path;
-  int i;
+  unsigned int i;
 
   save_file.open(save_file_path.c_str(), ios::out);
 
-  save_file << "<Mussa type=flp seq_num=" << species_num;
+  save_file << "<Mussa type=flp seq_count=" << sequence_count();
   save_file << " win=" << win_size;
   // add a function para new_thres defaults to -1 to later deal with
   // reanalysis with higher thres - if statement whether to record base thres
@@ -152,10 +149,10 @@ Nway_Paths::save(string save_file_path)
     //cout << a_path.size() << endl;
     //first entry is the window length of the windows in the path
     save_file << a_path[0] << ":";
-    for(i = 1; i <= species_num; ++i)
+    for(i = 1; i <= sequence_count(); ++i)
     {
       save_file << a_path[i];
-      if (i != species_num)
+      if (i != sequence_count())
         save_file << ",";
     }
     save_file << endl;
@@ -168,14 +165,17 @@ Nway_Paths::save(string save_file_path)
 
 
 int
-Nway_Paths::seq_num()
+NwayPaths::sequence_count()
 {
-  return species_num;
+  if (pathz.begin() == pathz.end() )
+    return 0;
+  else
+    return pathz.begin()->size();
 }
 
 
 string
-Nway_Paths::load(string load_file_path)
+NwayPaths::load(string load_file_path)
 {
   fstream load_file;
   string file_data_line, header_data, data, path_node, path_length;
@@ -183,7 +183,6 @@ Nway_Paths::load(string load_file_path)
   vector<int> loaded_path;
   string err_msg;
 
-
   load_file.open(load_file_path.c_str(), ios::in);
 
   if (!load_file)
@@ -208,7 +207,7 @@ Nway_Paths::load(string load_file_path)
   header_data = file_data_line.substr(0,space_split_i); 
   equal_split_i = header_data.find("=");
   data = file_data_line.substr(equal_split_i+1); 
-  species_num = atoi (data.c_str());
+  unsigned int species_num = atoi (data.c_str());
   file_data_line = file_data_line.substr(space_split_i+1);
   // get window size
   space_split_i = file_data_line.find(" ");
@@ -256,7 +255,6 @@ Nway_Paths::load(string load_file_path)
     getline(load_file,file_data_line);
   }
 
-
   load_file.close();
 
   return "";
@@ -267,7 +265,7 @@ Nway_Paths::load(string load_file_path)
 
 
 void
-Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
+NwayPaths::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;
@@ -303,7 +301,7 @@ Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path,
       else
         path.push_back(*new_nodes_i * -1);
 
-      if (depth < species_num - 1)
+      if (depth < all_comparisons.size() - 1)
         path_search(all_comparisons, path, depth + 1);
       else
         pathz.push_back(path);
@@ -320,7 +318,7 @@ Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path,
 */
 
 void
-Nway_Paths::find_paths_r(vector<vector<FLPs> > all_comparisons)
+NwayPaths::find_paths_r(vector<vector<FLPs> > all_comparisons)
 {
   vector<int> path;
   int win_i, window_num;
@@ -354,7 +352,7 @@ Nway_Paths::find_paths_r(vector<vector<FLPs> > all_comparisons)
 
 
 void
-Nway_Paths::save_old(string save_file_path)
+NwayPaths::save_old(string save_file_path)
 {
   fstream save_file;
   list<vector<int> >::iterator path_i, paths_end;
@@ -369,7 +367,7 @@ Nway_Paths::save_old(string save_file_path)
   {
     a_path = *path_i;
     //cout << a_path.size() << endl;
-    for(i = 0; i < species_num; ++i)
+    for(i = 0; i < path_i->size(); ++i)
       save_file << i << "," << a_path[i] << " ";
     save_file << endl;
     ++path_i;
@@ -380,7 +378,7 @@ Nway_Paths::save_old(string save_file_path)
 
 /*
 void
-Nway_Paths::find_paths(vector<vector<FLPs> > all_comparisons)
+NwayPaths::find_paths(vector<vector<FLPs> > all_comparisons)
 {
   int win_i, sp_i;
   vector<list<list<int> > > path_src_tree;
@@ -389,14 +387,14 @@ Nway_Paths::find_paths(vector<vector<FLPs> > all_comparisons)
   <list<list<int> > >::iterator branch_i, branch_end;  
 
   pathz.clear();
-  path_src_tree.reserve(species_num - 1);
+  path_src_tree.reserve(all_comparisons.size()- 1);
 
 
   // loop thru all windows in first species
   for (win_i = 0; win_i < window_num; win_i++)
   {
     // clear the path search tree
-    for(i = 0; i < species_num; i++)
+    for(i = 0; i < all_comparisons.size(); i++)
       path_src_tree[i].clear();
 
     // top level kept empty even tho implicity has one entry of the first
@@ -411,7 +409,7 @@ Nway_Paths::find_paths(vector<vector<FLPs> > all_comparisons)
     // go across all species
     // if path search tree becomes empty, break out of loop, no reason to search further
     sp_i = 1;
-    while ((sp_i < species_num) && (path tree not empty))
+    while ((sp_i < all_comparisons.size()) && (path tree not empty))
     {
       branch_i = path_src_tree[1].begin();
       branch_end = path_src_tree[1].end();
@@ -437,13 +435,13 @@ Nway_Paths::find_paths(vector<vector<FLPs> > all_comparisons)
   }
 }
 
-void Nway_Paths::refine()
+void NwayPaths::refine()
 {
 }
 */
 
 
-void Nway_Paths::print(list<vector<int> >& dump_path)
+void NwayPaths::print(list<vector<int> >& dump_path)
 {
   list<vector<int> >::iterator pathz_i;
   vector<int>::iterator path_i;
index 5a055ca2cf01e564892dac5e02df9a539deeef00..1889b048b6bc85a9df982a4827db32ad4a8032a6 100644 (file)
 
 #include "alg/flp.hh"
 
-class Nway_Paths
+class NwayPaths
 {
   friend class ConnView;
   friend class SeqView;
   protected:
-    int species_num;
     int threshold;
     int win_size;
     int soft_thres;
 
     double ent_thres;
-    std::vector<char *> c_sequences;
+    std::vector<char *> c_sequences; //used by entropy_path_search
 
   public:
-    Nway_Paths();
+    NwayPaths();
     //! setup an nway comparison, initialize # of species, window size, 
     //! threshold
-    void setup(int sp_num, int w, int t);
+    void setup(int w, int t);
     void setup_ent(double new_entropy_thres, std::vector<std::string> some_Seqs);
     void set_soft_thres(int soft_thres);
 
@@ -54,7 +53,8 @@ class Nway_Paths
     void save(std::string save_file_path);
     std::string load(std::string load_file_path);
     void add_path(std::vector<int> loaded_path);
-    int seq_num();
+    //! how many sequences are in our comparison
+    int sequence_count();
 
     void find_paths(std::vector<std::vector<FLPs> > all_comparisons);
     void refine();
index e72714c2c7ceadf7f7a553577333b161e8e537fa..7e2290512d2fa4b28e3caafc023dccb32a5f83f2 100644 (file)
@@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE( nway_null )
   analysis.add_a_seq(s1);
   analysis.add_a_seq(s2);
   analysis.analyze(4,3);
-  Nway_Paths npath = analysis.paths();
+  NwayPaths npath = analysis.paths();
   // there should be no paths for these sequences
   for (std::list<std::vector<int> >::iterator pathz_i = npath.pathz.begin();
        pathz_i != npath.pathz.end();
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( nway_test )
   analysis.add_a_seq(s0);
   analysis.add_a_seq(s1);
   analysis.analyze(4,3);
-  Nway_Paths npath = analysis.paths();
+  NwayPaths npath = analysis.paths();
   for (std::list<std::vector<int> >::iterator pathz_i = npath.pathz.begin();
        pathz_i != npath.pathz.end();
        ++pathz_i)
index c11db9932b0e380c4a8b21b7d1f95593d8b1916e..25f622b3c78e8533a48fac56ecb30b51f31986a4 100644 (file)
@@ -21,7 +21,7 @@ using namespace std;
 void
 ConnView::setup(string name, int sq_num, int win_len,
                 vector<Sequence> *some_seqs,
-                Nway_Paths *some_paths)
+                NwayPaths *some_paths)
 {
   int i, i2, seq_length;
   Sequence a_seq;
index 91a30f09971b0db9522aa41863b38e60192d12e3..923b0f594fc673a5702633d24b517a7702240003 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <FL/Fl_Box.H>
 
-class Nway_Paths;
+class NwayPaths;
 class ConnView : public Fl_Box
 {
   public:
@@ -32,7 +32,7 @@ class ConnView : public Fl_Box
     {}
 
     void setup(std::string name, int sq_num, int win_len,
-               std::vector<Sequence> *, Nway_Paths *);
+               std::vector<Sequence> *, NwayPaths *);
     void scale_paths();
 
     void spawnSeq();
@@ -53,7 +53,7 @@ class ConnView : public Fl_Box
   //this data is passed as pointers to the instantiated classes
     std::vector<Sequence> *S;
     //! Store the nway paths our analysis did, we mostly need the refined paths
-    Nway_Paths *P;
+    NwayPaths *P;
 
     int name_pad, y_pad;
     float x_scale_factor;
index 3fcc9d0f380763ee4997489adb194c2ab352ed50..e1faa342daf022913589060f044c07f85953b298 100644 (file)
@@ -289,7 +289,7 @@ void PathScene::draw_lines() const
   GLfloat y;
   bool reversed = false;
   bool prevReversed = false;
-  const Nway_Paths& nway = mussaAnalysis.paths();
+  const NwayPaths& nway = mussaAnalysis.paths();
 
   glLineWidth(0.5);
   vector<GlSequence>::const_iterator track_itor;