libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::PwizMsRunReader Class Reference

#include <pwizmsrunreader.h>

Inheritance diagram for pappso::PwizMsRunReader:
pappso::MsRunReader

Public Member Functions

 PwizMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
 
virtual ~PwizMsRunReader ()
 
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index) override
 get a MassSpectrumSPtr class given its spectrum index
 
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index) override
 
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const override
 get a QualifiedMassSpectrum class given its scan number
 
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
 
virtual void readSpectrumCollection2 (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index
 
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum
 
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
 
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file
 
virtual bool hasScanNumbers () const override
 tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file
 
virtual bool releaseDevice () override
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object
 
virtual bool acquireDevice () override
 acquire data back end device
 
const OboPsiModTerm getOboPsiModTermNativeIDFormat () const
 get OboPsiModTerm corresponding to the nativeID format format of mz data
 
virtual std::size_t spectrumStringIdentifier2SpectrumIndex (const QString &spectrum_identifier) override
 if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found
 
- Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (const MsRunIdCstSPtr &ms_run_id)
 
 MsRunReader (const MsRunReader &other)
 
virtual ~MsRunReader ()
 
const MsRunIdCstSPtrgetMsRunId () const
 
virtual std::size_t scanNumber2SpectrumIndex (std::size_t scan_number)
 if possible, converts a scan number into a spectrum index This is a convenient function to help transition from the old scan number (not implemented by all vendors) to more secure spectrum index (not vendor dependant). It is better to not rely on this function.
 
virtual std::vector< double > getRetentionTimeLine ()
 retention timeline get retention times along the MSrun in seconds
 
virtual Trace getTicChromatogram ()
 get a TIC chromatogram
 
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true
 
bool isMonoThread () const
 

Protected Member Functions

virtual void readSpectrumCollectionWithMsrunReadConfig (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)
 
virtual void initialize () override
 
virtual bool accept (const QString &file_name) const override
 tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format
 
bool processRetentionTime (pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
 
bool processDriftTime (pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
 
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData (std::size_t spectrum_index, bool want_binary_data, bool &ok) const
 
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr (const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
 
pwiz::msdata::SpectrumPtr getPwizSpectrumPtr (pwiz::msdata::SpectrumList *p_spectrum_list, std::size_t spectrum_index, bool want_binary_data) const
 
virtual const OboPsiModTerm getOboPsiModTermInstrumentModelName () const override
 get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: instrument model def: "Instrument model name not including the vendor's name." [PSI:MS] relationship: part_of MS:1000463 ! instrument
 

Static Protected Member Functions

static std::string setGlobalLocaleToEnglish ()
 
static void setGlobalLocaleToCurrentOs (const std::string &environment_locale)
 

Protected Attributes

pwiz::msdata::MSDataPtr msp_msData = nullptr
 
- Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
 
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr
 

Static Protected Attributes

static QMutex m_mutex
 

Private Attributes

bool m_hasScanNumbers = false
 

Friends

class MsFileAccessor
 

Detailed Description

Definition at line 45 of file pwizmsrunreader.h.

Constructor & Destructor Documentation

◆ PwizMsRunReader()

pappso::PwizMsRunReader::PwizMsRunReader ( MsRunIdCstSPtr & msrun_id_csp)

Definition at line 56 of file pwizmsrunreader.cpp.

56 : MsRunReader(msrun_id_csp)
57{
58 // The initialization needs to be done immediately so that we get the pwiz
59 // MsDataPtr corresponding to the right ms_run_id in the parameter. That
60 // pointer will be set to msp_msData.
61
62 initialize();
63}
virtual void initialize() override
class PMSPP_LIB_DECL MsRunReader
Definition msrunreader.h:56

References pappso::MsRunReader::MsRunReader(), and initialize().

Referenced by MsFileAccessor.

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 166 of file pwizmsrunreader.cpp.

167{
168}

Member Function Documentation

◆ accept()

bool pappso::PwizMsRunReader::accept ( const QString & file_name) const
overrideprotectedvirtual

tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format

Implements pappso::MsRunReader.

Definition at line 729 of file pwizmsrunreader.cpp.

730{
731 // We want to know if we can handle the file_name.
732 pwiz::msdata::ReaderList reader_list;
733
734 std::string reader_type = reader_list.identify(file_name.toStdString());
735
736 if(!reader_type.empty())
737 return true;
738
739 return false;
740}

Referenced by MsFileAccessor.

◆ acquireDevice()

bool pappso::PwizMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 1106 of file pwizmsrunreader.cpp.

1107{
1108 if(msp_msData == nullptr)
1109 {
1110 initialize();
1111 }
1112 return true;
1113}
pwiz::msdata::MSDataPtr msp_msData

References initialize(), and msp_msData.

Referenced by MsFileAccessor, readSpectrumCollectionByMsLevel(), readSpectrumCollectionWithMsrunReadConfig(), and spectrumStringIdentifier2SpectrumIndex().

◆ getOboPsiModTermInstrumentModelName()

const pappso::OboPsiModTerm pappso::PwizMsRunReader::getOboPsiModTermInstrumentModelName ( ) const
overrideprotectedvirtual

get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: instrument model def: "Instrument model name not including the vendor's name." [PSI:MS] relationship: part_of MS:1000463 ! instrument

Velos Plus: Thermo Scientific second generation Velos.

LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred to as the Orbitrap Elite.

Orbitrap Fusion: Thermo Scientific Orbitrap Fusion.

LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred to as the Orbitrap Elite.

Q Exactive HF: Thermo Scientific Q Exactive.

LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred to as the Orbitrap Elite.

Exactive Plus: Thermo Scientific Exactive Plus MS.

Q Exactive Plus: Thermo Scientific Q Exactive Plus.

Orbitrap Fusion Lumos: Thermo Scientific Orbitrap Fusion Lumos mass spectrometer with Tribrid architecture consisting of quadrupole mass filter, linear ion trap and Orbitrap mass analyzers.

Q Exactive HF-X: Thermo Scientific Q Exactive HF-X Hybrid Quadrupole Orbitrap MS.

Orbitrap Exploris 480: Thermo Scientific Orbitrap Exploris 480 Quadrupole Orbitrap MS.

Orbitrap Eclipse: Thermo Scientific Orbitrap Eclipse mass spectrometer with Tribrid architecture consisting of quadrupole mass filter, linear ion trap and Orbitrap mass analyzers.

Orbitrap Exploris 240: Thermo Scientific Orbitrap Exploris 240 Quadrupole Orbitrap MS.

Orbitrap Exploris 120: Thermo Scientific Orbitrap Exploris 120 Quadrupole Orbitrap MS.

LTQ Orbitrap Velos Pro: Thermo Scientific LTQ Orbitrap Velos Pro, often just referred to as the Orbitrap Velos Pro.

Q Exactive UHMR: Thermo Scientific Q Exactive UHMR (Ultra High Mass Range) Hybrid Quadrupole Orbitrap MS.

TSQ Altis Plus: Thermo Scientific TSQ Altis Plus Triple Quadrupole MS.

Orbitrap Ascend: Thermo Scientific Orbitrap Ascend mass spectrometer with Tribrid architecture consisting of quadrupole mass filter, linear ion trap and Orbitrap mass analyzers.

Orbitrap Astral: Thermo Scientific Orbitrap Astral mass spectrometer contains three mass analyzers: a quadrupole analyzer, an Orbitrap analyzer, and the Astral analyzer.

Reimplemented from pappso::MsRunReader.

Definition at line 1202 of file pwizmsrunreader.cpp.

1203{
1204
1205
1206 pappso::OboPsiModTerm term;
1207
1208 if(getOboPsiModTermNativeIDFormat().getAccession() == "MS:1000768")
1209 {
1210
1211 pappso::FilterOboPsiModMap psims_map;
1212
1213 pappso::OboPsiMs psims_file(psims_map);
1214 // it should be a Thermo instrument
1215 /*
1216 * [Term]
1217 id: MS:1000494
1218 name: Thermo Scientific instrument model
1219 def: "Thermo Scientific instrument model." [PSI:MS]
1220 is_a: MS:1000483 ! Thermo Fisher Scientific instrument model
1221
1222 */
1223 term = psims_map.getOboPsiModTermWithAccession("MS:1000494");
1224
1225 for(auto &param_group : msp_msData.get()->paramGroupPtrs)
1226 {
1227 for(auto &cv_param : param_group.get()->cvParams)
1228 {
1229 if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive)
1230 {
1231 term = psims_map.getOboPsiModTermWithAccession("MS:1001911");
1232 }
1233 else if(cv_param.cvid == pwiz::cv::CVID::MS_Velos_Plus)
1234 {
1235 /// Velos Plus: Thermo Scientific second generation Velos.
1236 term = psims_map.getOboPsiModTermWithAccession("MS:1001909");
1237 }
1238 else if(cv_param.cvid == pwiz::cv::CVID::MS_LTQ_Orbitrap_Elite)
1239 {
1240 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1241 /// to as the Orbitrap Elite.
1242
1243 term = psims_map.getOboPsiModTermWithAccession("MS:1001910");
1244 }
1245
1246 /// Orbitrap Fusion: Thermo Scientific Orbitrap Fusion.
1247 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Fusion)
1248 {
1249 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1250 /// to as the Orbitrap Elite.
1251
1252 term = psims_map.getOboPsiModTermWithAccession("MS:1002416");
1253 }
1254 /// Q Exactive HF: Thermo Scientific Q Exactive.
1255 // MS_Q_Exactive_HF = 1002523,
1256 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_HF)
1257 {
1258 /// LTQ Orbitrap Elite: Thermo Scientific LTQ Orbitrap Elite, often just referred
1259 /// to as the Orbitrap Elite.
1260
1261 term = psims_map.getOboPsiModTermWithAccession("MS:1002523");
1262 }
1263 //
1264 /// Exactive Plus: Thermo Scientific Exactive Plus MS.
1265 else if(cv_param.cvid == pwiz::cv::CVID::MS_Exactive_Plus)
1266 {
1267 term = psims_map.getOboPsiModTermWithAccession("MS:1002526");
1268 }
1269 /// Q Exactive Plus: Thermo Scientific Q Exactive Plus.
1270 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_Plus)
1271 {
1272 term = psims_map.getOboPsiModTermWithAccession("MS:1002634");
1273 }
1274 /// Orbitrap Fusion Lumos: Thermo Scientific Orbitrap Fusion Lumos mass spectrometer
1275 /// with Tribrid architecture consisting of quadrupole mass filter, linear ion trap
1276 /// and Orbitrap mass analyzers.
1277 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Fusion_Lumos)
1278 {
1279 term = psims_map.getOboPsiModTermWithAccession("MS:1002732");
1280 }
1281 /// Q Exactive HF-X: Thermo Scientific Q Exactive HF-X Hybrid Quadrupole Orbitrap MS.
1282 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_HF_X)
1283 {
1284 term = psims_map.getOboPsiModTermWithAccession("MS:1002877");
1285 }
1286 /// Orbitrap Exploris 480: Thermo Scientific Orbitrap Exploris 480 Quadrupole Orbitrap
1287 /// MS.
1288
1289 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_480)
1290 {
1291 term = psims_map.getOboPsiModTermWithAccession("MS:1003028");
1292 }
1293 /// Orbitrap Eclipse: Thermo Scientific Orbitrap Eclipse mass spectrometer with
1294 /// Tribrid architecture consisting of quadrupole mass filter, linear ion trap and
1295 /// Orbitrap mass analyzers.
1296 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Eclipse)
1297 {
1298 term = psims_map.getOboPsiModTermWithAccession("MS:1003029");
1299 }
1300 /// Orbitrap Exploris 240: Thermo Scientific Orbitrap Exploris 240 Quadrupole Orbitrap
1301 /// MS.
1302
1303 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_240)
1304 {
1305 term = psims_map.getOboPsiModTermWithAccession("MS:1003094");
1306 }
1307 /// Orbitrap Exploris 120: Thermo Scientific Orbitrap Exploris 120 Quadrupole Orbitrap
1308 /// MS.
1309
1310 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Exploris_120)
1311 {
1312 term = psims_map.getOboPsiModTermWithAccession("MS:1003095");
1313 }
1314 /// LTQ Orbitrap Velos Pro: Thermo Scientific LTQ Orbitrap Velos Pro, often just
1315 /// referred to as the Orbitrap Velos Pro.
1316 else if(cv_param.cvid == pwiz::cv::CVID::MS_LTQ_Orbitrap_Velos_Pro)
1317 {
1318 term = psims_map.getOboPsiModTermWithAccession("MS:1003096");
1319 }
1320 /// Q Exactive UHMR: Thermo Scientific Q Exactive UHMR (Ultra High Mass Range) Hybrid
1321 /// Quadrupole Orbitrap MS.
1322 else if(cv_param.cvid == pwiz::cv::CVID::MS_Q_Exactive_UHMR)
1323 {
1324 term = psims_map.getOboPsiModTermWithAccession("MS:1003245");
1325 }
1326 /// TSQ Altis Plus: Thermo Scientific TSQ Altis Plus Triple Quadrupole MS.
1327 else if(cv_param.cvid == pwiz::cv::CVID::MS_TSQ_Altis_Plus)
1328 {
1329 term = psims_map.getOboPsiModTermWithAccession("MS:1003292");
1330 }
1331 /// Orbitrap Ascend: Thermo Scientific Orbitrap Ascend mass spectrometer with Tribrid
1332 /// architecture consisting of quadrupole mass filter, linear ion trap and Orbitrap
1333 /// mass analyzers.
1334 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Ascend)
1335 {
1336 term = psims_map.getOboPsiModTermWithAccession("MS:1003356");
1337 }
1338 /// Orbitrap Astral: Thermo Scientific Orbitrap Astral mass spectrometer contains
1339 /// three mass analyzers: a quadrupole analyzer, an Orbitrap analyzer, and the Astral
1340 /// analyzer.
1341 else if(cv_param.cvid == pwiz::cv::CVID::MS_Orbitrap_Astral)
1342 {
1343 term = psims_map.getOboPsiModTermWithAccession("MS:1003378");
1344 }
1345 }
1346 }
1347 }
1348 else
1349 {
1350
1351 throw ExceptionNotFound(QObject::tr("instrument model name not found in %1")
1352 .arg(mcsp_msRunId.get()->getFileName()));
1353 }
1354
1355 return term;
1356}
const OboPsiModTerm & getOboPsiModTermWithAccession(const QString &accession) const
MsRunIdCstSPtr mcsp_msRunId
const OboPsiModTerm getOboPsiModTermNativeIDFormat() const
get OboPsiModTerm corresponding to the nativeID format format of mz data

