Browse code

Use pwiz to extract acquisitionNum from scanId

jorainer authored on 27/10/2021 05:52:05
Showing1 changed files

... ...
@@ -22,9 +22,7 @@ void RcppPwiz::open(Rcpp::StringVector fileName)
22 22
 
23 23
   filename = Rcpp::as<std::string>(fileName(0));
24 24
   msd = new MSDataFile(filename);
25
-  // Better not to guess the native ID format. For mzML/mzXML all should be fine
26
-  // with the default one.
27
-  // nativeIdFormat = id::getDefaultNativeIDFormat(*msd);
25
+  nativeIdFormat = id::getDefaultNativeIDFormat(*msd);
28 26
 }
29 27
 
30 28
 /* Release all memory on close. */
... ...
@@ -132,42 +130,40 @@ Rcpp::List RcppPwiz::getInstrumentInfo ( )
132 130
   return instrumentInfo;
133 131
 }
134 132
 
135
-// int RcppPwiz::getAcquisitionNumber(size_t index) const
136
-// {
137
-//   const SpectrumIdentity& si = msd->run.spectrumListPtr->spectrumIdentity(index);
138
-//   string scanNumber = id::translateNativeIDToScanNumber(nativeIdFormat, si.id);
139
-//   if (scanNumber.empty()) {
140
-//     return static_cast<int>(index) + 1;
141
-//   }
142
-//   else
143
-//     return lexical_cast<int>(scanNumber);
144
-//   // return static_cast<int>(index) + 1;
145
-// }
146
-
147
-// Using this function instead of pwiz translateNativeIDToScanNumber because
148
-// it randomly causes segfaults on macOS.
149 133
 int RcppPwiz::getAcquisitionNumber(string id, size_t index) const
150 134
 {
151
-  if (id.find("controllerType") != std::string::npos) {
152
-    if (id.find("controllerType=0 controllerNumber=1") == std::string::npos)
153
-      return static_cast<int>(index) + 1;
154
-  }
155
-  string e;
156
-  std::smatch match;
157
-  if (id.find("scan=") != std::string::npos)
158
-    e ="scan=(\\d+)";
159
-  else if (id.find("index=") != std::string::npos)
160
-    e = "index=(\\d+)";
161
-  else if (id.find("spectrum=") != std::string::npos)
162
-    e = "spectrum=(\\d+)";
163
-  else if (id.find("scanId=") != std::string::npos)
164
-    e = "scanId=(\\d+)";
165
-  else return static_cast<int>(index) + 1;
166
-  if (std::regex_search(id, match, std::regex(e)))
167
-    return lexical_cast<int>(match[1]);
168
-  else return static_cast<int>(index) + 1;
135
+  // const SpectrumIdentity& si = msd->run.spectrumListPtr->spectrumIdentity(index);
136
+  string scanNumber = id::translateNativeIDToScanNumber(nativeIdFormat, id);
137
+  if (scanNumber.empty())
138
+    return static_cast<int>(index) + 1;
139
+  else
140
+    return lexical_cast<int>(scanNumber);
169 141
 }
170 142
 
143
+// Using this function instead of pwiz translateNativeIDToScanNumber because
144
+// it randomly causes segfaults on macOS.
145
+// int RcppPwiz::getAcquisitionNumber(string id, size_t index) const
146
+// {
147
+//   if (id.find("controllerType") != std::string::npos) {
148
+//     if (id.find("controllerType=0 controllerNumber=1") == std::string::npos)
149
+//       return static_cast<int>(index) + 1;
150
+//   }
151
+//   string e;
152
+//   std::smatch match;
153
+//   if (id.find("scan=") != std::string::npos)
154
+//     e ="scan=(\\d+)";
155
+//   else if (id.find("index=") != std::string::npos)
156
+//     e = "index=(\\d+)";
157
+//   else if (id.find("spectrum=") != std::string::npos)
158
+//     e = "spectrum=(\\d+)";
159
+//   else if (id.find("scanId=") != std::string::npos)
160
+//     e = "scanId=(\\d+)";
161
+//   else return static_cast<int>(index) + 1;
162
+//   if (std::regex_search(id, match, std::regex(e)))
163
+//     return lexical_cast<int>(match[1]);
164
+//   else return static_cast<int>(index) + 1;
165
+// }
166
+
171 167
 Rcpp::DataFrame RcppPwiz::getScanHeaderInfo (Rcpp::IntegerVector whichScan) {
172 168
   if (msd != NULL) {
173 169
     SpectrumListPtr slp = msd->run.spectrumListPtr;