Added qPCR Validation design code
[htsworkflow.git] / htswanalysis / src / profile_reads_against_features.cpp
index 8cc62ef920d9e9c404cb397a53649c69f5bdcdc0..7f32b931ef602d3b42b4570ebcbd6237701a4cf5 100755 (executable)
@@ -11,18 +11,15 @@ using namespace std;
 
 vector<int> profile(2000,0);
 
-void int_to_chromstr(int chrom, char* chr);
-int chromstr_to_int(string chrom);
-
 void split (const string& text, const string& separators, vector<string>& words);
 
 class Hit {
   public:
-    int chr;
+    string chr;
     unsigned int pos;
     bool strand;
 
-    Hit(int chr, unsigned int pos, bool strand) {
+    Hit(string chr, unsigned int pos, bool strand) {
       this->chr = chr; this->pos = pos; this->strand = strand;
     }
 };
@@ -60,8 +57,8 @@ int main(int argc, char** argv) {
     split(line_str, delim, fields);
     if(fields.size() != 3) { cerr << "Error: wrong number of fields in feature list (line " << N << " has " << fields.size() << " fields)\n"; }
 
-    int chr = chromstr_to_int(fields[0]);
-    if(chr == -1) { continue; }
+    string chr = fields[0];
+
     int pos = atoi(fields[1].c_str());
     bool strand = (bool)(atoi(fields[2].c_str()));
 
@@ -78,7 +75,9 @@ int main(int argc, char** argv) {
   location_delim = ":";
   char strand_str[2]; strand_str[1] = '\0';
   ifstream seqs(filename);
+  unsigned int linenum = 0;
   while(seqs.peek() != EOF) {
+    cerr << ++linenum << endl;
     char line[2048];
     seqs.getline(line,2048,'\n');
     string line_str(line);
@@ -87,8 +86,8 @@ int main(int argc, char** argv) {
     if(fields.size() == 3) { continue; }
  
     vector<string> location; split(fields[3], location_delim, location);
-    int chr = chromstr_to_int(location[0]);
-    if(chr == -1) { continue; }
+    string chr = location[0];
+
     int pos = atoi(location[1].c_str());
     bool strand = ((fields[4].c_str())[0] == 'F')?0:1;
 
@@ -102,17 +101,17 @@ int main(int argc, char** argv) {
   //sort the data so we can run through it once
   std::sort(data.begin(),data.end(),compare_hits);
   
-  int chrom = -1
+  string chrom = ""
   unsigned int feat_idx = 0;
   int num_hits = 0;
   for(Hits::iterator i = data.begin(); i != data.end(); ++i) {
     num_hits++;
-    if(chrom == -1 || i->chr != chrom) {
+    if(chrom == "" || i->chr != chrom) {
       chrom = i->chr;
       feat_idx = 0;
       while(feat_idx < features.size() && features[feat_idx].chr != chrom) { feat_idx++; }
       if(feat_idx == features.size()) { break; }
-      cerr << chrom << " feat_idx: " << feat_idx << endl;
+      cerr << chrom.c_str() << " feat_idx: " << feat_idx << endl;
     }
 
     int dist_to_feature = i->pos - features[feat_idx].pos;
@@ -137,29 +136,6 @@ int main(int argc, char** argv) {
   }
 }
 
-int chromstr_to_int(string chromstr) {
-  const char* chrom = chromstr.c_str();
-  if(chrom[0] != 'c' || chrom[1] != 'h' || chrom[2] != 'r') { return -1; }
-  if(chrom[3] == 'X') { return 23; } else
-  if(chrom[3] == 'Y') { return 24; } else
-  if(chrom[3] == 'M') { return 25; } else
-  if(chrom[3] >= '0' && chrom[3] <= '9') { return atoi(chrom+3); } else 
-  { return -1; } 
-}
-
-void int_to_chromstr(int chrom, char* chr) {
-  strcpy(chr,"chr\0\0\0");
-  switch(chrom) {
-    case 23: chr[3]='X'; break;
-    case 24: chr[3]='Y'; break;
-    case 25: chr[3]='M'; break;
-    default: chr[3]=(char)(48+(int)(chrom/10));
-             chr[4]=(char)(48+(int)(chrom - 10*(int)(chrom/10)));
-             if(chr[3]=='0') { chr[3]=chr[4]; chr[4]='\0'; }
-  }
-}
-  
-
 void split (const string& text, const string& separators, vector<string>& words) {
 
     size_t n     = text.length ();