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 ()
 
const pwiz::msdata::MSDataPtr getMsDataPtr () const
 
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
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
 
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
 
void checkNativeId (const pwiz::msdata::Spectrum *pwiz_spectrum_ptr, MassSpectrumId &mass_spectrum_id) const
 

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}
MsRunReader(const MsRunIdCstSPtr &ms_run_id)
virtual void initialize() override

References initialize().

◆ ~PwizMsRunReader()

pappso::PwizMsRunReader::~PwizMsRunReader ( )
virtual

Definition at line 164 of file pwizmsrunreader.cpp.

165{
166}

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 734 of file pwizmsrunreader.cpp.

735{
736 // We want to know if we can handle the file_name.
737 pwiz::msdata::ReaderList reader_list;
738
739 std::string reader_type = reader_list.identify(file_name.toStdString());
740
741 if(!reader_type.empty())
742 return true;
743
744 return false;
745}

◆ acquireDevice()

bool pappso::PwizMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 1134 of file pwizmsrunreader.cpp.

1135{
1136 if(msp_msData == nullptr)
1137 {
1138 initialize();
1139 }
1140 return true;
1141}
pwiz::msdata::MSDataPtr msp_msData

References initialize(), and msp_msData.

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

◆ checkNativeId()

void pappso::PwizMsRunReader::checkNativeId ( const pwiz::msdata::Spectrum *  pwiz_spectrum_ptr,
MassSpectrumId mass_spectrum_id 
) const
protected

Definition at line 955 of file pwizmsrunreader.cpp.

957{
958 QString native_id = QString::fromStdString(pwiz_spectrum_ptr->id);
959 mass_spectrum_id.setNativeId(native_id);
960
961
962 // qWarning() << "native_id";
963 if(mcsp_msRunId->getMsDataFormat() == Enums::MsDataFormat::MGF)
964 {
965 std::vector<pwiz::data::CVParam>::const_iterator it =
966 find_if(pwiz_spectrum_ptr->cvParams.cbegin(),
967 pwiz_spectrum_ptr->cvParams.cend(),
968 pwiz::data::CVParamIs(pwiz::cv::MS_spectrum_title));
969 if(it != pwiz_spectrum_ptr->cvParams.cend())
970 {
971 mass_spectrum_id.setNativeId(QString::fromStdString(it->value));
972 // qWarning() << QString::fromStdString(it->value);
973 }
974 }
975}
MsRunIdCstSPtr mcsp_msRunId

References pappso::MsRunReader::mcsp_msRunId, pappso::Enums::MGF, and pappso::MassSpectrumId::setNativeId().

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

◆ getMsDataPtr()

const pwiz::msdata::MSDataPtr pappso::PwizMsRunReader::getMsDataPtr ( ) const

Definition at line 170 of file pwizmsrunreader.cpp.

171{
172 return msp_msData;
173}

References msp_msData.

◆ 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 1230 of file pwizmsrunreader.cpp.

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

◆ getOboPsiModTermNativeIDFormat()

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

get OboPsiModTerm corresponding to the nativeID format format of mz data

Definition at line 176 of file pwizmsrunreader.cpp.

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

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

Referenced by getOboPsiModTermInstrumentModelName().

◆ 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 207 of file pwizmsrunreader.cpp.

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

Referenced by 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 1121 of file pwizmsrunreader.cpp.

1122{
1123 return m_hasScanNumbers;
1124}

References m_hasScanNumbers.