References getOboPsiModTermNativeIDFormat(), pappso::FilterOboPsiModMap::getOboPsiModTermWithAccession(), pappso::MsRunReader::mcsp_msRunId, and msp_msData.

Referenced by MsFileAccessor.

◆ getOboPsiModTermNativeIDFormat()

const OboPsiModTerm pappso::PwizMsRunReader::getOboPsiModTermNativeIDFormat ( ) const

get OboPsiModTerm corresponding to the nativeID format format of mz data

Definition at line 172 of file pwizmsrunreader.cpp.

173{
174
175 OboPsiModTerm term;
176
177 term.setAccession("MS:1000824");
178 term.m_name = "no nativeID format";
179 term.m_definition =
180 "No nativeID format indicates that the file tagged with this term does "
181 "not "
182 "contain spectra that can have a nativeID format.";
183
184
185 pwiz::cv::CVID cvid = pwiz::msdata::id::getDefaultNativeIDFormat(*(msp_msData.get()));
186
187 switch(cvid)
188 {
189 case pwiz::cv::MS_Thermo_nativeID_format:
190 term.setAccession("MS:1000768");
191 term.m_name = "Thermo nativeID format";
192 term.m_definition =
193 "Native format defined by controllerType=xsd:nonNegativeInteger "
194 "controllerNumber=xsd:positiveInteger scan=xsd:positiveInteger.";
195 break;
196 default:
197 break;
198 }
199 return term;
200}

