Browse code

Merge branch 'master' of github.com:sneumann/Rdisop

Steffen Neumann authored on 01/04/2019 19:34:12
Showing3 changed files

... ...
@@ -9,8 +9,8 @@ Description: Identification of metabolites using high precision mass
9 9
              of sum formulae, alternatively for a given sum formula
10 10
              the theoretical isotope distribution can be calculated 
11 11
              to search in MS peak lists.
12
-Depends: R (>= 2.0.0), RcppClassic
13
-LinkingTo: RcppClassic, Rcpp
12
+Depends: R (>= 2.0.0), Rcpp
13
+LinkingTo: Rcpp
14 14
 Suggests: RUnit
15 15
 SystemRequirements: None
16 16
 License: GPL-2
... ...
@@ -1,3 +1,4 @@
1 1
 # echo "useDynLib(Rdisop)" ; echo -n "export(" ; grep --no-filename "<- function" R/*.R | cut -d" " -f 1 | grep -v First.lib | grep -v getElement | sort |  xargs echo -n | tr " " , ; echo ")"
2 2
 useDynLib(Rdisop)
3 3
 export(addMolecules,decomposeIsotopes,decomposeMass,getMass,getFormula,getIsotope,getValid,getMolecule,getScore,initializeCHNOPS,initializeCHNOPSMgKCaFe,initializeCHNOPSNaK,initializeElements,initializePSE,initializeCharges,isotopeScore,subMolecules)
4
+import(Rcpp)
4 5
\ No newline at end of file
... ...
@@ -30,13 +30,13 @@
30 30
 //
31 31
 // R Stuff
32 32
 //
33
-#include <RcppClassic.h>
33
+#include <Rcpp.h>
34 34
 extern "C" {
35 35
 #include <Rdefines.h>
36 36
 #include <Rinternals.h>
37 37
 #include <R_ext/Rdynload.h>
38 38
 }
39
-
39
+using namespace Rcpp;
40 40
 using namespace ims;
41 41
 using namespace std;
42 42
 