◆ 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() << "The number of runs is:" << msDataPtrVector.size()
94 << "The number of spectra in first run is:"
95 << msDataPtrVector.at(0)->run.spectrumListPtr->size();
96
97 // Single-run file handling here.
98
99 // Specific case of the MGF data format: we do not have a run id for that
100 // kind of data. In this case there must be a single run!
101
102 if(mcsp_msRunId->getRunId().isEmpty())
103 {
104 if(msDataPtrVector.size() != 1)
105 throw(
106 ExceptionNotPossible("For the kind of file at hand there can only be "
107 "one run in the file."));
108
109 // At this point we know the single msDataPtr is the one we are looking
110 // for.
111
112 msp_msData = msDataPtrVector.front();
113 }
114 else
115 {
116 // Multi-run file handling here.
117 for(const pwiz::msdata::MSDataPtr &msDataPtr : msDataPtrVector)
118 {
119 qDebug() << "msDataPtr->run.id=" << msDataPtr->run.id.c_str();
120 qDebug() << "mcsp_msRunId->getRunId()=" << mcsp_msRunId->getRunId();
121 qDebug() << "mcsp_msRunId->getXmlId()=" << mcsp_msRunId->getXmlId();
122 qDebug() << "mcsp_msRunId->getSampleName()=" << mcsp_msRunId->getSampleName();
123
124 if(msDataPtr->run.id == mcsp_msRunId->getRunId().toStdString())
125 {
126 msp_msData = msDataPtr;
127
128 qDebug() << "Found the right MSDataPtr for run id.";
129
130 break;
131 }
132 }
133 }
134
135 if(msp_msData == nullptr)
136 {
137 throw(ExceptionNotPossible(QString("Could not find a pwiz MSDataPtr "
138 "matching the requested run id : %1")
139 .arg(mcsp_msRunId.get()->toString())));
140 }
141
142
143 // check if this MS run can be used with scan numbers
144 // MS:1000490 Agilent instrument model
145 pwiz::cv::CVID native_id_format = pwiz::msdata::id::getDefaultNativeIDFormat(*msp_msData.get());
146
147 // msp_msData.get()->getDefaultNativeIDFormat();
148
149 if(native_id_format == pwiz::cv::CVID::MS_Thermo_nativeID_format)
150 {
151 m_hasScanNumbers = true;
152 }
153 else
154 {
155 m_hasScanNumbers = false;
156 }
157
158 if(mcsp_msRunId.get()->getMsDataFormat() == Enums::MsDataFormat::mzXML)
159 {
160 m_hasScanNumbers = true;
161 }
162}
static std::string toUtf8StandardString(const QString &text)
Definition utils.cpp:166

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

Referenced by PwizMsRunReader(), and acquireDevice().

◆ massSpectrumCstSPtr()

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

Implements pappso::MsRunReader.

Definition at line 756 of file pwizmsrunreader.cpp.

757{
758 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
759 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumCstSPtr();
760}
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().

◆ 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 749 of file pwizmsrunreader.cpp.

750{
751 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
752 return qualifiedMassSpectrum(spectrum_index, true).getMassSpectrumSPtr();
753}
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.

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

◆ 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 1155 of file pwizmsrunreader.cpp.

1157{
1158 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
1159
1160 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
1161
1162 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
1163
1164 return xic_coord;
1165}
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 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 1145 of file pwizmsrunreader.cpp.

1147{
1148
1149 QualifiedMassSpectrum mass_spectrum = qualifiedMassSpectrum(spectrum_index, false);
1150
1151 return newXicCoordSPtrFromQualifiedMassSpectrum(mass_spectrum, precision);
1152}
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().

◆ processDriftTime()

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

Definition at line 310 of file pwizmsrunreader.cpp.

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

References pappso::QualifiedMassSpectrum::setDtInMilliSeconds().

Referenced by qualifiedMassSpectrumFromPwizSpectrumPtr().

◆ processRetentionTime()

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

Definition at line 247 of file pwizmsrunreader.cpp.

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

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

Referenced by 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 763 of file pwizmsrunreader.cpp.

764{
765
766 QualifiedMassSpectrum spectrum;
767 bool ok = false;
768
769 spectrum = qualifiedMassSpectrumFromPwizMSData(spectrum_index, want_binary_data, ok);
770
771 if(mcsp_msRunId->getMsDataFormat() == Enums::MsDataFormat::MGF)
772 {
773 if(spectrum.getRtInSeconds() == 0)
774 {
775 // spectrum = qualifiedMassSpectrumFromPwizMSData(scan_num - 1);
776 }
777 }
778
779 // if(!ok)
780 // qDebug() << "Encountered a mass spectrum for which the status is bad.";
781
782 return spectrum;
783}
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(), and newXicCoordSPtrFromSpectrumIndex().

◆ qualifiedMassSpectrumFromPwizMSData()

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

Definition at line 689 of file pwizmsrunreader.cpp.

692{
693
694 std::string backup_env = setGlobalLocaleToEnglish();
695
696 MassSpectrumId massSpectrumId(mcsp_msRunId);
697
698 if(msp_msData == nullptr)
699 {
700 setGlobalLocaleToCurrentOs(backup_env);
701 return (QualifiedMassSpectrum(massSpectrumId));
702 }
703
704 // const bool want_binary_data = true;
705
706 pwiz::msdata::SpectrumListPtr spectrum_list_p = msp_msData->run.spectrumListPtr;
707
708 if(spectrum_index == spectrum_list_p.get()->size())
709 {
710 setGlobalLocaleToCurrentOs(backup_env);
711 throw ExceptionNotFound(
712 QObject::tr("The spectrum index cannot be equal to the size of the "
713 "spectrum list."));
714 }
715
716 // At this point we know the spectrum index might be sane, so store it in
717 // the mass spec id object.
718 massSpectrumId.setSpectrumIndex(spectrum_index);
719
720 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
721 getPwizSpectrumPtr(spectrum_list_p.get(), spectrum_index, want_binary_data);
722
723 setGlobalLocaleToCurrentOs(backup_env);
724
725 checkNativeId(native_pwiz_spectrum_sp.get(), massSpectrumId);
726
727
729 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
730}
static std::string setGlobalLocaleToEnglish()
void checkNativeId(const pwiz::msdata::Spectrum *pwiz_spectrum_ptr, MassSpectrumId &mass_spectrum_id) const
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 checkNativeId(), getPwizSpectrumPtr(), pappso::MsRunReader::mcsp_msRunId, msp_msData, qualifiedMassSpectrumFromPwizSpectrumPtr(), setGlobalLocaleToCurrentOs(), setGlobalLocaleToEnglish(), and pappso::MassSpectrumId::setSpectrumIndex().

