Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension of bruker precursor information (2nd attempt) #3191

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ba475f1
Feature Reader Bruker with extended precursor info
xjasg Nov 6, 2023
c9f071e
Collisional Cross Sectional Area added
Andre99999999 Sep 4, 2024
5c7e77a
mzXML and MGF Reader/Writer externded
xjasg Nov 19, 2023
e8e5c5e
Bugfix Typo
xjasg Nov 25, 2023
112bf17
Changes after review
Andre99999999 Sep 4, 2024
0b8ffc4
Bugfix merges
Andre99999999 Sep 4, 2024
ee17fef
Test files changed
Andre99999999 Sep 7, 2024
8aeecd0
lowest and highest observed mz
Andre99999999 Sep 29, 2024
0f3b1a3
small cleanup
Andre99999999 Sep 29, 2024
8104588
Merge branch 'master' into feature/bruker_precursor_2
xjasg Oct 10, 2024
3ab4cff
Bugfix
Andre99999999 Oct 10, 2024
912c3c6
Fix Build exception
Andre99999999 Oct 11, 2024
56949cf
Bugfix unused header
Andre99999999 Oct 11, 2024
e7bf0d5
Revert changes after review
Andre99999999 Oct 11, 2024
3e7fd96
Remove unnecessary code
Andre99999999 Oct 11, 2024
5f5a974
Remove unused function
Andre99999999 Oct 11, 2024
ef4e5d4
cleanup
Andre99999999 Oct 11, 2024
e2e6ea2
Revert "lowest and highest observed mz"
Andre99999999 Oct 11, 2024
bb1a8ee
Partially revert last changes ( add intensity population again )
Andre99999999 Oct 31, 2024
853d207
Whitespace issues
Andre99999999 Nov 1, 2024
701ac75
merge latest version
Andre99999999 Nov 1, 2024
a80d333
Whitespace issue
Andre99999999 Nov 1, 2024
f4213a0
MGF Serializer + Spectrum list changes (Revwiew findings)
Andre99999999 Nov 6, 2024
e487769
Bugfix Build error
Andre99999999 Nov 6, 2024
73aca39
Extend MGF test with new parameters
Andre99999999 Nov 8, 2024
c18d414
Cleanup
Andre99999999 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions pwiz/data/msdata/Serializer_MGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class Serializer_MGF::Impl
void read(shared_ptr<istream> is, MSData& msd) const;
};

