Skip to content

Commit

Permalink
Merge pull request #265 from jorainer/master
Browse files Browse the repository at this point in the history
feat: pwiz returns peak matrices with column names
  • Loading branch information
sneumann committed Mar 20, 2022
2 parents 68e1720 + 0e6e520 commit 88b1c19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: mzR
Type: Package
Title: parser for netCDF, mzXML, mzData and mzML and mzIdentML files
(mass spectrometry data)
Version: 2.29.4
Version: 2.29.5
Author: Bernd Fischer, Steffen Neumann, Laurent Gatto, Qiang Kou, Johannes Rainer
Authors@R: c(
person("Steffen", "Neumann", email="sneumann@ipb-halle.de", role=c("aut","cre")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
CHANGES IN VERSION 2.27.5
-------------------------
o `peaks` method for pwiz backend sets colnames on returned matrices.

CHANGES IN VERSION 2.29.4
-------------------------
o Re-apply fix for compile error on clang by Kurt Hornik, closes #263
Expand Down
2 changes: 2 additions & 0 deletions inst/unitTests/test_pwiz.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test_mzXML <- function() {
checkTrue(is.matrix(peaks(mzxml,1)))
pks <- peaks(mzxml, 2:3)
checkTrue(length(pks) == 2)
checkEquals(colnames(pks[[1L]]), c("mz", "intensity"))
peaksCount(mzxml)
hdr <- header(mzxml)
checkTrue(any(colnames(hdr) == "spectrumId"))
Expand Down Expand Up @@ -39,6 +40,7 @@ test_mzML <- function() {
pks <- peaks(mzml)
pks <- peaks(mzml,1)
pks <- peaks(mzml,2:3)
checkEquals(colnames(pks[[1L]]), c("mz", "intensity"))
peaksCount(mzml)
hdr <- header(mzml)
checkTrue(any(colnames(hdr) == "spectrumId"))
Expand Down
3 changes: 3 additions & 0 deletions src/RcppPwiz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ Rcpp::List RcppPwiz::getPeakList(Rcpp::IntegerVector whichScan) {
std::vector<double> data;
Rcpp::NumericVector data_matrix;
Rcpp::List res(n_want);
Rcpp::CharacterVector cn = Rcpp::CharacterVector::create("mz", "intensity");
for (size_t i = 0; i < n_want; i++) {
current_scan = whichScan[i];
if (current_scan < 1 || current_scan > n_scans) {
Expand All @@ -414,6 +415,7 @@ Rcpp::List RcppPwiz::getPeakList(Rcpp::IntegerVector whichScan) {
ints = sp->getIntensityArray();
if (!mzs.get() || !ints.get()) {
Rcpp::NumericMatrix pks(0, 2);
Rcpp::colnames(pks) = cn;
res[i] = pks;
continue;
}
Expand All @@ -423,6 +425,7 @@ Rcpp::List RcppPwiz::getPeakList(Rcpp::IntegerVector whichScan) {
data.insert(data.end(), ints->data.begin(), ints->data.end());
data_matrix = Rcpp::wrap(data);
data_matrix.attr("dim") = Rcpp::Dimension(ints->data.size(), 2);
Rcpp::colnames(data_matrix) = cn;
res[i] = data_matrix;
}
return res;
Expand Down

0 comments on commit 88b1c19

Please sign in to comment.