Referenced by 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 375 of file pwizmsrunreader.cpp.

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

788{
789 try
790 {
792 }
793 catch(std::exception &error)
794 {
795 qDebug() << "Going to throw";
796
798 QObject::tr("Error reading data (spectrum collection) using the "
799 "proteowizard library: %1")
800 .arg(error.what()));
801 }
802}
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().

◆ readSpectrumCollection2()

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

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

Implements pappso::MsRunReader.

Definition at line 805 of file pwizmsrunreader.cpp.

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

References readSpectrumCollectionWithMsrunReadConfig().

◆ 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 825 of file pwizmsrunreader.cpp.

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

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

Referenced by readSpectrumCollection().

◆ readSpectrumCollectionWithMsrunReadConfig()

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

Definition at line 978 of file pwizmsrunreader.cpp.

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

References pappso::MsRunReadConfig::acceptMsLevel(), pappso::MsRunReadConfig::acceptRetentionTimeInSeconds(), acquireDevice(), checkNativeId(), 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::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::SpectrumCollectionHandlerInterface::shouldStop(), and pappso::SpectrumCollectionHandlerInterface::spectrumListHasSize().

Referenced by 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 1127 of file pwizmsrunreader.cpp.

1128{
1129 msp_msData = nullptr;
1130 return true;
1131}

References msp_msData.

◆ setGlobalLocaleToCurrentOs()

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

Definition at line 1191 of file pwizmsrunreader.cpp.

1192{
1193 try
1194 {
1195#ifdef MXE
1196 // std::locale::global(std::locale("C")); // set locale to default
1197 // locale
1198 std::setlocale(LC_ALL, environment_locale.c_str());
1199#else
1200 std::locale::global(std::locale("")); // sets locale according to OS environment
1201#endif
1202 }
1203 catch(std::exception &error)
1204 {
1206 QObject::tr("Error trying to set local to original system one %1 : %2")
1207 .arg(environment_locale.c_str())
1208 .arg(error.what()));
1209 }
1210}

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

◆ setGlobalLocaleToEnglish()

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

Definition at line 1167 of file pwizmsrunreader.cpp.

1168{
1169 std::string env_backup;
1170 try
1171 {
1172#ifdef MXE
1173 // std::locale::global(std::locale("C")); // set locale to default
1174 // locale
1175
1176 std::string env_backup = std::setlocale(LC_ALL, nullptr);
1177 std::setlocale(LC_ALL, "C");
1178#else
1179 std::locale::global(std::locale("C")); // set locale to default locale
1180#endif
1181 }
1182 catch(std::exception &error)
1183 {
1185 QObject::tr("Error trying to set local to C : %1").arg(error.what()));
1186 }
1187 return env_backup;
1188}

Referenced by 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 1115 of file pwizmsrunreader.cpp.

1116{
1117 return msp_msData->run.spectrumListPtr.get()->size();
1118}

References msp_msData.

◆ 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 1213 of file pwizmsrunreader.cpp.

1214{
1215 acquireDevice();
1216 std::size_t spectrum_id =
1217 msp_msData->run.spectrumListPtr->find(spectrum_identifier.toStdString());
1218 if(spectrum_id == msp_msData->run.spectrumListPtr->size())
1219 {
1221 QObject::tr("Spectrum identifier %1 not found").arg(spectrum_identifier));
1222 }
1223 return spectrum_id;
1224}

References acquireDevice(), and msp_msData.

Friends And Related Symbol Documentation

◆ MsFileAccessor

friend class MsFileAccessor
friend

Definition at line 47 of file pwizmsrunreader.h.

Member Data Documentation

◆ m_hasScanNumbers

bool pappso::PwizMsRunReader::m_hasScanNumbers = false
private

Definition at line 138 of file pwizmsrunreader.h.

Referenced by hasScanNumbers(), and initialize().

◆ m_mutex

QMutex pappso::PwizMsRunReader::m_mutex
staticprotected

Definition at line 133 of file pwizmsrunreader.h.

◆ msp_msData


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