Skip to content

Feature/auto add up new #4

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

Open
wants to merge 10 commits into
base: feature/oswSpeedUp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace OpenMS

std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const override;

std::vector<std::size_t> getSpectraRTRange(double rt_start, double rt_end) const override;

size_t getNrSpectra() const override;

SpectrumSettings getSpectraMetaInfo(int id) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace OpenMS

std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const override;

std::vector<std::size_t> getSpectraRTRange(double rt_start, double rt_end) const override;

size_t getNrSpectra() const override;

SpectrumSettings getSpectraMetaInfo(int id) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ namespace OpenMS
{
/**
* @brief An implementation of the OpenSWATH Spectrum Access interface completely in memory
*
*
* This implementation of the spectrum access interface ensures that all data
* is held completely in memory and is quickly accessible. This class can be
* generated by passing any object implementing the Spectrum Access interface
* and guarantees to provide the same access to the raw data as the original
* object with the added benefits (and downside) of keeping all data in system
* memory.
*
*
* A possible example
*
*
* @code
* OpenSwath::ISpectrumAccess * data_access;
* fillData(data_access); // assume that data_access points to some data
Expand Down Expand Up @@ -70,6 +70,8 @@ namespace OpenMS

std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const override;

std::vector<std::size_t> getSpectraRTRange(double rt_start, double rt_end) const override;

size_t getNrSpectra() const override;

OpenSwath::ChromatogramPtr getChromatogramById(int id) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace OpenMS

std::vector<std::size_t> getSpectraByRT(double /* RT */, double /* deltaRT */) const override;

std::vector<std::size_t> getSpectraRTRange(double /* rt_start */, double /* rt_end */) const override;

size_t getNrSpectra() const override;

OpenSwath::ChromatogramPtr getChromatogramById(int /* id */) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenMS
public:

explicit SpectrumAccessTransforming(OpenSwath::SpectrumAccessPtr sptr);

~SpectrumAccessTransforming() override = 0;

boost::shared_ptr<ISpectrumAccess> lightClone() const override = 0;
Expand All @@ -35,6 +35,8 @@ namespace OpenMS

std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const override;

std::vector<std::size_t> getSpectraRTRange(double rt_start, double rt_end) const override;

size_t getNrSpectra() const override;

OpenSwath::ChromatogramPtr getChromatogramById(int id) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ namespace OpenMS
double dotprod_score_dia = 0;
double manhatt_score_dia = 0;

int numSpectraAdd = 1; // num spectra that are summed up when computing DIA scores

OpenSwath_Scores() = default;

double get_quick_lda_score(double library_corr_,
Expand Down
16 changes: 8 additions & 8 deletions src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathScoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class RangeMZ;
class RangeMobility;
class RangeRT;

namespace OpenMS
{
Expand Down Expand Up @@ -169,6 +170,7 @@ namespace OpenMS
* @param mzerror_ppm m/z and mass error (in ppm) for all transitions
* @param[in] drift_target target drift value
* @param[in] range_im drift time lower and upper bounds
* @param[in] range_rt retention time lower and upper bounds
*
*/
void calculateDIAScores(OpenSwath::IMRMFeature* imrmfeature,
Expand All @@ -180,7 +182,8 @@ namespace OpenMS
OpenSwath_Scores& scores,
std::vector<double>& mzerror_ppm,
const double drift_target,
const RangeMobility& range_im);
const RangeMobility& range_im,
const RangeRT& range_rt);

/** @brief Score a single chromatographic feature using the precursor map.
*
Expand Down Expand Up @@ -286,17 +289,14 @@ namespace OpenMS
*/
SpectrumSequence fetchSpectrumSwath(OpenSwath::SpectrumAccessPtr swath_map, double RT, int nr_spectra_to_add, const RangeMobility& im_range);


protected:

/** @breif converts a ion mobility enhanced spectrum to a non ion mobility spectrum by filtering by drift time
/** @breif similar to fetchSpectrumSwath() however select spectra across entire rt range of the feature
*/
OpenSwath::SpectrumPtr filterByDrift_(const OpenSwath::SpectrumPtr& input, const RangeMobility& range_im);
SpectrumSequence fetchSpectrumSwathAuto(OpenSwath::SpectrumAccessPtr swathmap, const RangeMobility& im_range, const RangeRT& rt_range);


/** @breif Adds up an array of spectrum into one spectrum. If the spectra are ion mobility enhanced, first filter by drift time and then add up spectra
/** @breif similar to fetchSpectrumSwath() however select spectra across entire rt range of the feature
*/
OpenSwath::SpectrumPtr getAddedSpectra_(std::vector<OpenSwath::SpectrumPtr>&, const RangeMobility& range_im);
SpectrumSequence fetchSpectrumSwathAuto(std::vector<OpenSwath::SwathMap> swath_maps, const RangeMobility& im_range, const RangeRT& rt_range);

};
}
Expand Down
2 changes: 2 additions & 0 deletions src/openms/include/OpenMS/INTERFACES/ISpectrumAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Interfaces
virtual SpectrumPtr getSpectrumById(const std::string& id) const = 0;
/// Return a vector of ids of spectra that are within RT +/- deltaRT
virtual std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const = 0;
/// Return a vector of ids of spectra between rt_start and rt_end
virtual std::vector<std::size_t> getSpectraRTRange(double rt_start, double rt_end) const = 0;
/// Returns the number of spectra available
virtual size_t getNrSpectra() const = 0;
/// Returns the meta information for a spectrum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace OpenMS
SpectrumAccessOpenMS::SpectrumAccessOpenMS(const SpectrumAccessOpenMS & rhs) :
ms_experiment_(rhs.ms_experiment_)
{
// this only copies the pointers and not the actual data ...
// this only copies the pointers and not the actual data ...
}


