[project @ 13]
[mussa.git] / flp.cc
diff --git a/flp.cc b/flp.cc
index 300dd8aef4925d6bc9905a484d555740299cd00c..801060c2b928163456c53e4b0ee040298b848e6a 100644 (file)
--- a/flp.cc
+++ b/flp.cc
@@ -1,3 +1,13 @@
+//  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.
+
+
 //                        ----------------------------------------
 //                            ---------- flp.cc  -----------
 //                        ----------------------------------------
@@ -81,6 +91,32 @@ FLPs::matches(int index)
   return these_matches;
 }
 
+list<int>
+FLPs::thres_matches(int index, int thres)
+{
+  list<int> thres_matches;
+  list<match>::iterator list_i, list_end;
+
+  index = abs(index);
+  list_i = all_matches[index].begin();
+  list_end = all_matches[index].end();
+  thres_matches.clear();
+
+  //if (list_i == list_end)
+  //cout << "its fuckin empty!!!!";
+  while (list_i != list_end)
+  {
+    if (list_i->score >= thres)
+      thres_matches.push_back(list_i->index);
+    //cout << list_i->index << " ";
+
+    ++list_i;
+  }
+  //cout << endl;
+
+  return thres_matches;
+}
+
 
 void
 FLPs::file_save(string save_file_path)
@@ -118,9 +154,17 @@ void
 FLPs::file_load(string file_path)
 {
   fstream data_file;
-  string file_data, file_data_line, index_data, score_data;
-  int type, window, hard_thres, index, score;
+  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;
+
+
+
+
 
 
   data_file.open(file_path.c_str(), ios::in);
@@ -133,25 +177,47 @@ FLPs::file_load(string file_path)
 
   while ((!data_file.eof()) && tag_open)
   {
+    // intialize list to empty
+    a_match_list.clear();
+
     getline(data_file,file_data_line);
-    /*
-    if ( = "</Seqcomp>")
+    
+    if (file_data_line == "</Seqcomp>")
       tag_open = false;
     // parse line of matches
+    else if (file_data_line == "")
+    {
+      //cout << "empty line\n";
+      all_matches.push_back(a_match_list); 
+    }
     else
     {
-      needs stuff...um, code...
-      {
-      index = atoi(index_data);
-      core = atoi(score_data);
-      cout << index << "," << score << " ";
-      data_file >> index_data;
+      split_index = file_data_line.find(" ");
+      
+      while (split_index != string::npos)
       {
+       pair_data = file_data_line.substr(0,split_index); 
+       file_data_line = file_data_line.substr(split_index+1);
+       //cout << "pair_data = " << pair_data << "...";
+       // parse out the 2 pieces of data, index and score of pair match
+        comma_index = pair_data.find(",");
+        index_data = pair_data.substr(0, comma_index);
+       a_match.index = atoi(index_data.c_str() );
+       score_data = pair_data.substr(comma_index+1); 
+       a_match.score = atoi(score_data.c_str() );
+
+       //cout << a_match.index << "," << a_match.score << " ";
+
+       a_match_list.push_back(a_match);
+
+       split_index = file_data_line.find(" ");
+      }
+      //cout << "\n";
+      all_matches.push_back(a_match_list); 
     }
-    cout << "\n";
-    */
   }
-
+  seq1_win_num = all_matches.size();
+  cout << "windows in flp = " << all_matches.size() << endl;
   data_file.close();
 }