Skip to content

Commit

Permalink
- fix merge mass axis error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
prafols committed Mar 7, 2019
1 parent 60f8d61 commit 0d1637f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Imports:
digest (>= 0.6.9),
Rcpp (>= 0.12.2)
LinkingTo: Rcpp
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
2 changes: 1 addition & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NULL
#' @param mz1 the first mass axis to merge.
#' @param mz2 the second mass axis to merge.
#'
#' @return a common mass axis that represents mz1 and mz1 accurately.
#' @return a list containing the common mass axis that represents mz1 and mz1 accurately and a boolean indicating if and error was raised.
#' @export
#'
MergeMassAxis <- function(mz1, mz2) {
Expand Down
4 changes: 2 additions & 2 deletions R/imzMLreader.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ import_imzML <- function(imzML_File, ibd_File = paste(sub("\\.[^.]*$", "", imzM

#Combine the two mass axis using Cpp method
resMZMerge <- MergeMassAxis(mzAxis, mzdd)
if(resMZMerge[1] == -1)
if(resMZMerge$error)
{
mzMergeErrorCount <- mzMergeErrorCount + 1
}
else
{
mzAxis <- resMZMerge
mzAxis <- resMZMerge$mass
}

#Update progress bar
Expand Down
2 changes: 1 addition & 1 deletion man/MergeMassAxis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BEGIN_RCPP
END_RCPP
}
// MergeMassAxis
NumericVector MergeMassAxis(NumericVector mz1, NumericVector mz2);
List MergeMassAxis(NumericVector mz1, NumericVector mz2);
RcppExport SEXP _rMSI_MergeMassAxis(SEXP mz1SEXP, SEXP mz2SEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Expand Down
12 changes: 7 additions & 5 deletions src/mergeTwoMassAxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ using namespace Rcpp;
//' @param mz1 the first mass axis to merge.
//' @param mz2 the second mass axis to merge.
//'
//' @return a common mass axis that represents mz1 and mz1 accurately.
//' @return a list containing the common mass axis that represents mz1 and mz1 accurately and a boolean indicating if and error was raised.
//' @export
//'
// [[Rcpp::export]]
NumericVector MergeMassAxis(NumericVector mz1, NumericVector mz2)
List MergeMassAxis(NumericVector mz1, NumericVector mz2)
{
int i1 = 0; //Iterator over mz1
int i2 = 0; //Iterator over mz2
Expand Down Expand Up @@ -103,15 +103,17 @@ NumericVector MergeMassAxis(NumericVector mz1, NumericVector mz2)
}

//if the new mass axis is empty then mz1 and mz2 are non-overlaping vectors, so an error is raised.
bool bError = false;
if( iN == 0)
{
delete[] mzNew;
return -1;
bError = true;
iN = 1;
mzNew[0] = -1; //Mark as error using -1 (not possible to have an m/z value of -1)
}

//Copy to a NumericVector
NumericVector resultMass(iN);
memcpy(resultMass.begin(), mzNew, sizeof(double)*iN);
delete[] mzNew;
return resultMass;
return List::create( Named("mass") = resultMass, Named("error") = bError );
}

0 comments on commit 0d1637f

Please sign in to comment.