Expand Down Expand Up @@ -159,6 +159,25 @@ namespace OpenMS
return result;
}

std::vector<std::size_t> SpectrumAccessOpenMS::getSpectraRTRange(double rt_start, double rt_end) const
{

// Start at the rt_start
std::vector<std::size_t> result;
auto spectrum = ms_experiment_->RTBegin(rt_start);
if (spectrum == ms_experiment_->end()) return result;

result.push_back(std::distance(ms_experiment_->begin(), spectrum));
spectrum++;

while (spectrum != ms_experiment_->end() && spectrum->getRT() <= rt_end)
{
result.push_back(spectrum - ms_experiment_->begin());
spectrum++;
}
return result;
}

size_t SpectrumAccessOpenMS::getNrChromatograms() const
{
return ms_experiment_->getChromatograms().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ namespace OpenMS
return result;
}

std::vector<std::size_t> SpectrumAccessOpenMSCached::getSpectraRTRange(double rt_start, double rt_end) const
{
std::vector<std::size_t> result;
auto spectrum = meta_ms_experiment_.RTBegin(rt_start);
if (spectrum == meta_ms_experiment_.end()) return result;

result.push_back(std::distance(meta_ms_experiment_.begin(), spectrum));
spectrum++;

while (spectrum != meta_ms_experiment_.end() && spectrum->getRT() < rt_end)
{
result.push_back(spectrum - meta_ms_experiment_.begin());
spectrum++;
}
return result;
}

size_t SpectrumAccessOpenMSCached::getNrSpectra() const
{
return meta_ms_experiment_.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace OpenMS
chromatograms_(rhs.chromatograms_),
chromatogram_ids_(rhs.chromatogram_ids_)
{
// this only copies the pointers and not the actual data ...
// this only copies the pointers and not the actual data ...
}

boost::shared_ptr<OpenSwath::ISpectrumAccess> SpectrumAccessOpenMSInMemory::lightClone() const
Expand Down Expand Up @@ -93,6 +93,25 @@ namespace OpenMS
return result;
}

std::vector<std::size_t> SpectrumAccessOpenMSInMemory::getSpectraRTRange(double rt_start, double rt_end) const
{

std::vector<std::size_t> result;
OpenSwath::SpectrumMeta s;
s.RT = rt_start;
auto spectrum = std::lower_bound(spectra_meta_.begin(), spectra_meta_.end(), s, OpenSwath::SpectrumMeta::RTLess());
if (spectrum == spectra_meta_.end()) return result;

result.push_back(std::distance(spectra_meta_.begin(), spectrum));
++spectrum;
while ( spectrum != spectra_meta_.end() && spectrum->RT < rt_end)
{
result.push_back(std::distance(spectra_meta_.begin(), spectrum));
++spectrum;
}
return result;
}

size_t SpectrumAccessOpenMSInMemory::getNrSpectra() const
{
OPENMS_PRECONDITION(spectra_.size() == spectra_meta_.size(), "Spectra and meta data needs to match")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace OpenMS
}
spectra.reserve(tmp_spectra.size());
spectra_meta.reserve(tmp_spectra.size());

for (Size k = 0; k < tmp_spectra.size(); k++)
{
const MSSpectrumType& spectrum = tmp_spectra[k];
Expand Down Expand Up @@ -187,6 +187,11 @@ namespace OpenMS
}
}

std::vector<std::size_t> SpectrumAccessSqMass::getSpectraRTRange(double rt_start, double rt_end) const
{
throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
}

size_t SpectrumAccessSqMass::getNrSpectra() const
{
size_t res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ namespace OpenMS
return sptr_->getSpectraByRT(RT, deltaRT);
}

std::vector<std::size_t> SpectrumAccessTransforming::getSpectraRTRange(double rt_start, double rt_end) const
{
return sptr_->getSpectraRTRange(rt_start, rt_end);
}

