... | ... |
@@ -133,7 +133,7 @@ setMethod("writeMSData", signature(object = "list", file = "character"), |
133 | 133 |
## Check software_processing: |
134 | 134 |
software_processing <- .check_software_processing(software_processing) |
135 | 135 |
## Add mzR processing: |
136 |
- mzR <- c("mzR", paste(packageVersion("mzR"), collapse = ".")) |
|
136 |
+ mzR <- c("mzR", paste(packageVersion("mzR"), collapse = "."), "MS:-1") |
|
137 | 137 |
if (outformat == "mzml") |
138 | 138 |
mzR <- c(mzR, "MS:1000544") |
139 | 139 |
if (outformat == "mzxml") |
... | ... |
@@ -114,7 +114,7 @@ |
114 | 114 |
\code{mergedResultStartScanNum}, \code{mergedResultEndScanNum}, |
115 | 115 |
\code{spectrumId}, \code{centroided} (\code{logical} whether the data |
116 | 116 |
of the spectrum is in centroid mode or profile mode; only for pwiz |
117 |
- backend) and \code{injectionTime} (ion injection time, in seconds) |
|
117 |
+ backend) and \code{injectionTime} (ion injection time, in milliseconds) |
|
118 | 118 |
when available in the original file. If multiple scans are queried, a |
119 | 119 |
\code{data.frame} is returned with the scans reported along the |
120 | 120 |
rows. |
... | ... |
@@ -2,12 +2,12 @@ |
2 | 2 |
|
3 | 3 |
RcppPwiz::RcppPwiz() |
4 | 4 |
{ |
5 |
- msd = NULL; |
|
6 |
- instrumentInfo = Rcpp::List::create(); |
|
7 |
- chromatogramsInfo = Rcpp::DataFrame::create(); |
|
8 |
- isInCacheInstrumentInfo = FALSE; |
|
9 |
- allScanHeaderInfo = Rcpp::List::create(); |
|
10 |
- isInCacheAllScanHeaderInfo = FALSE; |
|
5 |
+ msd = NULL; |
|
6 |
+ instrumentInfo = Rcpp::List::create(); |
|
7 |
+ chromatogramsInfo = Rcpp::DataFrame::create(); |
|
8 |
+ isInCacheInstrumentInfo = FALSE; |
|
9 |
+ allScanHeaderInfo = Rcpp::List::create(); |
|
10 |
+ isInCacheAllScanHeaderInfo = FALSE; |
|
11 | 11 |
} |
12 | 12 |
/* Destructor*/ |
13 | 13 |
RcppPwiz::~RcppPwiz() |
... | ... |
@@ -18,8 +18,8 @@ RcppPwiz::~RcppPwiz() |
18 | 18 |
void RcppPwiz::open(const string& fileName) |
19 | 19 |
{ |
20 | 20 |
|
21 |
- filename = fileName; |
|
22 |
- msd = new MSDataFile(fileName); |
|
21 |
+ filename = fileName; |
|
22 |
+ msd = new MSDataFile(fileName); |
|
23 | 23 |
|
24 | 24 |
} |
25 | 25 |
|
... | ... |
@@ -76,98 +76,98 @@ void RcppPwiz::close() |
76 | 76 |
|
77 | 77 |
|
78 | 78 |
string RcppPwiz::getFilename() { |
79 |
- return filename; |
|
79 |
+ return filename; |
|
80 | 80 |
} |
81 | 81 |
|
82 | 82 |
int RcppPwiz::getLastScan() const { |
83 |
- if (msd != NULL) { |
|
84 |
- SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
85 |
- return slp->size(); |
|
86 |
- } |
|
87 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
88 |
- return -1; |
|
83 |
+ if (msd != NULL) { |
|
84 |
+ SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
85 |
+ return slp->size(); |
|
86 |
+ } |
|
87 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
88 |
+ return -1; |
|
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
int RcppPwiz::getLastChrom() const { |
92 |
- if (msd != NULL) { |
|
93 |
- ChromatogramListPtr clp = msd->run.chromatogramListPtr; |
|
94 |
- return clp->size(); |
|
95 |
- } |
|
96 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
97 |
- return -1; |
|
92 |
+ if (msd != NULL) { |
|
93 |
+ ChromatogramListPtr clp = msd->run.chromatogramListPtr; |
|
94 |
+ return clp->size(); |
|
95 |
+ } |
|
96 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
97 |
+ return -1; |
|
98 | 98 |
} |
99 | 99 |
|
100 | 100 |
Rcpp::List RcppPwiz::getInstrumentInfo ( ) |
101 | 101 |
{ |
102 |
- if (msd != NULL) |
|
102 |
+ if (msd != NULL) |
|
103 | 103 |
{ |
104 |
- if (!isInCacheInstrumentInfo) |
|
104 |
+ if (!isInCacheInstrumentInfo) |
|
105 | 105 |
{ |
106 | 106 |
|
107 |
- vector<InstrumentConfigurationPtr> icp = msd->instrumentConfigurationPtrs; // NULL for mzData |
|
108 |
- if (icp.size() != 0) |
|
107 |
+ vector<InstrumentConfigurationPtr> icp = msd->instrumentConfigurationPtrs; // NULL for mzData |
|
108 |
+ if (icp.size() != 0) |
|
109 | 109 |
{ |
110 |
- CVTranslator cvTranslator; |
|
111 |
- LegacyAdapter_Instrument adapter(*icp[0], cvTranslator); |
|
112 |
- vector<SoftwarePtr> sp = msd->softwarePtrs; |
|
113 |
- std::vector<SamplePtr> sample = msd->samplePtrs; |
|
114 |
- std::vector<ScanSettingsPtr> scansetting = msd->scanSettingsPtrs; |
|
115 |
- std::string ionisation = ""; |
|
116 |
- std::string analyzer = ""; |
|
117 |
- std::string detector = ""; |
|
118 |
- // Fix issue #113 |
|
119 |
- // if (icp[0]->componentList.size() > 0) |
|
120 |
- // That does still not mean we have a ionisation available. |
|
121 |
- // Could be that either analyzer or detector or ionisation is |
|
122 |
- // defined. |
|
123 |
- // Have to use try-catch |
|
124 |
- try { |
|
125 |
- ionisation = std::string(adapter.ionisation()); |
|
126 |
- } catch(...) {} |
|
127 |
- try { |
|
128 |
- analyzer = std::string(adapter.analyzer()); |
|
129 |
- } catch(...) {} |
|
130 |
- try { |
|
131 |
- detector = std::string(adapter.detector()); |
|
132 |
- } catch(...) {} |
|
133 |
- instrumentInfo = Rcpp::List::create( |
|
134 |
- Rcpp::_["manufacturer"] = std::string(adapter.manufacturer()), |
|
135 |
- Rcpp::_["model"] = std::string(adapter.model()), |
|
136 |
- Rcpp::_["ionisation"] = ionisation, |
|
137 |
- Rcpp::_["analyzer"] = analyzer, |
|
138 |
- Rcpp::_["detector"] = detector, |
|
139 |
- Rcpp::_["software"] = (sp.size()>0?sp[0]->id + " " + sp[0]->version:""), |
|
140 |
- Rcpp::_["sample"] = (sample.size()>0?sample[0]->name+sample[0]->id:""), |
|
141 |
- Rcpp::_["source"] = (scansetting.size()>0?scansetting[0]->sourceFilePtrs[0]->location:"") |
|
142 |
- ) ; |
|
110 |
+ CVTranslator cvTranslator; |
|
111 |
+ LegacyAdapter_Instrument adapter(*icp[0], cvTranslator); |
|
112 |
+ vector<SoftwarePtr> sp = msd->softwarePtrs; |
|
113 |
+ std::vector<SamplePtr> sample = msd->samplePtrs; |
|
114 |
+ std::vector<ScanSettingsPtr> scansetting = msd->scanSettingsPtrs; |
|
115 |
+ std::string ionisation = ""; |
|
116 |
+ std::string analyzer = ""; |
|
117 |
+ std::string detector = ""; |
|
118 |
+ // Fix issue #113 |
|
119 |
+ // if (icp[0]->componentList.size() > 0) |
|
120 |
+ // That does still not mean we have a ionisation available. |
|
121 |
+ // Could be that either analyzer or detector or ionisation is |
|
122 |
+ // defined. |
|
123 |
+ // Have to use try-catch |
|
124 |
+ try { |
|
125 |
+ ionisation = std::string(adapter.ionisation()); |
|
126 |
+ } catch(...) {} |
|
127 |
+ try { |
|
128 |
+ analyzer = std::string(adapter.analyzer()); |
|
129 |
+ } catch(...) {} |
|
130 |
+ try { |
|
131 |
+ detector = std::string(adapter.detector()); |
|
132 |
+ } catch(...) {} |
|
133 |
+ instrumentInfo = Rcpp::List::create( |
|
134 |
+ Rcpp::_["manufacturer"] = std::string(adapter.manufacturer()), |
|
135 |
+ Rcpp::_["model"] = std::string(adapter.model()), |
|
136 |
+ Rcpp::_["ionisation"] = ionisation, |
|
137 |
+ Rcpp::_["analyzer"] = analyzer, |
|
138 |
+ Rcpp::_["detector"] = detector, |
|
139 |
+ Rcpp::_["software"] = (sp.size()>0?sp[0]->id + " " + sp[0]->version:""), |
|
140 |
+ Rcpp::_["sample"] = (sample.size()>0?sample[0]->name+sample[0]->id:""), |
|
141 |
+ Rcpp::_["source"] = (scansetting.size()>0?scansetting[0]->sourceFilePtrs[0]->location:"") |
|
142 |
+ ) ; |
|
143 | 143 |
|
144 | 144 |
} |
145 |
- else |
|
145 |
+ else |
|
146 | 146 |
{ |
147 |
- instrumentInfo = Rcpp::List::create( |
|
148 |
- Rcpp::_["manufacturer"] = "", |
|
149 |
- Rcpp::_["model"] = "", |
|
150 |
- Rcpp::_["ionisation"] = "", |
|
151 |
- Rcpp::_["analyzer"] = "", |
|
152 |
- Rcpp::_["detector"] = "", |
|
153 |
- Rcpp::_["software"] = "", |
|
154 |
- Rcpp::_["sample"] = "", |
|
155 |
- Rcpp::_["source"] = "" |
|
156 |
- ) ; |
|
147 |
+ instrumentInfo = Rcpp::List::create( |
|
148 |
+ Rcpp::_["manufacturer"] = "", |
|
149 |
+ Rcpp::_["model"] = "", |
|
150 |
+ Rcpp::_["ionisation"] = "", |
|
151 |
+ Rcpp::_["analyzer"] = "", |
|
152 |
+ Rcpp::_["detector"] = "", |
|
153 |
+ Rcpp::_["software"] = "", |
|
154 |
+ Rcpp::_["sample"] = "", |
|
155 |
+ Rcpp::_["source"] = "" |
|
156 |
+ ) ; |
|
157 | 157 |
} |
158 | 158 |
|
159 |
- isInCacheInstrumentInfo = TRUE; |
|
159 |
+ isInCacheInstrumentInfo = TRUE; |
|
160 | 160 |
} |
161 |
- return(instrumentInfo); |
|
161 |
+ return(instrumentInfo); |
|
162 | 162 |
} |
163 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
164 |
- return instrumentInfo; |
|
163 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
164 |
+ return instrumentInfo; |
|
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
|
168 | 168 |
Rcpp::DataFrame RcppPwiz::getScanHeaderInfo (Rcpp::IntegerVector whichScan) |
169 | 169 |
{ |
170 |
- if (msd != NULL) |
|
170 |
+ if (msd != NULL) |
|
171 | 171 |
{ |
172 | 172 |
SpectrumListPtr slp = msd->run.spectrumListPtr; |
173 | 173 |
int N = slp->size(); |
... | ... |
@@ -220,8 +220,7 @@ Rcpp::DataFrame RcppPwiz::getScanHeaderInfo (Rcpp::IntegerVector whichScan) |
220 | 220 |
Scan& scan = sp->scanList.scans.empty() ? dummy : sp->scanList.scans[0]; |
221 | 221 |
CVParam param = sp->cvParamChild(MS_scan_polarity); |
222 | 222 |
polarity[i] = (param.cvid==MS_negative_scan ? 0 : (param.cvid==MS_positive_scan ? +1 : -1 ) ); |
223 |
- // ionInjectionTime[i] = sp->cvParam(MS_ion_injection_time).valueAs<double>(); |
|
224 |
- ionInjectionTime[i] = scan.cvParam(MS_ion_injection_time).timeInSeconds(); |
|
223 |
+ ionInjectionTime[i] = scan.cvParam(MS_ion_injection_time).valueAs<double>(); |
|
225 | 224 |
filterString[i] = scan.cvParam(MS_filter_string).value.empty() ? NA_STRING : Rcpp::String(scan.cvParam(MS_filter_string).value); |
226 | 225 |
|
227 | 226 |
peaksCount[i] = scanHeader.peaksCount; |
... | ... |
@@ -307,64 +306,64 @@ Rcpp::DataFrame RcppPwiz::getScanHeaderInfo (Rcpp::IntegerVector whichScan) |
307 | 306 |
|
308 | 307 |
return header; |
309 | 308 |
} |
310 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
311 |
- return Rcpp::DataFrame::create( ); |
|
309 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
310 |
+ return Rcpp::DataFrame::create( ); |
|
312 | 311 |
} |
313 | 312 |
|
314 | 313 |
Rcpp::DataFrame RcppPwiz::getAllScanHeaderInfo ( ) |
315 | 314 |
{ |
316 |
- if (msd != NULL) |
|
315 |
+ if (msd != NULL) |
|
317 | 316 |
{ |
318 |
- if (!isInCacheAllScanHeaderInfo) |
|
317 |
+ if (!isInCacheAllScanHeaderInfo) |
|
319 | 318 |
{ |
320 |
- SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
321 |
- int N = slp->size(); |
|
319 |
+ SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
320 |
+ int N = slp->size(); |
|
322 | 321 |
|
323 |
- allScanHeaderInfo = getScanHeaderInfo(Rcpp::seq(1, N)); |
|
324 |
- isInCacheAllScanHeaderInfo = TRUE; |
|
322 |
+ allScanHeaderInfo = getScanHeaderInfo(Rcpp::seq(1, N)); |
|
323 |
+ isInCacheAllScanHeaderInfo = TRUE; |
|
325 | 324 |
} |
326 |
- return allScanHeaderInfo ; |
|
325 |
+ return allScanHeaderInfo ; |
|
327 | 326 |
} |
328 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
329 |
- return Rcpp::DataFrame::create( ); |
|
327 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
328 |
+ return Rcpp::DataFrame::create( ); |
|
330 | 329 |
} |
331 | 330 |
|
332 | 331 |
Rcpp::List RcppPwiz::getPeakList ( int whichScan ) |
333 | 332 |
{ |
334 |
- if (msd != NULL) |
|
333 |
+ if (msd != NULL) |
|
335 | 334 |
{ |
336 |
- SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
335 |
+ SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
337 | 336 |
|
338 |
- if ((whichScan <= 0) || (whichScan > slp->size())) |
|
337 |
+ if ((whichScan <= 0) || (whichScan > slp->size())) |
|
339 | 338 |
{ |
340 |
- Rprintf("Index whichScan out of bounds [1 ... %d].\n", slp->size()); |
|
341 |
- return Rcpp::List::create( ); |
|
339 |
+ Rprintf("Index whichScan out of bounds [1 ... %d].\n", slp->size()); |
|
340 |
+ return Rcpp::List::create( ); |
|
342 | 341 |
} |
343 | 342 |
|
344 |
- SpectrumPtr s = slp->spectrum(whichScan - 1, true); |
|
345 |
- vector<MZIntensityPair> pairs; |
|
346 |
- s->getMZIntensityPairs(pairs); |
|
343 |
+ SpectrumPtr s = slp->spectrum(whichScan - 1, true); |
|
344 |
+ vector<MZIntensityPair> pairs; |
|
345 |
+ s->getMZIntensityPairs(pairs); |
|
347 | 346 |
|
348 |
- Rcpp::NumericMatrix peaks(pairs.size(), 2); |
|
347 |
+ Rcpp::NumericMatrix peaks(pairs.size(), 2); |
|
349 | 348 |
|
350 |
- if(pairs.size()!=0) |
|
349 |
+ if(pairs.size()!=0) |
|
351 | 350 |
{ |
352 |
- for (int i = 0; i < pairs.size(); i++) |
|
351 |
+ for (int i = 0; i < pairs.size(); i++) |
|
353 | 352 |
{ |
354 |
- MZIntensityPair p = pairs.at(i); |
|
355 |
- peaks(i,0) = p.mz; |
|
356 |
- peaks(i,1) = p.intensity; |
|
353 |
+ MZIntensityPair p = pairs.at(i); |
|
354 |
+ peaks(i,0) = p.mz; |
|
355 |
+ peaks(i,1) = p.intensity; |
|
357 | 356 |
} |
358 | 357 |
|
359 | 358 |
} |
360 | 359 |
|
361 |
- return Rcpp::List::create( |
|
362 |
- Rcpp::_["peaksCount"] = pairs.size(), |
|
363 |
- Rcpp::_["peaks"] = peaks |
|
364 |
- ) ; |
|
360 |
+ return Rcpp::List::create( |
|
361 |
+ Rcpp::_["peaksCount"] = pairs.size(), |
|
362 |
+ Rcpp::_["peaks"] = peaks |
|
363 |
+ ) ; |
|
365 | 364 |
} |
366 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
367 |
- return Rcpp::List::create( ); |
|
365 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
366 |
+ return Rcpp::List::create( ); |
|
368 | 367 |
} |
369 | 368 |
|
370 | 369 |
/** |
... | ... |
@@ -651,6 +650,11 @@ void RcppPwiz::addSpectrumList(MSData& msd, |
651 | 650 |
spectrumList->spectra.push_back(SpectrumPtr(new Spectrum)); |
652 | 651 |
Spectrum& spct = *spectrumList->spectra[i]; |
653 | 652 |
spct.set(MS_ms_level, msLevel[i]); |
653 |
+ // centroided |
|
654 |
+ if (centroided[i] != NA_LOGICAL && centroided[i] == TRUE) |
|
655 |
+ spct.set(MS_centroid_spectrum); |
|
656 |
+ if (centroided[i] != NA_LOGICAL && centroided[i] == FALSE) |
|
657 |
+ spct.set(MS_profile_spectrum); |
|
654 | 658 |
// [X] polarity |
655 | 659 |
if (polarity[i] == 0) |
656 | 660 |
spct.set(MS_negative_scan); |
... | ... |
@@ -660,16 +664,12 @@ void RcppPwiz::addSpectrumList(MSData& msd, |
660 | 664 |
spct.set(MS_MS1_spectrum); |
661 | 665 |
else |
662 | 666 |
spct.set(MS_MSn_spectrum); |
663 |
- spct.set(MS_lowest_observed_m_z, lowMZ[i]); |
|
664 |
- spct.set(MS_highest_observed_m_z, highMZ[i]); |
|
665 |
- spct.set(MS_base_peak_m_z, basePeakMZ[i]); |
|
666 |
- spct.set(MS_base_peak_intensity, basePeakIntensity[i]); |
|
667 |
+ spct.set(MS_lowest_observed_m_z, lowMZ[i], MS_m_z); |
|
668 |
+ spct.set(MS_highest_observed_m_z, highMZ[i], MS_m_z); |
|
669 |
+ spct.set(MS_base_peak_m_z, basePeakMZ[i], MS_m_z); |
|
670 |
+ spct.set(MS_base_peak_intensity, basePeakIntensity[i], |
|
671 |
+ MS_number_of_detector_counts); |
|
667 | 672 |
spct.set(MS_total_ion_current, totIonCurrent[i]); |
668 |
- // centroided |
|
669 |
- if (centroided[i] != NA_LOGICAL && centroided[i] == TRUE) |
|
670 |
- spct.set(MS_centroid_spectrum); |
|
671 |
- if (centroided[i] != NA_LOGICAL && centroided[i] == FALSE) |
|
672 |
- spct.set(MS_profile_spectrum); |
|
673 | 673 |
// TODO: |
674 | 674 |
// [X] seqNum: number observed in file. |
675 | 675 |
spct.index = seqNum[i] - 1; // Or just i? |
... | ... |
@@ -681,15 +681,12 @@ void RcppPwiz::addSpectrumList(MSData& msd, |
681 | 681 |
spct.scanList.scans.push_back(Scan()); |
682 | 682 |
spct.scanList.set(MS_no_combination); |
683 | 683 |
Scan &spct_scan = spct.scanList.scans.back(); |
684 |
- if (rtime_seconds) { |
|
684 |
+ if (rtime_seconds) |
|
685 | 685 |
spct_scan.set(MS_scan_start_time, retentionTime[i], UO_second); |
686 |
- if (ionInjectionTime[i] > 0) |
|
687 |
- spct_scan.set(MS_ion_injection_time, ionInjectionTime[i], UO_second); |
|
688 |
- } else { |
|
686 |
+ else |
|
689 | 687 |
spct_scan.set(MS_scan_start_time, retentionTime[i], UO_minute); |
690 |
- if (ionInjectionTime[i] > 0) |
|
691 |
- spct_scan.set(MS_ion_injection_time, ionInjectionTime[i], UO_minute); |
|
692 |
- } |
|
688 |
+ if (ionInjectionTime[i] > 0) |
|
689 |
+ spct_scan.set(MS_ion_injection_time, ionInjectionTime[i], UO_millisecond); |
|
693 | 690 |
|
694 | 691 |
if (!Rcpp::StringVector::is_na(filterString[i])) |
695 | 692 |
spct_scan.set(MS_filter_string, filterString[i]); |
... | ... |
@@ -756,38 +753,38 @@ void RcppPwiz::addSpectrumList(MSData& msd, |
756 | 753 |
|
757 | 754 |
Rcpp::DataFrame RcppPwiz::getChromatogramsInfo( int whichChrom ) |
758 | 755 |
{ |
759 |
- if (msd != NULL) { |
|
760 |
- ChromatogramListPtr clp = msd->run.chromatogramListPtr; |
|
761 |
- if (clp.get() == 0) { |
|
762 |
- Rcpp::Rcerr << "The direct support for chromatogram info is only available in mzML format." << std::endl; |
|
763 |
- return Rcpp::DataFrame::create(); |
|
764 |
- } else if (clp->size() == 0) { |
|
765 |
- Rcpp::Rcerr << "No available chromatogram info." << std::endl; |
|
766 |
- return Rcpp::DataFrame::create(); |
|
767 |
- } else if ( (whichChrom < 0) || (whichChrom > clp->size()) ) { |
|
768 |
- Rprintf("Index whichChrom out of bounds [0 ... %d].\n", (clp->size())-1); |
|
769 |
- return Rcpp::DataFrame::create( ); |
|
770 |
- } else { |
|
771 |
- std::vector<double> time; |
|
772 |
- std::vector<double> intensity; |
|
773 |
- ChromatogramPtr c = clp->chromatogram(whichChrom, true); |
|
774 |
- vector<TimeIntensityPair> pairs; |
|
775 |
- c->getTimeIntensityPairs (pairs); |
|
776 |
- |
|
777 |
- for (int i = 0; i < pairs.size(); i++) { |
|
778 |
- TimeIntensityPair p = pairs.at(i); |
|
779 |
- time.push_back(p.time); |
|
780 |
- intensity.push_back(p.intensity); |
|
781 |
- } |
|
756 |
+ if (msd != NULL) { |
|
757 |
+ ChromatogramListPtr clp = msd->run.chromatogramListPtr; |
|
758 |
+ if (clp.get() == 0) { |
|
759 |
+ Rcpp::Rcerr << "The direct support for chromatogram info is only available in mzML format." << std::endl; |
|
760 |
+ return Rcpp::DataFrame::create(); |
|
761 |
+ } else if (clp->size() == 0) { |
|
762 |
+ Rcpp::Rcerr << "No available chromatogram info." << std::endl; |
|
763 |
+ return Rcpp::DataFrame::create(); |
|
764 |
+ } else if ( (whichChrom < 0) || (whichChrom > clp->size()) ) { |
|
765 |
+ Rprintf("Index whichChrom out of bounds [0 ... %d].\n", (clp->size())-1); |
|
766 |
+ return Rcpp::DataFrame::create( ); |
|
767 |
+ } else { |
|
768 |
+ std::vector<double> time; |
|
769 |
+ std::vector<double> intensity; |
|
770 |
+ ChromatogramPtr c = clp->chromatogram(whichChrom, true); |
|
771 |
+ vector<TimeIntensityPair> pairs; |
|
772 |
+ c->getTimeIntensityPairs (pairs); |
|
773 |
+ |
|
774 |
+ for (int i = 0; i < pairs.size(); i++) { |
|
775 |
+ TimeIntensityPair p = pairs.at(i); |
|
776 |
+ time.push_back(p.time); |
|
777 |
+ intensity.push_back(p.intensity); |
|
778 |
+ } |
|
782 | 779 |
|
783 |
- chromatogramsInfo = Rcpp::DataFrame::create(Rcpp::_["time"] = time, |
|
784 |
- Rcpp::_[c->id] = intensity); |
|
780 |
+ chromatogramsInfo = Rcpp::DataFrame::create(Rcpp::_["time"] = time, |
|
781 |
+ Rcpp::_[c->id] = intensity); |
|
785 | 782 |
|
786 |
- } |
|
787 |
- return(chromatogramsInfo); |
|
788 | 783 |
} |
789 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
790 |
- return Rcpp::DataFrame::create( ); |
|
784 |
+ return(chromatogramsInfo); |
|
785 |
+ } |
|
786 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
787 |
+ return Rcpp::DataFrame::create( ); |
|
791 | 788 |
} |
792 | 789 |
|
793 | 790 |
// get the header info for chromatograms. |
... | ... |
@@ -897,53 +894,53 @@ Rcpp::DataFrame RcppPwiz::getAllChromatogramHeaderInfo ( ) { |
897 | 894 |
|
898 | 895 |
Rcpp::NumericMatrix RcppPwiz::get3DMap ( std::vector<int> scanNumbers, double whichMzLow, double whichMzHigh, double resMz ) |
899 | 896 |
{ |
900 |
- if (msd != NULL) |
|
897 |
+ if (msd != NULL) |
|
901 | 898 |
{ |
902 | 899 |
|
903 |
- SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
904 |
- double f = 1 / resMz; |
|
905 |
- int low = round(whichMzLow * f); |
|
906 |
- int high = round(whichMzHigh * f); |
|
907 |
- int dmz = high - low + 1; |
|
908 |
- int drt = scanNumbers.size(); |
|
900 |
+ SpectrumListPtr slp = msd->run.spectrumListPtr; |
|
901 |
+ double f = 1 / resMz; |
|
902 |
+ int low = round(whichMzLow * f); |
|
903 |
+ int high = round(whichMzHigh * f); |
|
904 |
+ int dmz = high - low + 1; |
|
905 |
+ int drt = scanNumbers.size(); |
|
909 | 906 |
|
910 |
- Rcpp::NumericMatrix map3d(drt, dmz); |
|
907 |
+ Rcpp::NumericMatrix map3d(drt, dmz); |
|
911 | 908 |
|
912 |
- for (int i = 0; i < drt; i++) |
|
909 |
+ for (int i = 0; i < drt; i++) |
|
913 | 910 |
{ |
914 |
- for (int j = 0; j < dmz; j++) |
|
911 |
+ for (int j = 0; j < dmz; j++) |
|
915 | 912 |
{ |
916 |
- map3d(i,j) = 0.0; |
|
913 |
+ map3d(i,j) = 0.0; |
|
917 | 914 |
} |
918 | 915 |
} |
919 | 916 |
|
920 |
- int j=0; |
|
921 |
- Rprintf("%d\n",1); |
|
922 |
- for (int i = 0; i < scanNumbers.size(); i++) |
|
917 |
+ int j=0; |
|
918 |
+ Rprintf("%d\n",1); |
|
919 |
+ for (int i = 0; i < scanNumbers.size(); i++) |
|
923 | 920 |
{ |
924 |
- SpectrumPtr s = slp->spectrum(scanNumbers[i] - 1, true); |
|
925 |
- vector<MZIntensityPair> pairs; |
|
926 |
- s->getMZIntensityPairs(pairs); |
|
921 |
+ SpectrumPtr s = slp->spectrum(scanNumbers[i] - 1, true); |
|
922 |
+ vector<MZIntensityPair> pairs; |
|
923 |
+ s->getMZIntensityPairs(pairs); |
|
927 | 924 |
|
928 |
- for (int k=0; k < pairs.size(); k++) |
|
925 |
+ for (int k=0; k < pairs.size(); k++) |
|
929 | 926 |
{ |
930 |
- MZIntensityPair p = pairs.at(k); |
|
931 |
- j = round(p.mz * f) - low; |
|
932 |
- if ((j >= 0) & (j < dmz)) |
|
927 |
+ MZIntensityPair p = pairs.at(k); |
|
928 |
+ j = round(p.mz * f) - low; |
|
929 |
+ if ((j >= 0) & (j < dmz)) |
|
933 | 930 |
{ |
934 |
- if (p.intensity > map3d(i,j)) |
|
931 |
+ if (p.intensity > map3d(i,j)) |
|
935 | 932 |
{ |
936 |
- map3d(i,j) = p.intensity; |
|
933 |
+ map3d(i,j) = p.intensity; |
|
937 | 934 |
} |
938 | 935 |
} |
939 | 936 |
} |
940 | 937 |
|
941 | 938 |
} |
942 |
- return(map3d); |
|
939 |
+ return(map3d); |
|
943 | 940 |
} |
944 | 941 |
|
945 |
- Rprintf("Warning: pwiz not yet initialized.\n "); |
|
946 |
- return Rcpp::NumericMatrix(0,0); |
|
942 |
+ Rprintf("Warning: pwiz not yet initialized.\n "); |
|
943 |
+ return Rcpp::NumericMatrix(0,0); |
|
947 | 944 |
} |
948 | 945 |
|
949 | 946 |
string RcppPwiz::getRunStartTimeStamp() { |