... ...
@@ -169,8 +169,8 @@ RcppExport SEXP decomposeIsotopes(SEXP v_masses, SEXP v_abundances, SEXP s_error
169 169
     SEXP  rl=R_NilValue; // Use this when there is nothing to be returned.
170 170
     try {
171 171
 
172
-	RcppVector<double> masses = RcppVector<double>(v_masses);
173
-	RcppVector<double> abundances = RcppVector<double>(v_abundances);
172
+	NumericVector masses = NumericVector(v_masses);
173
+	NumericVector abundances = NumericVector(v_abundances);
174 174
 	double error = *REAL(s_error);
175 175
 
176 176
 	// converts relative (ppm) in absolute error 
... ...
@@ -342,11 +342,13 @@ RcppExport SEXP decomposeIsotopes(SEXP v_masses, SEXP v_abundances, SEXP s_error
342 342
 	  rl = rlistScores(scores, Rf_asInteger(z));
343 343
 	}
344 344
     } catch(std::exception& ex) {
345
-      exceptionMesg = copyMessageToR(ex.what());
346
-      error_return(exceptionMesg); 
345
+      //exceptionMesg = copyMessageToR(ex.what());
346
+      //error_return(exceptionMesg); 
347
+      forward_exception_to_r(ex);
347 348
     } catch(...) {
348
-      exceptionMesg = copyMessageToR("unknown reason");
349
-      error_return(exceptionMesg); 
349
+      //exceptionMesg = copyMessageToR("unknown reason");
350
+      //error_return(exceptionMesg); 
351
+      ::Rf_error("c++ exception (unknown reason)");
350 352
     }
351 353
         
352 354
     return rl;
... ...
@@ -367,8 +369,8 @@ RcppExport SEXP calculateScore(SEXP v_predictMasses, SEXP v_predictAbundances, S
367 369
 
368 370
 
369 371
 
370
-	RcppVector<double> masses = RcppVector<double>(v_predictMasses);
371
-	RcppVector<double> abundances = RcppVector<double>(v_predictAbundances);
372
+	NumericVector masses = NumericVector(v_predictMasses);
373
+	NumericVector abundances = NumericVector(v_predictAbundances);
372 374
 
373 375
 	// fills peaklist masses and abundances, 
374 376
 	// since we cannot use masses and abundances - instances of RcppVector object - directly
... ...
@@ -384,8 +386,8 @@ RcppExport SEXP calculateScore(SEXP v_predictMasses, SEXP v_predictAbundances, S
384 386
 	// initializes distribution probability scorer
385 387
 	scorer_type scorer(peaklist_masses, peaklist_abundances);
386 388
 
387
-	masses = RcppVector<double>(v_measuredMasses);
388
-	abundances = RcppVector<double>(v_meausuredAbundances);
389
+	masses = NumericVector(v_measuredMasses);
390
+	abundances = NumericVector(v_meausuredAbundances);
389 391
 	//cout << "Mess:" << masses<<"\n";
390 392
 	masses_container mess_masses;
391 393
 	abundances_container mess_abundances;
... ...
@@ -406,15 +408,8 @@ RcppExport SEXP calculateScore(SEXP v_predictMasses, SEXP v_predictAbundances, S
406 408
 	}
407 409
 
408 410
 	score_type score=scorer.score(mess_masses, mess_abundances);
409
-	//SEXP output;
410
-	//PROTECT(output = NEW_NUMERIC(1));
411
-	//cout<< score;
412
-	//REAL(output)[0]=score;
413
-	//UNPROTECT(1);
414
- 	//return (output);
415
-	RcppResultSet rs;
416
-	rs.add("", score);
417
-	return(rs.getSEXP());
411
+	//List output;
412
+	return(List::create(  _[""]  = score));
418 413
 }
419 414
 // }}}
420 415
 
... ...
@@ -477,11 +472,9 @@ RcppExport SEXP getMolecule(SEXP s_formula, SEXP l_alphabet,
477 472
     scores.insert(make_pair(1.0, molecule));
478 473
     rl = rlistScores(scores, Rf_asInteger(z));
479 474
   } catch(std::exception& ex) {
480
-    exceptionMesg = copyMessageToR(ex.what());
481
-    Rf_error(exceptionMesg); 
475
+    forward_exception_to_r(ex);
482 476
   } catch(...) {
483
-    exceptionMesg = copyMessageToR("unknown reason");
484
-    error_return(exceptionMesg); 
477
+    ::Rf_error("c++ exception (unknown reason)");
485 478
   }
486 479
 
487 480
   return rl;
... ...
@@ -625,18 +618,17 @@ SEXP  rlistScores(multimap<score_type, ComposedElement, greater<score_type> > sc
625 618
 
626 619
 	// Build result set to be returned as a list to R.
627 620
 	vector<string> formula(scores.size());
628
-	RcppVector<double> score(scores.size());
629
-	RcppVector<double> exactmass(scores.size());
630
-	RcppVector<int> charge(scores.size());
621
+	NumericVector score(scores.size());
622
+	NumericVector exactmass(scores.size());
623
+	IntegerVector charge(scores.size());
631 624
 
632 625
 	// Chemical rules
633 626
 	vector<string> parity(scores.size());
634 627
 	vector<string> valid(scores.size());
635
-	RcppVector<double> DBE(scores.size());
628
+	NumericVector DBE(scores.size());
636 629
 
637 630
 	SEXP isotopes = PROTECT(Rf_allocVector(VECSXP, scores.size()));
638 631
 
639
- 	RcppResultSet rs;
640 632
 	unsigned int i = 0;
641 633
 
642 634
 	vector<string> colNames(2);
... ...
@@ -676,26 +668,21 @@ SEXP  rlistScores(multimap<score_type, ComposedElement, greater<score_type> > sc
676 668
 		i++;
677 669
 	}
678 670
 
679
-	rs.add("formula", formula);
680
-	rs.add("score", score);
681
-	rs.add("exactmass", exactmass);
682
-	rs.add("charge", z);
683
-
684
-	rs.add("parity", parity);
685
-	rs.add("valid", valid);
686
-	rs.add("DBE", DBE);
687
-
688
-	rs.add("isotopes", isotopes, true);
689
-
690
-	// Get the list to be returned to R.
691
-	SEXP rl = rs.getReturnList();
692 671
 
693 672
 	UNPROTECT(1); // SEXP isotopes
694 673
 
695 674
 	if(exceptionMesg != NULL) {
696 675
 	  Rf_error(exceptionMesg);
697 676
 	}
698
-	return rl;
677
+	
678
+	return(List::create(  _["formula"]  = formula,
679
+                       _["score"]  = score,
680
+                       _["exactmass"]  = exactmass,
681
+                       _["charge"]  = charge,
682
+                       _["parity"]  = parity,
683
+                       _["valid"]  = valid,
684
+                       _["DBE"]  = DBE,
685
+                       _["isotopes"]  = isotopes));
699 686
 
700 687
 	// }}}
701 688
 }