size_t SpectrumAccessTransforming::getNrSpectra() const
{
return sptr_->getNrSpectra();
Expand Down
15 changes: 10 additions & 5 deletions src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ namespace OpenMS
defaults_.setValidStrings("write_convex_hull", {"true","false"});
defaults_.setValue("spectrum_addition_method", "simple", "For spectrum addition, either use simple concatenation or use peak resampling", {"advanced"});
defaults_.setValidStrings("spectrum_addition_method", {"simple", "resample"});
defaults_.setValue("add_up_spectra", 1, "Add up spectra around the peak apex (needs to be a non-even integer)", {"advanced"});
defaults_.setMinInt("add_up_spectra", 1);
defaults_.setValue("add_up_spectra", 1, "Add up spectra around the peak apex (needs to be a non-even integer), if set to -1 all spectra across peak width are summed", {"advanced"});
//defaults_.setMinInt("add_up_spectra", 1);
defaults_.setValue("spacing_for_spectra_resampling", 0.005, "If spectra are to be added, use this spacing to add them up", {"advanced"});
defaults_.setMinFloat("spacing_for_spectra_resampling", 0.0);
defaults_.setValue("uis_threshold_sn", -1, "S/N threshold to consider identification transition (set to -1 to consider all)");
Expand Down Expand Up @@ -169,7 +169,7 @@ namespace OpenMS
void MRMFeatureFinderScoring::pickExperiment(const OpenSwath::SpectrumAccessPtr& input,
FeatureMap& output,
const OpenSwath::LightTargetedExperiment& transition_exp,
const TransformationDescription& trafo,
const TransformationDescription& trafo,
const std::vector<OpenSwath::SwathMap>& swath_maps,
TransitionGroupMapType& transition_group_map)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace OpenMS
{
MRMFeature idmrmfeature = trgr_ident.getFeaturesMuteable()[feature_idx];
OpenSwath::IMRMFeature* idimrmfeature;
idimrmfeature = new MRMFeatureOpenMS(idmrmfeature);
idimrmfeature = new MRMFeatureOpenMS(idmrmfeature);

// get drift time upper/lower offset (this assumes that all chromatograms
// are derived from the same precursor with the same drift time)
Expand Down Expand Up @@ -549,6 +549,9 @@ namespace OpenMS
for (SignedSize feature_idx = 0; feature_idx < (SignedSize) mrmfeatures.size(); ++feature_idx)
{
auto& mrmfeature = mrmfeatures[feature_idx];

RangeRT rt_range(mrmfeature.getMetaValue("leftWidth"), mrmfeature.getMetaValue("rightWidth"));

OpenSwath::IMRMFeature* imrmfeature;
imrmfeature = new MRMFeatureOpenMS(mrmfeature);

Expand Down Expand Up @@ -686,7 +689,7 @@ namespace OpenMS
scorer.calculateDIAScores(imrmfeature,
transition_group_detection.getTransitions(),
swath_maps, ms1_map_, diascoring_, *pep, scores, masserror_ppm,
drift_target, im_range);
drift_target, im_range, rt_range);
mrmfeature.setMetaValue("masserror_ppm", masserror_ppm);
}
if (sonar_present && su_.use_sonar_scores)
Expand Down Expand Up @@ -826,6 +829,8 @@ namespace OpenMS
// Add the DIA / SWATH scores, ion mobility scores and SONAR scores
if (swath_present && su_.use_dia_scores_)
{
mrmfeature.addScore("num_spectra_add", scores.numSpectraAdd);

if (su_.use_ms2_isotope_scores)
{
mrmfeature.addScore("var_isotope_correlation_score", scores.isotope_correlation);
Expand Down
4 changes: 3 additions & 1 deletion src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace OpenMS
"EXP_IM REAL," \
"DELTA_IM REAL," \
"TOTAL_MI REAL NULL," \
"NUM_SPEC_ADD INT NULL," \
"VAR_BSERIES_SCORE REAL NULL," \
"VAR_DOTPROD_SCORE REAL NULL," \
"VAR_INTENSITY_SCORE REAL NULL," \
Expand Down Expand Up @@ -258,7 +259,7 @@ namespace OpenMS
<< feature_it.getMetaValue("rightWidth") << "); ";

sql_feature_ms2 << "INSERT INTO FEATURE_MS2 " \
"(FEATURE_ID, AREA_INTENSITY, TOTAL_AREA_INTENSITY, APEX_INTENSITY, EXP_IM, DELTA_IM, TOTAL_MI, "\
"(FEATURE_ID, AREA_INTENSITY, TOTAL_AREA_INTENSITY, APEX_INTENSITY, EXP_IM, DELTA_IM, TOTAL_MI, NUM_SPEC_ADD," \
"VAR_BSERIES_SCORE, VAR_DOTPROD_SCORE, VAR_INTENSITY_SCORE, " \
"VAR_ISOTOPE_CORRELATION_SCORE, VAR_ISOTOPE_OVERLAP_SCORE, VAR_LIBRARY_CORR, "\
"VAR_LIBRARY_DOTPROD, VAR_LIBRARY_MANHATTAN, VAR_LIBRARY_RMSD, VAR_LIBRARY_ROOTMEANSQUARE, "\
Expand All @@ -276,6 +277,7 @@ namespace OpenMS
<< getScore(feature_it, "im_drift") << ", "
<< getScore(feature_it, "im_delta") << ", "
<< getScore(feature_it, "total_mi") << ", "
<< getScore(feature_it, "num_spectra_add") << ", "
<< getScore(feature_it, "var_bseries_score") << ", "
<< getScore(feature_it, "var_dotprod_score") << ", "
<< getScore(feature_it, "var_intensity_score") << ", "
Expand Down
Loading