References pappso::OboPsiModTerm::m_definition, pappso::OboPsiModTerm::m_name, msp_msData, and pappso::OboPsiModTerm::setAccession().

Referenced by getOboPsiModTermInstrumentModelName(), and MsFileAccessor.

◆ getPwizSpectrumPtr()

pwiz::msdata::SpectrumPtr pappso::PwizMsRunReader::getPwizSpectrumPtr ( pwiz::msdata::SpectrumList * p_spectrum_list,
std::size_t spectrum_index,
bool want_binary_data ) const
protected

Definition at line 203 of file pwizmsrunreader.cpp.

206{
207 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp;
208
209 try
210 {
211 native_pwiz_spectrum_sp = p_spectrum_list->spectrum(spectrum_index, want_binary_data);
212 }
213 catch(std::runtime_error &error)
214 {
215 qDebug() << "getPwizSpectrumPtr error " << error.what() << " " << typeid(error).name();
216
217 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in "
218 "MS file std::runtime_error :\n%2")
219 .arg(spectrum_index)
220 .arg(error.what()));
221 }
222 catch(std::exception &error)
223 {
224 qDebug() << "getPwizSpectrumPtr error " << error.what() << typeid(error).name();
225
226 throw ExceptionNotFound(QObject::tr("Pwiz spectrum index %1 not found in MS file :\n%2")
227 .arg(spectrum_index)
228 .arg(error.what()));
229 }
230
231 if(native_pwiz_spectrum_sp.get() == nullptr)
232 {
233 throw ExceptionNotFound(
234 QObject::tr("Pwiz spectrum index %1 not found in MS file : null pointer")
235 .arg(spectrum_index));
236 }
237
238 return native_pwiz_spectrum_sp;
239}

Referenced by MsFileAccessor, qualifiedMassSpectrumFromPwizMSData(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

◆ hasScanNumbers()

bool pappso::PwizMsRunReader::hasScanNumbers ( ) const
overridevirtual

tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file

Reimplemented from pappso::MsRunReader.

Definition at line 1093 of file pwizmsrunreader.cpp.

1094{
1095 return m_hasScanNumbers;
1096}

References m_hasScanNumbers.

Referenced by MsFileAccessor.

◆ initialize()

void pappso::PwizMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 67 of file pwizmsrunreader.cpp.

68{
69 std::string file_name_std = Utils::toUtf8StandardString(mcsp_msRunId->getFileName());
70
71
72 // Now actually search the useful MSDataPtr to the member variable.
73
74 pwiz::msdata::DefaultReaderList defaultReaderList;
75
76 std::vector<pwiz::msdata::MSDataPtr> msDataPtrVector;
77
78 try
79 {
80 defaultReaderList.read(file_name_std, msDataPtrVector);
81 }
82 catch(std::exception &error)
83 {
84 qDebug() << QString("Failed to read the data from file %1")
85 .arg(QString::fromStdString(file_name_std));
86
87 throw(PappsoException(QString("Error reading file %1 in PwizMsRunReader, for msrun %2:\n%3")
88 .arg(mcsp_msRunId->getFileName())
89 .arg(mcsp_msRunId.get()->toString())
90 .arg(error.what())));
91 }
92
93 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
94 //<< "The number of runs is:" << msDataPtrVector.size()
95 //<< "The number of spectra in first run is:"
96 //<< msDataPtrVector.at(0)->run.spectrumListPtr->size();
97
98 // Single-run file handling here.
99
100 // Specific case of the MGF data format: we do not have a run id for that
101 // kind of data. In this case there must be a single run!
102
103 if(mcsp_msRunId->getRunId().isEmpty())
104 {
105 if(msDataPtrVector.size() != 1)
106 throw(
107 ExceptionNotPossible("For the kind of file at hand there can only be "
108 "one run in the file."));
109
110 // At this point we know the single msDataPtr is the one we are looking
111 // for.
112
113 msp_msData = msDataPtrVector.front();
114 }
115 else
116 {
117 // Multi-run file handling here.
118 for(const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
119 {
120 qDebug() << "msDataPtr->run.id=" << msDataPtr->run.id.c_str();
121 qDebug() << "mcsp_msRunId->getRunId()=" << mcsp_msRunId->getRunId();
122 qDebug() << "mcsp_msRunId->getXmlId()=" << mcsp_msRunId->getXmlId();
123 qDebug() << "mcsp_msRunId->getSampleName()=" << mcsp_msRunId->getSampleName();
124 if(msDataPtr->run.id == mcsp_msRunId->getRunId().toStdString())
125 {
126 msp_msData = msDataPtr;
127
128 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
129 // "()"
130 //<< "Found the right MSDataPtr for run id.";
131
132 break;
133 }
134 }
135 }
136
137 if(msp_msData == nullptr)
138 {
139 throw(ExceptionNotPossible(QString("Could not find a pwiz MSDataPtr "
140 "matching the requested run id : %1")
141 .arg(mcsp_msRunId.get()->toString())));
142 }
143
144
145 // check if this MS run can be used with scan numbers
146 // MS:1000490 Agilent instrument model
147 pwiz::cv::CVID native_id_format = pwiz::msdata::id::getDefaultNativeIDFormat(*msp_msData.get());
148
149 // msp_msData.get()->getDefaultNativeIDFormat();
150
151 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
152 {
153 m_hasScanNumbers = true;
154 }
155 else
156 {
157 m_hasScanNumbers = false;
158 }
159
160 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::mzXML)
161 {
162 m_hasScanNumbers = true;
163 }
164}
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:162

References m_hasScanNumbers, pappso::MsRunReader::mcsp_msRunId, msp_msData, pappso::Enums::mzXML, and pappso::Utils::toUtf8StandardString().

Referenced by PwizMsRunReader(), acquireDevice(), and MsFileAccessor.

◆ massSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr pappso::PwizMsRunReader::massSpectrumCstSPtr ( std::size_t spectrum_index)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 751 of file pwizmsrunreader.cpp.

752{
753 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
754 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
755}
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.

References pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr(), and qualifiedMassSpectrum().

Referenced by MsFileAccessor.

◆ massSpectrumSPtr()

pappso::MassSpectrumSPtr pappso::PwizMsRunReader::massSpectrumSPtr ( std::size_t spectrum_index)
overridevirtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 744 of file pwizmsrunreader.cpp.

745{
746 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
747 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumSPtr();
748}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

References pappso::QualifiedMassSpectrum::getMassSpectrumSPtr(), and qualifiedMassSpectrum().

Referenced by MsFileAccessor.

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr pappso::PwizMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum ( const pappso::QualifiedMassSpectrum & mass_spectrum,
pappso::PrecisionPtr precision ) const
overridevirtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 1127 of file pwizmsrunreader.cpp.

1129{
1130 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
1131
1132 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
1133
1134 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
1135
1136 return xic_coord;
1137}
pappso_double getPrecursorMz(bool *ok=nullptr) const
get precursor mz
pappso_double getRtInSeconds() const
Get the retention time in seconds.
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44

References pappso::QualifiedMassSpectrum::getPrecursorMz(), and pappso::QualifiedMassSpectrum::getRtInSeconds().

Referenced by MsFileAccessor, and newXicCoordSPtrFromSpectrumIndex().

◆ newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr pappso::PwizMsRunReader::newXicCoordSPtrFromSpectrumIndex ( std::size_t spectrum_index,
pappso::PrecisionPtr precision ) const
overridevirtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 1117 of file pwizmsrunreader.cpp.

1119{
1120
1121 QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, false);
1122
1123 return newXicCoordSPtrFromQualifiedMassSpectrum(mass_spectrum, precision);
1124}
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum

