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