template <typename T>
struct nosci10_policy : boost::spirit::karma::real_policies<T>
{
// we want to generate up to 10 fractional digits
static unsigned int precision(T) { return 10; }
// we want the numbers always to be in fixed format
static int floatfield(T) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
template <typename T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert whitespace only change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I´ll fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed.

struct nosci10_policy : boost::spirit::karma::real_policies<T>
{
// we want to generate up to 10 fractional digits
static unsigned int precision(T) { return 10; }
// we want the numbers always to be in fixed format
static int floatfield(T) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
};


Expand All @@ -78,25 +78,25 @@ void Serializer_MGF::Impl::write(ostream& os, const MSData& msd,
SpectrumList& sl = *msd.run.spectrumListPtr;
SpectrumWorkerThreads spectrumWorkers(sl, useWorkerThreads, continueOnError);
for (size_t i=0, end=sl.size(); i < end; ++i)
{
SpectrumPtr s;
try
{
// s = sl->spectrum(i, true);
s = spectrumWorkers.processBatch(i);
}
catch (std::exception& e)
{
if (continueOnError)
{
{
SpectrumPtr s;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert whitespace only change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing whitespace changes here. You know how to review the diff in GitHub? You can also review it locally if you set your diff engine to show whitespace changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry, but unfortunately it's not finished yet. Yes, It's easy to see whitespace changes, but undoing them without removing other important things is a bit difficult for me. But I´m on it. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespaces should now be removed.

try
{
// s = sl->spectrum(i, true);
s = spectrumWorkers.processBatch(i);
}
catch (std::exception& e)
{
if (continueOnError)
{
cerr << "Skipping spectrum " << i << " \"" << (s ? s->id : sl.spectrumIdentity(i).id) << "\": " << e.what() << endl;
continue;
}
else
throw;
}
else
throw;
}

Scan* scan = !s->scanList.empty() ? &s->scanList.scans[0] : 0;
const Scan& scan = !s->scanList.empty() ? s->scanList.scans[0] : Scan();

if (s->cvParam(MS_ms_level).valueAs<int>() > 1 &&
!s->precursors.empty() &&
Expand All @@ -105,16 +105,16 @@ void Serializer_MGF::Impl::write(ostream& os, const MSData& msd,
os << "BEGIN IONS\n";

const SelectedIon& si = s->precursors[0].selectedIons[0];
CVParam scanTimeParam = scan ? scan->cvParam(MS_scan_start_time) : CVParam();
CVParam scanTimeParam = scan.cvParam(MS_scan_start_time);
CVParam chargeParam = si.cvParam(MS_charge_state);

CVParam spectrumTitle = s->cvParam(MS_spectrum_title);
if (!spectrumTitle.empty())
os << "TITLE=" << spectrumTitle.value << '\n';
else if (titleIsThermoDTA)
{
string scan = id::value(s->id, "scan");
os << "TITLE=" << thermoBasename << '.' << scan << '.' << scan << '.' << chargeParam.value << '\n';
string scan_string = id::value(s->id, "scan");
os << "TITLE=" << thermoBasename << '.' << scan_string << '.' << scan_string << '.' << chargeParam.value << '\n';
}
else
os << "TITLE=" << s->id << '\n';
Expand All @@ -132,6 +132,16 @@ void Serializer_MGF::Impl::write(ostream& os, const MSData& msd,
os << " " << intensityParam.valueFixedNotation();
os << '\n';

CVParam inverseReduceIonMobility = scan.cvParam(MS_inverse_reduced_ion_mobility);
if (!inverseReduceIonMobility.empty())
os << "INVREION=" << inverseReduceIonMobility.valueFixedNotation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check whether some official product already writes it this way? Because according to the official MGF spec this is not a valid parameter. https://www.matrixscience.com/help/data_file_help.html
It should be ION_MOBILITY= and it has a weird format that reproduces the PEPMASS parameter for some reason (see the link). I don't see why 1/k0 needs a separate parameter if an official one already exists. Except maybe for being sure of what kind of ion mobility is being recorded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I´ll check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope it´s done now. :-)

os << '\n';

CVParam collisionalCrossSectionalArea = scan.cvParam(MS_collisional_cross_sectional_area);
if (!collisionalCrossSectionalArea.empty())
os << "COLLCROSSSA=" << collisionalCrossSectionalArea.valueFixedNotation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no official MGF parameter for this. I would be more comfortable with this in the TITLE string, unless a Bruker product is already writing MGFs this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, Is there an example of adding some parameters to the title string?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a titleMaker filter that allows for easy customization of the MGF title string with a user-defined format. Although it doesn't support CCS currently, only instrument-level ion mobility metrics. If you don't want to use that, you can add "ccs=" to the title string above this, before the line:
if (!scanTimeParam.empty())
os << "RTINSECONDS=" << scanTimeParam.timeInSeconds() << '\n';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that sounds good, I'll implement it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be finished.

os << '\n';

if (chargeParam.empty())
{
vector<string> charges;
Expand All @@ -148,9 +158,9 @@ void Serializer_MGF::Impl::write(ostream& os, const MSData& msd,

const BinaryDataArray& mzArray = *s->getMZArray();
const BinaryDataArray& intensityArray = *s->getIntensityArray();
using namespace boost::spirit::karma;
typedef real_generator<double, nosci10_policy<double> > nosci10_type;
static const nosci10_type nosci10 = nosci10_type();
using namespace boost::spirit::karma;
typedef real_generator<double, nosci10_policy<double> > nosci10_type;
static const nosci10_type nosci10 = nosci10_type();
char buffer[256];
for (size_t p=0; p < s->defaultArrayLength; ++p)
{
Expand Down
4 changes: 2 additions & 2 deletions pwiz/data/msdata/Serializer_mzXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ struct PrecursorInfo
string collisionEnergy;
string activation;
double windowWideness;


bool empty() const
{
Expand Down Expand Up @@ -514,7 +515,6 @@ vector<PrecursorInfo> getPrecursorInfo(const Spectrum& spectrum,
return result;
}


void write_precursors(XMLWriter& xmlWriter, const vector<PrecursorInfo>& precursorInfo)
{
xmlWriter.pushStyle(XMLWriter::StyleFlag_InlineInner);
Expand All @@ -535,7 +535,7 @@ void write_precursors(XMLWriter& xmlWriter, const vector<PrecursorInfo>& precurs
attributes.add("activationMethod", it->activation);
if (it->windowWideness != 0)
attributes.add("windowWideness", it->windowWideness);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert whitespace only changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

xmlWriter.startElement("precursorMz", attributes);
xmlWriter.characters(it->mz, false);
xmlWriter.endElement();
Expand Down
10 changes: 10 additions & 0 deletions pwiz/data/msdata/SpectrumList_MGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ class SpectrumList_MGFImpl : public SpectrumList_MGF
else
selectedIon.set(MS_selected_ion_m_z, value, MS_m_z);
}
else if (name == "INVREION")
{
bal::trim(value);
scan.cvParams.push_back(CVParam(MS_inverse_reduced_ion_mobility, value, MS_volt_second_per_square_centimeter));
}
else if (name == "COLLCROSSSA")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When moving CCS to the title, it can be parsed back in the name == TITLE block above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
bal::trim(value);
scan.cvParams.push_back(CVParam(MS_collisional_cross_sectional_area, value, UO_square_angstrom));
}
else if (name == "CHARGE")
{
bal::trim_if(value, bal::is_any_of(" \t\r"));
Expand Down
1 change: 0 additions & 1 deletion pwiz/data/msdata/SpectrumList_mzXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ class HandlerScan : public SAXParser::Handler
bool getBinaryData_;
string scanNumber_;
string collisionEnergy_;
string activationMethod_;
HandlerPeaks handlerPeaks_;
HandlerPrecursor handlerPrecursor_;
CVID nativeIdFormat_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1221.992746500243" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="1"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="38916.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -268,6 +269,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1135.076451371559" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="3367.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -377,6 +379,7 @@
<selectedIonList count="1">
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1426.71440688228" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="272.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -487,6 +490,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1318.158480438941" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="693.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -597,6 +601,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1135.076451371559" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="3367.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -706,6 +711,7 @@
<selectedIonList count="1">
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1426.71440688228" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="272.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -816,6 +822,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1318.158480438941" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="693.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -926,6 +933,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1135.076451371559" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="3367.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1035,6 +1043,7 @@
<selectedIonList count="1">
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1426.71440688228" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="272.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1145,6 +1154,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1318.158480438941" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="693.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1255,6 +1265,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1135.076451371559" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="3367.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1364,6 +1375,7 @@
<selectedIonList count="1">
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1426.71440688228" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="272.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1474,6 +1486,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1318.158480438941" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="693.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down Expand Up @@ -1584,6 +1597,7 @@
<selectedIon>
<cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="1135.076451371559" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
<cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>
<cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="3367.0" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
</selectedIon>
</selectedIonList>
<activation>
Expand Down
Loading
Loading