References newXicCoordSPtrFromQualifiedMassSpectrum(), and qualifiedMassSpectrum().

Referenced by MsFileAccessor.

◆ processDriftTime()

bool pappso::PwizMsRunReader::processDriftTime ( pwiz::msdata::Spectrum * spectrum_p,
QualifiedMassSpectrum & qualified_mass_spectrum ) const
protected

Definition at line 306 of file pwizmsrunreader.cpp.

308{
309 // Not all the acquisitions have ion mobility data. We need to test
310 // that:
311
312 if(spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_ion_mobility_drift_time))
313 {
314
315 // qDebug() << "as strings:"
316 //<< QString::fromStdString(
317 // spectrum_p->scanList.scans[0]
318 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
319 //.valueAs<std::string>());
320
321 pappso_double driftTime = spectrum_p->scanList.scans[0]
322 .cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
323 .valueAs<double>();
324
325 // qDebug() << "driftTime:" << driftTime;
326
327 // Old version requiring use of QString.
328 // pappso_double driftTime =
329 // QString(spectrum_p->scanList.scans[0]
330 //.cvParam(pwiz::msdata::MS_ion_mobility_drift_time)
331 //.value.c_str())
332 //.toDouble();
333
334 // Now make positively sure that the obtained value is correct.
335 // Note that I suffered a lot with Waters Synapt data that
336 // contained apparently correct drift time XML element that in
337 // fact contained either NaN or inf. When such mass spectra were
338 // encountered, the mz,i data were bogus and crashed the data
339 // loading functions. We just want to skip this kind of bogus mass
340 // spectrum by letting the caller know that the drift time was
341 // bogus ("I" is Filippo Rusconi).
342
343 if(std::isnan(driftTime) || std::isinf(driftTime))
344 {
345 // qDebug() << "detected as nan or inf.";
346
347 return false;
348 }
349 else
350 {
351 // The mzML standard stipulates that drift times are in
352 // milliseconds.
353 qualified_mass_spectrum.setDtInMilliSeconds(driftTime);
354 }
355 }
356 // End of
357 // if(spectrum_p->scanList.scans[0].hasCVParam(
358 // pwiz::msdata::MS_ion_mobility_drift_time))
359 else
360 {
361 // Not a bogus mass spectrum but also not a drift spectrum, set -1
362 // as the drift time value.
363 qualified_mass_spectrum.setDtInMilliSeconds(-1);
364 }
365
366 return true;
367}
double pappso_double
A type definition for doubles.
Definition types.h:61

References pappso::QualifiedMassSpectrum::setDtInMilliSeconds().

Referenced by MsFileAccessor, and qualifiedMassSpectrumFromPwizSpectrumPtr().

◆ processRetentionTime()

bool pappso::PwizMsRunReader::processRetentionTime ( pwiz::msdata::Spectrum * spectrum_p,
QualifiedMassSpectrum & qualified_mass_spectrum ) const
protected

Definition at line 243 of file pwizmsrunreader.cpp.

245{
246
247 // We now have to set the retention time at which this mass spectrum
248 // was acquired. This is the scan start time.
249
250 if(!spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_scan_start_time))
251 {
252 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
253 { // MGF could not have scan start time
254 qualified_mass_spectrum.setRtInSeconds(-1);
255 }
256 else
257 {
258 throw(ExceptionNotPossible("The spectrum has no scan start time value set."));
259 }
260 }
261 else
262 {
263 pwiz::data::CVParam retention_time_cv_param =
264 spectrum_p->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time);
265
266 // Try to get the units of the retention time value.
267
268 std::string unit_name = retention_time_cv_param.unitsName();
269 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
270 //<< "Unit name for the retention time:"
271 //<< QString::fromStdString(unit_name);
272
273 if(unit_name == "second")
274 {
275 qualified_mass_spectrum.setRtInSeconds(retention_time_cv_param.valueAs<double>());
276 }
277 else if(unit_name == "minute")
278 {
279 qualified_mass_spectrum.setRtInSeconds(retention_time_cv_param.valueAs<double>() * 60);
280 }
281 else
282 throw(
283 ExceptionNotPossible("Could not determine the unit for the "
284 "scan start time value."));
285 }
286
287 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
288 //<< "Retention time for spectrum is:"
289 //<< qualified_mass_spectrum.getRtInSeconds();
290
291 // Old version not checking unit (by default unit is minutes for RT,
292 // not seconds)
293 //
294 // pappso_double retentionTime =
295 // QString(spectrum_p->scanList.scans[0]
296 //.cvParam(pwiz::msdata::MS_scan_start_time)
297 //.value.c_str())
298 //.toDouble();
299 // qualified_mass_spectrum.setRtInSeconds(retentionTime);
300
301 return true;
302}
@ MGF
Mascot format.
Definition types.h:154

References pappso::MsRunReader::mcsp_msRunId, pappso::Enums::MGF, and pappso::QualifiedMassSpectrum::setRtInSeconds().

Referenced by MsFileAccessor, and qualifiedMassSpectrumFromPwizSpectrumPtr().

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrum ( std::size_t spectrum_index,
bool want_binary_data = true ) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 758 of file pwizmsrunreader.cpp.

