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 24 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
27 changes: 21 additions & 6 deletions pwiz/data/msdata/Serializer_MGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void Serializer_MGF::Impl::write(ostream& os, const MSData& msd,
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,19 +105,29 @@ 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';
os << "TITLE=" << spectrumTitle.value;
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;
}
else
os << "TITLE=" << s->id << '\n';
os << "TITLE=" << s->id;

CVParam collisionalCrossSectionalArea = scan.cvParam(MS_collisional_cross_sectional_area);
if (!collisionalCrossSectionalArea.empty())
{
os << "," << "ccs=" << collisionalCrossSectionalArea.valueFixedNotation() << '\n';
}
else
{
os << '\n';
}

if (!scanTimeParam.empty())
os << "RTINSECONDS=" << scanTimeParam.timeInSeconds() << '\n';
Expand All @@ -132,6 +142,11 @@ 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 << "ION_MOBILITY=" << si.cvParam(MS_selected_ion_m_z).valueFixedNotation() << " " << inverseReduceIonMobility.valueFixedNotation();
os << '\n';

if (chargeParam.empty())
{
vector<string> charges;
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
61 changes: 60 additions & 1 deletion pwiz/data/msdata/SpectrumList_MGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ class SpectrumList_MGFImpl : public SpectrumList_MGF
if (scanTimeMin > 0)
scan.set(MS_scan_start_time, scanTimeMin * 60, UO_second);

double ccs = getCCSFromTitle(value);

if (ccs >= 0)
{
scan.cvParams.push_back(CVParam(MS_collisional_cross_sectional_area, ccs, UO_square_angstrom));
}

spectrum.set(MS_spectrum_title, value);
}
else if (name == "PEPMASS")
Expand All @@ -235,6 +242,13 @@ class SpectrumList_MGFImpl : public SpectrumList_MGF
else
selectedIon.set(MS_selected_ion_m_z, value, MS_m_z);
}
else if (name == "ION_MOBILITY")
{
bal::trim(value);
size_t delim = value.find_last_of(' ');

scan.cvParams.push_back(CVParam(MS_inverse_reduced_ion_mobility, value.substr(delim + 1, value.size() - delim - 1), MS_volt_second_per_square_centimeter));
}
else if (name == "CHARGE")
{
bal::trim_if(value, bal::is_any_of(" \t\r"));
Expand Down Expand Up @@ -330,6 +344,51 @@ class SpectrumList_MGFImpl : public SpectrumList_MGF
spectrum.set(MS_base_peak_intensity, basePeakIntensity);
}

/**
* Parse the spectrum title to look for CCS.
*/
static double getCCSFromTitle(const string& title)
{
// text to search for preceeding and following ccs
return getCCS(title, "ccs=");
}

/**
* Helper function to parse a double from the given string
* found between the two tags. Search for number after position
* Update position to the end of the parsed double.
*/
static double getCCS(const string& title, const char* startTag)
{
size_t start = title.find(startTag, 0);
if (start == string::npos)
return -1; // not found

start += strlen(startTag);
const string endTags[] = { "", " ", ",",";","\n","\r","\t" };
string ccsStr;

for(int i=0; i< sizeof(endTags)/sizeof(endTags[0]); i++)
{
const size_t end = title.find(endTags[i], start);

if(end != string::npos)
{
ccsStr = title.substr(start, end - start);
break;
}
}

try
{
return boost::lexical_cast<double>(ccsStr);
}
catch (...)
{
return 0;
}
}

/**
* Parse the spectrum title to look for retention times. If there are
* two times, return the center of the range. Possible formats to look
Expand Down Expand Up @@ -376,7 +435,7 @@ class SpectrumList_MGFImpl : public SpectrumList_MGF
* Update position to the end of the parsed double.
*/
double getTime(const string& title, const char* startTag,
const char* endTag, size_t position) const
const char* endTag, size_t& position) const
{
size_t start = title.find(startTag, position);
if( start == string::npos )
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