Browse code

Updated files because of warnings!

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Rtreemix@74741 bc3139a8-67e5-0310-9ffc-ced21a209358

Jasmina Bogojeska authored on 23/03/2013 15:16:54
Showing4 changed files

... ...
@@ -11,6 +11,10 @@
11 11
 #include "include/kmeans.h"
12 12
 #include "include/mtree.h"
13 13
 
14
+//R includes
15
+#include <R.h>
16
+#include <Rdefines.h>
17
+
14 18
 
15 19
 int argmin(vector& x, array<vector>& M)
16 20
 {
... ...
@@ -56,9 +60,10 @@ array<vector> kmeans_init(int K, matrix& X, double min_diff = 1e-10)
56 60
       
57 61
   if (i >= N)  // failure
58 62
     {
59
-      std::cerr << "k-means: Unable to find k = " << K << " sufficiently (min_diff >= " << min_diff << ") different vectors!" << std::endl
60
-		<< "         Try changing k or min_diff." << std::endl;
61
-      exit(1);
63
+      //std::cerr << "k-means: Unable to find k = " << K << " sufficiently (min_diff >= " << min_diff << ") different vectors!" << std::endl
64
+		//<< "         Try changing k or min_diff." << std::endl;
65
+      //exit(1);
66
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n k-means: Unable to find k = %d sufficiently (min_diff >= %5.3e) different vectors!\n Try changing k or min_diff.\n", K, min_diff);
62 67
     }
63 68
   
64 69
   return M;
... ...
@@ -11,6 +11,10 @@
11 11
 
12 12
 #include "include/mtree.h"
13 13
 
14
+//R includes
15
+#include <R.h>
16
+#include <Rdefines.h>
17
+
14 18
 
15 19
 array<string> load_profile(char *filestem, int L)
16 20
 {
... ...
@@ -40,8 +44,9 @@ array<string> load_profile(char *filestem, int L)
40 44
       
41 45
       if (j != L)
42 46
 	{
43
-	  std::cerr << "Number of profile labels does not coincide with number of data columns and/or model dimensions!" << std::endl;
44
-	  exit(1);
47
+	  //std::cerr << "Number of profile labels does not coincide with number of data columns and/or model dimensions!" << std::endl;
48
+	  //exit(1);
49
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Number of profile labels does not coincide with number of data columns and/or model dimensions!\n see warnings() and restart R", 1);
45 50
 	}
46 51
     }
47 52
 
... ...
@@ -67,8 +72,9 @@ void save_profile(array<string>& profile, char* filestem)
67 72
   std::ofstream prf(filename);
68 73
   if (! prf)
69 74
     {
70
-      std::cerr << "Can't open output file -- " << filename << std::endl;
71
-      exit(1);
75
+      //std::cerr << "Can't open output file -- " << filename << std::endl;
76
+      //exit(1);
77
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Can't open output file %s!\n see warnings() and restart R", 1, filename);
72 78
     }
73 79
   
74 80
   for (int j=0; j<L; j++)
... ...
@@ -90,8 +96,9 @@ integer_matrix load_pattern(char *filestem)
90 96
   std::ifstream patfile(filename);
91 97
   if (! patfile)
92 98
     {
93
-      std::cerr << "Can't open input file -- " << filename << std::endl;
94
-      exit(1);
99
+      //std::cerr << "Can't open input file -- " << filename << std::endl;
100
+      //exit(1);
101
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Can't open input file %s!\n see warnings() and restart R", 1, filename);
95 102
     }
96 103
   patfile >> pattern;
97 104
   patfile.close();
... ...
@@ -109,8 +116,9 @@ void save_pattern(integer_matrix& pattern, char *filestem)
109 116
   std::ofstream patfile(filename);
110 117
   if (! patfile)
111 118
     {
112
-      std::cerr << "Can't open output file -- " << filename << std::endl;
113
-      exit(1);
119
+      //std::cerr << "Can't open output file -- " << filename << std::endl;
120
+      //exit(1);
121
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Can't open output file %s!\n see warnings() and restart R", 1, filename);
114 122
     }
115 123
   patfile << pattern;
116 124
   patfile.close();
... ...
@@ -147,7 +155,8 @@ matrix pair_probs(integer_matrix& pat, vector& resp)
147 155
 	
148 156
 	if (count == 0)  // no data in the column pair (j1,j2)
149 157
 	  {
150
-	    std::cerr << "Warning: No data in column pair (" << j1 << ", " << j2 << ")! Assuming independence." << std::endl;
158
+	    //std::cerr << "Warning: No data in column pair (" << j1 << ", " << j2 << ")! Assuming independence." << std::endl;
159
+		Rprintf("Warning: No data in column pair (%d, %d)! Assuming independence!\n", j1, j2);
151 160
 	    wcount = P(0,j1) * P(0,j2);  // assuming independence
152 161
 	  }
153 162
 	
... ...
@@ -10,6 +10,9 @@
10 10
 
11 11
 #include "include/mtree.h"
12 12
 #include "include/mtreemix.h"
13
+//R includes
14
+#include <R.h>
15
+#include <Rdefines.h>
13 16
 
14 17
 vector event_freq(integer_matrix& pat)
15 18
 {
... ...
@@ -24,8 +27,9 @@ vector event_freq(integer_matrix& pat)
24 27
       freq[j] = nonnegmean(col);  // == rel. frequency
25 28
       if (freq[j] < 0.0)  // no data in this column!
26 29
 	{
27
-	  std::cerr << "No data in column " << j << " !" << std::endl;
28
-	  exit(1);
30
+	  //std::cerr << "No data in column " << j << " !" << std::endl;
31
+	  //exit(1);	
32
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n No data in column %2d!\n see warnings() and restart R", 1, j);
29 33
 	}
30 34
     }
31 35
 
... ...
@@ -460,11 +464,12 @@ double mtreemix_EM(array<string>& profile, integer_matrix& pattern, int K, int M
460 464
 	  double sum = oneK * wlike.row(i);  // sum of weighted likelihoods
461 465
 	  if (sum <= 0.0)
462 466
 	    {
463
-	      std::cerr << "EM aborted. Sample no. " << i + 1
464
-			<< " [" << pat_hat.row(i) << "] "
465
-			<< "has likelihood zero!" << std::endl;
467
+	      //std::cerr << "EM aborted. Sample no. " << i + 1
468
+			//<< " [" << pat_hat.row(i) << "] "
469
+			//<< "has likelihood zero!" << std::endl;
466 470
 	      // mtreemix_save(alpha, G, cond_prob, node_no, "Lzero");  // save model for diagnostics
467
-	      exit(1);
471
+	      //exit(1);
472
+		  Rf_error("internal: mtreemix invoked 'exit(%d)'\n EM aborted. Sample no. %2d has likelihood zero!\n see warnings() and restart R", 1, i + 1);
468 473
 	    }
469 474
 	  
470 475
 	  for (int k=0; k<K; k++)
... ...
@@ -589,11 +594,12 @@ double mtreemix_E_step(integer_matrix& pattern, int K, vector& alpha, array< gra
589 594
 	  double sum = oneK * wlike.row(i);  // sum of weighted likelihoods
590 595
 	  if (sum <= 0.0)
591 596
 	    {
592
-	      std::cerr << "E-step aborted. Sample no. " << i + 1
593
-			<< " [" << pat_hat.row(i) << "] "
594
-			<< "has likelihood zero!" << std::endl;
597
+	      //std::cerr << "E-step aborted. Sample no. " << i + 1
598
+			//<< " [" << pat_hat.row(i) << "] "
599
+		//	<< "has likelihood zero!" << std::endl;
595 600
 	      // mtreemix_save(alpha, G, cond_prob, node_no, "Lzero");  // save model for diagnostics
596
-	      exit(1);
601
+	      //exit(1);
602
+		  Rf_error("internal: mtreemix invoked 'exit(%d)'\n EM aborted. Sample no. %2d has likelihood zero!\n see warnings() and restart R", 1, i + 1);
597 603
 	    }
598 604
 	  
599 605
 	  for (int k=0; k<K; k++)
... ...
@@ -623,7 +629,8 @@ double mtreemix_loglike(integer_matrix& pattern, int K, vector& alpha, array<gra
623 629
 
624 630
       if (sum <= 0.0)
625 631
 	{
626
-	  std::cerr << "Warning: The sample: [" << pattern.row(i) << "] has likelihood zero!" << std::endl;
632
+	  //std::cerr << "Warning: The sample: [" << pattern.row(i) << "] has likelihood zero!" << std::endl;
633
+	  Rprintf("Warning: Sample no. %2d has likelihood zero!", i);
627 634
 	}
628 635
       
629 636
       logL += log(sum);
... ...
@@ -733,8 +740,9 @@ void mtreemix_save(vector& alpha, array< graph >& G, array< map<edge,double> >&
733 740
   std::ofstream mtreemix(filename);
734 741
   if (! mtreemix)
735 742
     {
736
-      std::cerr << "Can't open output file -- " << filename << std::endl;
737
-      exit(1);
743
+      //std::cerr << "Can't open output file -- " << filename << std::endl;
744
+      //exit(1);
745
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Can't open output file %s!\n see warnings() and restart R", 1, filename);
738 746
     }
739 747
 
740 748
   mtreemix << alpha << std::endl;
... ...
@@ -766,8 +774,9 @@ array<string> mtreemix_load(vector& alpha, array< graph >& G, array< map<node,st
766 774
   std::ifstream mtreemix(filename);
767 775
   if (! mtreemix)
768 776
     {
769
-      std::cerr << "Can't open input file -- " << filename << std::endl;
770
-      exit(1);
777
+      //std::cerr << "Can't open input file -- " << filename << std::endl;
778
+      //exit(1);
779
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Can't open input file %s!\n see warnings() and restart R", 1, filename);
771 780
     }
772 781
   
773 782
   mtreemix >> alpha >> std::ws;
... ...
@@ -880,8 +889,9 @@ array< map<edge,double> > waiting_times(array< map<edge,double> >& cond_prob, in
880 889
       break;
881 890
     
882 891
     default :
883
-      std::cerr << "Unknown sampling_mode -- " << sampling_mode << std::endl;
884
-      exit(1);
892
+      //std::cerr << "Unknown sampling_mode -- " << sampling_mode << std::endl;
893
+      //exit(1);
894
+	  Rf_error("internal: mtreemix invoked 'exit(%d)'\n Unknown sampling mode %2d!\n see warnings() and restart R", 1, sampling_mode);
885 895
     }
886 896
   return lambda;
887 897
 }
... ...
@@ -4,6 +4,10 @@
4 4
 #include <cstdarg>
5 5
 #include <sstream>
6 6
 
7
+//R includes
8
+#include <R.h>
9
+#include <Rdefines.h>
10
+
7 11
 //using namespace replaceleda;
8 12
 
9 13
 //template<class T>
... ...
@@ -364,9 +368,10 @@ void replaceleda::printGraph (replaceleda::graph &g, edge_array<double> &weights
364 368
    node v;
365 369
     edge e;
366 370
     
367
-    std::cerr << "#nodes: " << g.number_of_nodes() << " #edges: " << g.number_of_edges() << std::endl;
371
+    //std::cerr << "#nodes: " << g.number_of_nodes() << " #edges: " << g.number_of_edges() << std::endl;
372
+	Rprintf("#nodes %2d #edges %2d\n", g.number_of_nodes(), g.number_of_edges());
368 373
     list<node> xxx = g.all_nodes();
369
-    
374
+    /*
370 375
     forall_nodes(v, g){
371 376
 	std::cerr << v << " " << v->getIndex() << std::endl;
372 377
 	std::cerr << "(" << g.indeg(v) << "," << g.outdeg(v) << "," << g.degree(v) << "):" << std::endl;
... ...
@@ -376,7 +381,7 @@ void replaceleda::printGraph (replaceleda::graph &g, edge_array<double> &weights
376 381
 	    std::cerr << v->getIndex() << " -" << weights[e] << "-> " << t->getIndex() << std::endl; 
377 382
 	}
378 383
     }
379
-
384
+	*/
380 385
    
381 386
 
382 387
 }