759{
760
761 QualifiedMassSpectrum spectrum;
762 bool ok = false;
763
764 spectrum = qualifiedMassSpectrumFromPwizMSData(spectrum_index, want_binary_data, ok);
765
766 if(mcsp_msRunId->getMsDataFormat() == Enums::MsDataFormat::MGF)
767 {
768 if(spectrum.getRtInSeconds() == 0)
769 {
770 // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
771 }
772 }
773
774 // if(!ok)
775 // qDebug() << "Encountered a mass spectrum for which the status is bad.";
776
777 return spectrum;
778}
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizMSData(std::size_t spectrum_index, bool want_binary_data, bool &ok) const

References pappso::QualifiedMassSpectrum::getRtInSeconds(), pappso::MsRunReader::mcsp_msRunId, pappso::Enums::MGF, and qualifiedMassSpectrumFromPwizMSData().

Referenced by massSpectrumCstSPtr(), massSpectrumSPtr(), MsFileAccessor, and newXicCoordSPtrFromSpectrumIndex().

◆ qualifiedMassSpectrumFromPwizMSData()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizMSData ( std::size_t spectrum_index,
bool want_binary_data,
bool & ok ) const
protected

Definition at line 685 of file pwizmsrunreader.cpp.

688{
689
690 std::string backup_env = setGlobalLocaleToEnglish();
691
692 MassSpectrumId massSpectrumId(mcsp_msRunId);
693
694 if(msp_msData == nullptr)
695 {
696 setGlobalLocaleToCurrentOs(backup_env);
697 return (QualifiedMassSpectrum(massSpectrumId));
698 }
699
700 // const bool want_binary_data = true;
701
702 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
703
704 if(spectrum_index == spectrum_list_p.get()->size())
705 {
706 setGlobalLocaleToCurrentOs(backup_env);
707 throw ExceptionNotFound(
708 QObject::tr("The spectrum index cannot be equal to the size of the "
709 "spectrum list."));
710 }
711
712 // At this point we know the spectrum index might be sane, so store it in
713 // the mass spec id object.
714 massSpectrumId.setSpectrumIndex(spectrum_index);
715
716 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
717 getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
718
719 setGlobalLocaleToCurrentOs(backup_env);
720
721 massSpectrumId.setNativeId(QString::fromStdString(native_pwiz_spectrum_sp->id));
722
724 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
725}
static std::string setGlobalLocaleToEnglish()
static void setGlobalLocaleToCurrentOs(const std::string &environment_locale)
QualifiedMassSpectrum qualifiedMassSpectrumFromPwizSpectrumPtr(const MassSpectrumId &massSpectrumId, pwiz::msdata::Spectrum *spectrum_p, bool want_binary_data, bool &ok) const
pwiz::msdata::SpectrumPtr getPwizSpectrumPtr(pwiz::msdata::SpectrumList *p_spectrum_list, std::size_t spectrum_index, bool want_binary_data) const

References getPwizSpectrumPtr(), pappso::MsRunReader::mcsp_msRunId, msp_msData, qualifiedMassSpectrumFromPwizSpectrumPtr(), setGlobalLocaleToCurrentOs(), setGlobalLocaleToEnglish(), pappso::MassSpectrumId::setNativeId(), and pappso::MassSpectrumId::setSpectrumIndex().

Referenced by MsFileAccessor, and qualifiedMassSpectrum().

◆ qualifiedMassSpectrumFromPwizSpectrumPtr()

QualifiedMassSpectrum pappso::PwizMsRunReader::qualifiedMassSpectrumFromPwizSpectrumPtr ( const MassSpectrumId & massSpectrumId,
pwiz::msdata::Spectrum * spectrum_p,
bool want_binary_data,
bool & ok ) const
protected

Definition at line 371 of file pwizmsrunreader.cpp.

375{
376 // qDebug();
377
378 if(spectrum_p == nullptr)
379 qFatal("Spectrum pointer cannot be nullptr.");
380
381 std::string backup_env = setGlobalLocaleToEnglish();
382
383 QualifiedMassSpectrum qualified_mass_spectrum(massSpectrumId);
384
385 try
386 {
387
388 // We want to store the ms level for this spectrum
389
390 int msLevel = (spectrum_p->cvParam(pwiz::msdata::MS_ms_level).valueAs<int>());
391
392 qualified_mass_spectrum.setMsLevel(msLevel);
393
394 if(!spectrum_p->scanList.scans[0].hasCVParam(pwiz::msdata::MS_peak_list_scans))
395 {
396
397 // qDebug() << spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans)
398 // .valueAs<double>();
399 qualified_mass_spectrum.setParameterValue(
401 spectrum_p->cvParam(pwiz::msdata::MS_peak_list_scans).valueAs<double>());
402 }
403 // We want to know if this spectrum is a fragmentation spectrum obtained
404 // from a selected precursor ion.
405
406 std::size_t precursor_list_size = spectrum_p->precursors.size();
407
408 // qDebug() << "For spectrum at index:" <<
409 // massSpectrumId.getSpectrumIndex()
410 //<< "msLevel:" << msLevel
411 //<< "with number of precursors:" << precursor_list_size;
412
413 if(precursor_list_size > 0)
414 {
415
416 // Sanity check
417 if(msLevel < 2)
418 {
419 qDebug() << "Going to throw: msLevel cannot be less than two for "
420 "a spectrum that has items in its Precursor list.";
421
422 throw(
423 ExceptionNotPossible("msLevel cannot be less than two for "
424 "a spectrum that has items in its Precursor list."));
425 }
426
427 // See what is the first precursor in the list.
428
429 for(auto &precursor : spectrum_p->precursors)
430 {
431
432 // Set this variable ready as we need that default value in
433 // certain circumstances.
434
435 std::size_t precursor_spectrum_index = std::numeric_limits<std::size_t>::max();
436
437 // The spectrum ID of the precursor might be empty.
438
439 if(precursor.spectrumID.empty())
440 {
441 // qDebug() << "The precursor's spectrum ID is empty.";
442
443 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
444 {
445 // qDebug()
446 //<< "Format is MGF, precursor's spectrum ID can be
447 // empty.";
448 }
449 else
450 {
451 // When performing Lumos Fusion fragmentation
452 // experiments in Tune mode and with recording, the
453 // first spectrum of the list is a fragmentation
454 // spectrum (ms level 2) that has no identity for the
455 // precursor spectrum because there is no full scan
456 // accquisition.
457 }
458 }
459 // End of
460 // if(precursor.spectrumID.empty())
461 else
462 {
463 // We could get a native precursor spectrum id, so convert
464 // that native id to a spectrum index.
465
466 qualified_mass_spectrum.setPrecursorNativeId(
467 QString::fromStdString(precursor.spectrumID));
468
469 if(qualified_mass_spectrum.getPrecursorNativeId().isEmpty())
470 {
471 // qDebug() << "The native id of the precursor spectrum
472 // is empty.";
473 }
474
475 // Get the spectrum index of the spectrum that contained
476 // the precursor ion.
477
478 precursor_spectrum_index =
479 msp_msData->run.spectrumListPtr->find(precursor.spectrumID);
480
481 // Note that the Mascot MGF format has a peculiar handling
482 // of the precursor ion stuff so we cannot throw.
483 if(precursor_spectrum_index == msp_msData->run.spectrumListPtr->size())
484 {
485 if(mcsp_msRunId.get()->getMsDataFormat() != Enums::MsDataFormat::MGF)
486 {
487 throw(
488 ExceptionNotPossible("Failed to find the index of the "
489 "precursor ion's spectrum."));
490 }
491 }
492
493 qualified_mass_spectrum.setPrecursorSpectrumIndex(precursor_spectrum_index);
494
495 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__
496 // <<
497 // "()"
498 //<< "Set the precursor spectrum index to:"
499 //<< qualified_mass_spectrum.getPrecursorSpectrumIndex()
500 //<< "for qualified mass spectrum:"
501 //<< &qualified_mass_spectrum;
502 }
503
504 if(!precursor.selectedIons.size())
505 {
506 qDebug() << "Going to throw The spectrum has msLevel > 1 but the "
507 "precursor ions's selected ions list is empty..";
508
509 throw(
510 ExceptionNotPossible("The spectrum has msLevel > 1 but the "
511 "precursor ions's selected ions "
512 "list is empty."));
513 }
514
515 pwiz::msdata::SelectedIon &ion = *(precursor.selectedIons.begin());
516
517 // selected ion m/z
518
519 pappso_double selected_ion_mz =
520 QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str()).toDouble();
521
522 // selected ion peak intensity
523 //<cvParam cvRef="MS" accession="MS:1000042"
524 // value="910663.949707031" name="peak intensity"
525 // unitAccession="MS:1000131" unitName="number of detector
526 // counts" unitCvRef="MS" />
527
528 pappso_double selected_ion_peak_intensity =
529 QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str()).toDouble();
530
531 // charge state
532
533 unsigned int selected_ion_charge_state =
534 QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str()).toUInt();
535
536 // At this point we can craft a new PrecursorIonData instance
537 // and push it back to the vector.
538
539 PrecursorIonData precursor_ion_data(
540 selected_ion_mz, selected_ion_charge_state, selected_ion_peak_intensity);
541
542 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
543
544 // General sum-up
545
546 // qDebug()
547 //<< "Appended new PrecursorIonData:"
548 //<< "mz:"
549 //<< qualified_mass_spectrum.getPrecursorIonData().back().mz
550 //<< "charge:"
551 //<< qualified_mass_spectrum.getPrecursorIonData().back().charge
552 //<< "intensity:"
553 //<< qualified_mass_spectrum.getPrecursorIonData()
554 //.back()
555 //.intensity;
556 }
557 // End of
558 // for(auto &precursor : spectrum_p->precursors)
559 }
560 // End of
561 // if(precursor_list_size > 0)
562 else
563 {
564 // Sanity check
565
566 // Unfortunately, logic here is defeated by some vendors that have
567 // files with MS2 spectra without <precursorList>. Thus we have
568 // spectrum_p->precursors.size() == 0 and msLevel > 1.
569
570 // if(msLevel != 1)
571 //{
572 // throw(
573 // ExceptionNotPossible("msLevel cannot be different than 1 if "
574 //"there is not a single precursor ion."));
575 //}
576 }
577
578 // Sanity check.
579
580 if(precursor_list_size != qualified_mass_spectrum.getPrecursorIonData().size())
581 {
582 qDebug() << "Going to throw The number of precursors in the file is "
583 "different from the number of precursors in memory.";
584
585 throw pappso::PappsoException(
586 QObject::tr("The number of precursors in the file is different "
587 "from the number of precursors in memory."));
588 }
589
590 // if(precursor_list_size == 1)
591 //{
592 // qDebug() << "Trying to get the mz value of the unique precursor ion:"
593 //<< qualified_mass_spectrum.getPrecursorMz();
594 //}
595
596 processRetentionTime(spectrum_p, qualified_mass_spectrum);
597
598 processDriftTime(spectrum_p, qualified_mass_spectrum);
599
600 // for(pwiz::data::CVParam cv_param : ion.cvParams)
601 //{
602 // pwiz::msdata::CVID param_id = cv_param.cvid;
603 // qDebug() << param_id;
604 // qDebug() << cv_param.cvid.c_str();
605 // qDebug() << cv_param.name().c_str();
606 // qDebug() << cv_param.value.c_str();
607 //}
608
609 if(want_binary_data)
610 {
611
612 // Fill-in MZIntensityPair vector for convenient access to binary
613 // data
614
615 std::vector<pwiz::msdata::MZIntensityPair> pairs;
616 spectrum_p->getMZIntensityPairs(pairs);
617
618 MassSpectrum spectrum;
619 double tic = 0;
620 // std::size_t iterCount = 0;
621
622 // Iterate through the m/z-intensity pairs
623 for(std::vector<pwiz::msdata::MZIntensityPair>::const_iterator it = pairs.begin(),
624 end = pairs.end();
625 it != end;
626 ++it)
627 {
628 //++iterCount;
629
630 // qDebug() << "it->mz " << it->mz << " it->intensity" <<
631 // it->intensity;
632 if(it->intensity)
633 {
634 spectrum.push_back(DataPoint(it->mz, it->intensity));
635 tic += it->intensity;
636 }
637 }
638
639 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::MGF)
640 {
641 // Sort peaks by mz
642 spectrum.sortMz();
643 }
644
645 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()
646 // "<< spectrum.size();
647 MassSpectrumSPtr spectrum_sp = spectrum.makeMassSpectrumSPtr();
648 qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
649
650 // double sumY =
651 // qualified_mass_spectrum.getMassSpectrumSPtr()->sumY(); qDebug()
652 // <<
653 // __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
654 //<< "iterCount:" << iterCount << "Spectrum size "
655 //<< spectrum.size() << "with tic:" << tic
656 //<< "and sumY:" << sumY;
657 }
658 else
659 qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
660 }
661 catch(PappsoException &errorp)
662 {
663 qDebug() << "Going to throw";
664
665 throw pappso::PappsoException(
666 QObject::tr("Error reading data using the proteowizard library: %1").arg(errorp.qwhat()));
667 }
668 catch(std::exception &error)
669 {
670 qDebug() << "Going to throw";
671
672 throw pappso::PappsoException(
673 QObject::tr("Error reading data using the proteowizard library: %1").arg(error.what()));
674 }
675
676 ok = true;
677
678 // qDebug() << "QualifiedMassSpectrum: " <<
679 // qualified_mass_spectrum.toString();
680 return qualified_mass_spectrum;
681}
bool processDriftTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
bool processRetentionTime(pwiz::msdata::Spectrum *spectrum_p, QualifiedMassSpectrum &qualified_mass_spectrum) const
std::shared_ptr< MassSpectrum > MassSpectrumSPtr

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::QualifiedMassSpectrum::getPrecursorIonData(), pappso::QualifiedMassSpectrum::getPrecursorNativeId(), pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::Enums::MGF, msp_msData, processDriftTime(), processRetentionTime(), pappso::PappsoException::qwhat(), pappso::ScanNumber, setGlobalLocaleToEnglish(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::QualifiedMassSpectrum::setParameterValue(), pappso::QualifiedMassSpectrum::setPrecursorNativeId(), pappso::QualifiedMassSpectrum::setPrecursorSpectrumIndex(), and pappso::MassSpectrum::sortMz().

Referenced by MsFileAccessor, qualifiedMassSpectrumFromPwizMSData(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

◆ readSpectrumCollection()

void pappso::PwizMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface & handler)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 782 of file pwizmsrunreader.cpp.

783{
784 try
785 {
787 }
788 catch(std::exception &error)
789 {
790 qDebug() << "Going to throw";
791
792 throw pappso::PappsoException(
793 QObject::tr("Error reading data (spectrum collection) using the "
794 "proteowizard library: %1")
795 .arg(error.what()));
796 }
797}
virtual void readSpectrumCollectionByMsLevel(SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

References readSpectrumCollectionByMsLevel().

Referenced by MsFileAccessor.

◆ readSpectrumCollection2()

void pappso::PwizMsRunReader::readSpectrumCollection2 ( const MsRunReadConfig & config,
SpectrumCollectionHandlerInterface & handler )
overridevirtual

Implements pappso::MsRunReader.

Definition at line 800 of file pwizmsrunreader.cpp.

802{
803 qDebug();
804 try
805 {
807 }
808 catch(std::exception &error)
809 {
810 qDebug() << "Going to throw";
811
812 throw pappso::PappsoException(
813 QObject::tr("Error reading data (spectrum collection2) using the "
814 "proteowizard library: %1")
815 .arg(error.what()));
816 }
817}
virtual void readSpectrumCollectionWithMsrunReadConfig(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)

References readSpectrumCollectionWithMsrunReadConfig().

Referenced by MsFileAccessor.

◆ readSpectrumCollectionByMsLevel()

void pappso::PwizMsRunReader::readSpectrumCollectionByMsLevel ( SpectrumCollectionHandlerInterface & handler,
unsigned int ms_level )
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

Implements pappso::MsRunReader.

Definition at line 820 of file pwizmsrunreader.cpp.

822{
823
825 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
826
827 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
828 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
829 // spectrum has been fully qualified (that is, the member data have been
830 // set), it is transferred to the handler passed as parameter to this
831 // function for the consumer to do what it wants with it.
832
833 // Does the handler consuming the mass spectra read from file want these
834 // mass spectra to hold the binary data arrays (mz/i vectors)?
835
836 const bool want_binary_data = handler.needPeakList();
837
838 std::string backup_env = setGlobalLocaleToEnglish();
839
840 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
841 // run member of msp_msData.
842
843 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
844
845 // We'll need it to perform the looping in the spectrum list.
846 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
847
848 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
849
850 // Inform the handler of the spectrum list so that it can handle feedback to
851 // the user.
852 handler.spectrumListHasSize(spectrum_list_size);
853
854 // Iterate in the full list of spectra.
855
856 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
857 {
858
859 // If the user of this reader instance wants to stop reading the
860 // spectra, then break this loop.
861 if(handler.shouldStop())
862 {
863 qDebug() << "The operation was cancelled. Breaking the loop.";
864 break;
865 }
866
867 // Get the native pwiz-spectrum from the spectrum list.
868 // Note that this pointer is a shared pointer from pwiz.
869
870 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
871 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
872 /*
873 * we want to load metadata of the spectrum even if it does not contain
874 peaks
875
876 * if(!native_pwiz_spectrum_sp->hasBinaryData())
877 {
878 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
879 "
880 ()"
881 //<< "native pwiz spectrum is empty, continuing.";
882 continue;
883 }
884 */
885
886 // Instantiate the mass spectrum id that will hold critical information
887 // like the the native id string and the spectrum index.
888
889 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
890
891 // Get the spectrum native id as a QString to store it in the mass
892 // spectrum id class. This is will allow later to refer to the same
893 // spectrum starting back from the file.
894
895 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
896 massSpectrumId.setNativeId(native_id);
897
898 // Finally, instantiate the qualified mass spectrum with its id. This
899 // function will continue performing pappso-spectrum detailed
900 // qualification.
901
902 bool ok = false;
903
904 QualifiedMassSpectrum qualified_mass_spectrum = qualifiedMassSpectrumFromPwizSpectrumPtr(
905 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
906
907 if(!ok)
908 {
909 // qDebug() << "Encountered a mass spectrum for which the returned "
910 //"status is bad.";
911 continue;
912 }
913
914 // Before handing the mass spectrum out to the handler, see if the
915 // native mass spectrum was empty or not.
916
917 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
918 // qDebug() << "The mass spectrum has not defaultArrayLength";
919
920 qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
921
922 // The handler will receive the index of the mass spectrum in the
923 // current run via the mass spectrum id member datum.
924 if(ms_level == 0)
925 {
926 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
927 }
928 else
929 {
930 if(qualified_mass_spectrum.getMsLevel() == ms_level)
931 {
932 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
933 }
934 }
935 }
936
937 setGlobalLocaleToCurrentOs(backup_env);
938 // End of
939 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
940
941 // Now let the loading handler know that the loading of the data has ended.
942 // The handler might need this "signal" to perform additional tasks or to
943 // cleanup cruft.
944
945 // qDebug() << "Loading ended";
946 handler.loadingEnded();
947}
virtual bool acquireDevice() override
acquire data back end device

References acquireDevice(), pappso::QualifiedMassSpectrum::getMsLevel(), getPwizSpectrumPtr(), pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MsRunReader::mcsp_msRunId, msp_msData, pappso::SpectrumCollectionHandlerInterface::needPeakList(), qualifiedMassSpectrumFromPwizSpectrumPtr(), pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), setGlobalLocaleToCurrentOs(), setGlobalLocaleToEnglish(), pappso::MassSpectrumId::setNativeId(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::shouldStop(), and pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize().

Referenced by MsFileAccessor, and readSpectrumCollection().

◆ readSpectrumCollectionWithMsrunReadConfig()

void pappso::PwizMsRunReader::readSpectrumCollectionWithMsrunReadConfig ( const MsRunReadConfig & config,
SpectrumCollectionHandlerInterface & handler )
protectedvirtual

Definition at line 950 of file pwizmsrunreader.cpp.

952{
954 // qDebug();
955
956 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
957 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
958 // spectrum has been fully qualified (that is, the member data have been
959 // set), it is transferred to the handler passed as parameter to this
960 // function for the consumer to do what it wants with it.
961
962 // Does the handler consuming the mass spectra read from file want these
963 // mass spectra to hold the binary data arrays (mz/i vectors)?
964
965 const bool want_binary_data = config.needPeakList();
966
967
968 std::string backup_env = setGlobalLocaleToEnglish();
969
970 // qDebug();
971 // We access the pwiz-mass-spectra via the spectrumListPtr that sits in the
972 // run member of msp_msData.
973
974 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
975
976 // We'll need it to perform the looping in the spectrum list.
977 std::size_t spectrum_list_size = spectrum_list_p.get()->size();
978
979 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
980
981 // Inform the handler of the spectrum list so that it can handle feedback to
982 // the user.
983 handler.spectrumListHasSize(spectrum_list_size);
984
985 // Iterate in the full list of spectra.
986
987 qDebug();
988 for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
989 {
990
991
992 // If the user of this reader instance wants to stop reading the
993 // spectra, then break this loop.
994 if(handler.shouldStop())
995 {
996 qDebug() << "The operation was cancelled. Breaking the loop.";
997 break;
998 }
999
1000 // qDebug();
1001 // Get the native pwiz-spectrum from the spectrum list.
1002 // Note that this pointer is a shared pointer from pwiz.
1003
1004 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
1005 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
1006 // qDebug();
1007 /*
1008 * we want to load metadata of the spectrum even if it does not contain
1009 peaks
1010
1011 * if(!native_pwiz_spectrum_sp->hasBinaryData())
1012 {
1013 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ <<
1014 "
1015 ()"
1016 //<< "native pwiz spectrum is empty, continuing.";
1017 continue;
1018 }
1019 */
1020
1021 // Instantiate the mass spectrum id that will hold critical information
1022 // like the the native id string and the spectrum index.
1023
1024 MassSpectrumId massSpectrumId(mcsp_msRunId, iter /* spectrum index*/);
1025
1026 // qDebug();
1027 // Get the spectrum native id as a QString to store it in the mass
1028 // spectrum id class. This is will allow later to refer to the same
1029 // spectrum starting back from the file.
1030
1031 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
1032 massSpectrumId.setNativeId(native_id);
1033
1034 // Finally, instantiate the qualified mass spectrum with its id. This
1035 // function will continue performing pappso-spectrum detailed
1036 // qualification.
1037
1038 bool ok = false;
1039
1040 QualifiedMassSpectrum qualified_mass_spectrum = qualifiedMassSpectrumFromPwizSpectrumPtr(
1041 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
1042
1043 if(!ok)
1044 {
1045 // qDebug() << "Encountered a mass spectrum for which the returned "
1046 //"status is bad.";
1047 continue;
1048 }
1049
1050 // qDebug();
1051 // Before handing the mass spectrum out to the handler, see if the
1052 // native mass spectrum was empty or not.
1053
1054 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
1055 // qDebug() << "The mass spectrum has not defaultArrayLength";
1056
1057 qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
1058
1059 // The handler will receive the index of the mass spectrum in the
1060 // current run via the mass spectrum id member datum.
1061
1062 // qDebug();
1063 if(config.acceptMsLevel(qualified_mass_spectrum.getMsLevel()))
1064 {
1065 if(config.acceptRetentionTimeInSeconds(qualified_mass_spectrum.getRtInSeconds()))
1066 {
1067 handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
1068 }
1069 }
1070 }
1071
1072
1073 qDebug();
1074 setGlobalLocaleToCurrentOs(backup_env);
1075 // End of
1076 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
1077
1078 // Now let the loading handler know that the loading of the data has ended.
1079 // The handler might need this "signal" to perform additional tasks or to
1080 // cleanup cruft.
1081
1082 qDebug() << "Loading ended";
1083 handler.loadingEnded();
1084}

References pappso::MsRunReadConfig::acceptMsLevel(), pappso::MsRunReadConfig::acceptRetentionTimeInSeconds(), acquireDevice(), pappso::QualifiedMassSpectrum::getMsLevel(), getPwizSpectrumPtr(), pappso::QualifiedMassSpectrum::getRtInSeconds(), pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MsRunReader::mcsp_msRunId, msp_msData, pappso::MsRunReadConfig::needPeakList(), qualifiedMassSpectrumFromPwizSpectrumPtr(), pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), setGlobalLocaleToCurrentOs(), setGlobalLocaleToEnglish(), pappso::MassSpectrumId::setNativeId(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::shouldStop(), and pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize().

Referenced by MsFileAccessor, and readSpectrumCollection2().

◆ releaseDevice()

bool pappso::PwizMsRunReader::releaseDevice ( )
overridevirtual

release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 1099 of file pwizmsrunreader.cpp.

1100{
1101 msp_msData = nullptr;
1102 return true;
1103}

References msp_msData.

Referenced by MsFileAccessor.

◆ setGlobalLocaleToCurrentOs()

void pappso::PwizMsRunReader::setGlobalLocaleToCurrentOs ( const std::string & environment_locale)
staticprotected

Definition at line 1163 of file pwizmsrunreader.cpp.

1164{
1165 try
1166 {
1167#ifdef MXE
1168 // std::locale::global(std::locale("C")); // set locale to default
1169 // locale
1170 std::setlocale(LC_ALL, environment_locale.c_str());
1171#else
1172 std::locale::global(std::locale("")); // sets locale according to OS environment
1173#endif
1174 }
1175 catch(std::exception &error)
1176 {
1177 throw pappso::PappsoException(
1178 QObject::tr("Error trying to set local to original system one %1 : %2")
1179 .arg(environment_locale.c_str())
1180 .arg(error.what()));
1181 }
1182}

Referenced by MsFileAccessor, qualifiedMassSpectrumFromPwizMSData(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

◆ setGlobalLocaleToEnglish()

std::string pappso::PwizMsRunReader::setGlobalLocaleToEnglish ( )
staticprotected

Definition at line 1139 of file pwizmsrunreader.cpp.

1140{
1141 std::string env_backup;
1142 try
1143 {
1144#ifdef MXE
1145 // std::locale::global(std::locale("C")); // set locale to default
1146 // locale
1147
1148 std::string env_backup = std::setlocale(LC_ALL, nullptr);
1149 std::setlocale(LC_ALL, "C");
1150#else
1151 std::locale::global(std::locale("C")); // set locale to default locale
1152#endif
1153 }
1154 catch(std::exception &error)
1155 {
1156 throw pappso::PappsoException(
1157 QObject::tr("Error trying to set local to C : %1").arg(error.what()));
1158 }
1159 return env_backup;
1160}

Referenced by MsFileAccessor, qualifiedMassSpectrumFromPwizMSData(), qualifiedMassSpectrumFromPwizSpectrumPtr(), readSpectrumCollectionByMsLevel(), and readSpectrumCollectionWithMsrunReadConfig().

◆ spectrumListSize()

std::size_t pappso::PwizMsRunReader::spectrumListSize ( ) const
overridevirtual

get the totat number of spectrum conained in the MSrun data file

Implements pappso::MsRunReader.

Definition at line 1087 of file pwizmsrunreader.cpp.

1088{
1089 return msp_msData->run.spectrumListPtr.get()->size();
1090}

References msp_msData.

Referenced by MsFileAccessor.

◆ spectrumStringIdentifier2SpectrumIndex()

std::size_t pappso::PwizMsRunReader::spectrumStringIdentifier2SpectrumIndex ( const QString & spectrum_identifier)
overridevirtual

if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found

Parameters
spectrum_identifierstring identifier of a specific spectrum
Returns
the spectrum index

Implements pappso::MsRunReader.

Definition at line 1185 of file pwizmsrunreader.cpp.

1186{
1187 acquireDevice();
1188 std::size_t spectrum_id =
1189 msp_msData->run.spectrumListPtr->find(spectrum_identifier.toStdString());
1190 if(spectrum_id == msp_msData->run.spectrumListPtr->size())
1191 {
1192 throw pappso::ExceptionNotFound(
1193 QObject::tr("Spectrum identifier %1 not found").arg(spectrum_identifier));
1194 }
1195 return spectrum_id;
1196}

References acquireDevice(), and msp_msData.

Referenced by MsFileAccessor.

Friends And Related Symbol Documentation

◆ MsFileAccessor

Member Data Documentation

◆ m_hasScanNumbers

bool pappso::PwizMsRunReader::m_hasScanNumbers = false
private

Definition at line 133 of file pwizmsrunreader.h.

Referenced by hasScanNumbers(), and initialize().

◆ m_mutex

QMutex pappso::PwizMsRunReader::m_mutex
staticprotected

Definition at line 128 of file pwizmsrunreader.h.

◆ msp_msData


The documentation for this class was generated from the following files: