Skip to content

Commit

Permalink
Merge pull request #4 from poshul/fix/FLASHDeconvOnly
Browse files Browse the repository at this point in the history
Fix/flash deconv only
  • Loading branch information
JeeH-K authored Nov 9, 2022
2 parents 63a8ad2 + f4da9ff commit 411705a
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

#pragma once

#include <OpenMS/KERNEL/MSSpectrum.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS/TOPDOWN/PeakGroup.h>
#include <OpenMS/KERNEL/MSSpectrum.h>

#include <iomanip>

namespace OpenMS
Expand All @@ -63,7 +64,7 @@ namespace OpenMS
/**
@brief Constructor for DeconvolvedSpectrum. Takes the spectrum and scan number calculated from outside
@param spectrum spectrum for which the deconvolution will be performed
@param scan_number scan number of the spectrum: this argument is put here for real time case where scan number should be input separately.
@param scan_number scan number of the spectrum
*/
DeconvolvedSpectrum(const MSSpectrum& spectrum, const int scan_number);

Expand Down
23 changes: 11 additions & 12 deletions src/openms/include/OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@

#pragma once

#include <OpenMS/KERNEL/MSSpectrum.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/DATASTRUCTURES//Matrix.h>
#include <OpenMS/ANALYSIS/TOPDOWN/PeakGroup.h>
#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>
#include <iostream>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/DATASTRUCTURES/Matrix.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/KERNEL/MSSpectrum.h>

#include <boost/dynamic_bitset.hpp>
#include <iostream>

namespace OpenMS
{
Expand Down Expand Up @@ -76,11 +77,10 @@ namespace OpenMS
FLASHDeconvAlgorithm& operator=(const FLASHDeconvAlgorithm& fd) = default;

/**
@brief main deconvolution function that generates the deconvolved and decoy deconvolved spectrum from the original spectrum.
@brief main deconvolution function that generates the deconvolved target and decoy spectrum based on the original spectrum.
@param spec the original spectrum
@param survey_scans the survey scans to assign precursor mass to the deconvolved spectrum.
@param scan_number scan number is provided from input spectrum to this function in most cases.
But this parameter is used for real time deconvolution where scan number may be put separately.
@param scan_number scan number from input spectrum.
@param precursor_map_for_FLASHIda deconvolved precursor information from FLASHIda
*/
void performSpectrumDeconvolution(const MSSpectrum& spec,
Expand All @@ -94,7 +94,7 @@ namespace OpenMS
// return decoy deconvolved spectrum
//DeconvolvedSpectrum& getDecoyDeconvolvedSpectrum();

/// get calculated averagine. This should be called after calculateAveragine is called.
/// get calculated averagine. Call after calculateAveragine is called.
const PrecalculatedAveragine& getAveragine();

/// set calculated averagine
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace OpenMS

/** @brief Examine intensity distribution over isotope indices. Also determines the most plausible isotope index or, monoisotopic mono_mass
@param mono_mass monoisotopic mass
@param per_isotope_intensities per isotope intensity - aggregated through charges
@param per_isotope_intensities vector of intensities associated with each isotope - aggregated through charges
@param offset output offset between input monoisotopic mono_mass and determined monoisotopic mono_mass
@param avg precalculated averagine
@param window_width isotope offset value range. If -1, set automatically.
Expand Down Expand Up @@ -193,7 +193,6 @@ namespace OpenMS

FLASHDeconvAlgorithm* targetFD_;


/// if it is set to 0, not a decoy run. If 1, the charge decoy run, If 2, the random noise decoy run
int decoy_run_flag_ = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#pragma once

#include <OpenMS/APPLICATIONS/TOPPBase.h>
#include <OpenMS/CONCEPT/Constants.h>
#include <OpenMS/CHEMISTRY/ISOTOPEDISTRIBUTION/IsotopeDistribution.h>
#include <OpenMS/CHEMISTRY/ISOTOPEDISTRIBUTION/CoarseIsotopePatternGenerator.h>
#include <OpenMS/CHEMISTRY/ISOTOPEDISTRIBUTION/IsotopeDistribution.h>
#include <OpenMS/CONCEPT/Constants.h>
#include <OpenMS/FILTERING/DATAREDUCTION/MassTraceDetection.h>

namespace OpenMS
Expand All @@ -55,7 +55,7 @@ namespace OpenMS

struct OPENMS_DLLAPI FLASHDeconvHelperStructs
{
/// Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine calculation
/// @brief Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine calculation
class OPENMS_DLLAPI PrecalculatedAveragine
{
private:
Expand Down Expand Up @@ -172,7 +172,7 @@ namespace OpenMS
bool operator==(const TopPicItem& other) const;
};

///
/// Mass feature (Deconvolved masses in spectra are traced by Mass tracing to generate mass features - like LC-MS features).
struct OPENMS_DLLAPI MassFeature
{
public:
Expand Down
11 changes: 6 additions & 5 deletions src/openms/include/OpenMS/ANALYSIS/TOPDOWN/MassFeatureTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@

#pragma once

#include <OpenMS/FILTERING/DATAREDUCTION/MassTraceDetection.h>
#include <iostream>
#include <iomanip>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS/TOPDOWN/PeakGroup.h>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/FILTERING/DATAREDUCTION/MassTraceDetection.h>

#include <iostream>
#include <iomanip>

namespace OpenMS
{
Expand Down Expand Up @@ -76,14 +77,14 @@ namespace OpenMS

/// assignment operator
MassFeatureTrace& operator=(const MassFeatureTrace& fd) = default;
MassFeatureTrace& operator=(MassFeatureTrace&& fd) = default;

/// Obtain and store information from deconvolved_spectrum (necessary information for mass tracing afterwards)
void storeInformationFromDeconvolvedSpectrum(DeconvolvedSpectrum& deconvolved_spectrum);

/**
@brief Find mass features.
@param averagine precalculated averagine for cosine calculation
@param fst file streams for topfd output tsv, feature files
*/
std::vector<FLASHDeconvHelperStructs::MassFeature> findFeatures(const PrecalculatedAveragine& averagine);

Expand Down
7 changes: 7 additions & 0 deletions src/openms/include/OpenMS/ANALYSIS/TOPDOWN/PeakGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ namespace OpenMS
*/
void updateMonomassAndIsotopeIntensities();

/**
@brief Update isotope cosine sore and qscore
@param avg precalculated averagine
@param min_cos the peak groups with cosine score less than this will have QScore 0.
*/
void updateIsotopeCosineAndQScore(const FLASHDeconvHelperStructs::PrecalculatedAveragine& avg, double min_cos);

/// recruit peaks and then return as a spectrum.
Expand Down Expand Up @@ -161,6 +166,7 @@ namespace OpenMS
/// get charge range - the actual charge values
std::tuple<int, int> getAbsChargeRange() const;

/// get per isotope intensities
std::vector<float> getIsotopeIntensities() const;

/// get isotopic cosine score
Expand Down Expand Up @@ -249,6 +255,7 @@ namespace OpenMS

/// set per abs_charge signal power
void setChargePowers_(const int abs_charge, const float signal_pwr, const float noise_pwr, const float intensity);
/// update chargefit score and also update per charge intensities here.
void updateChargeFitScoreAndChargeIntensities_();
///update avg ppm error
void updateAvgPPMError_();
Expand Down
5 changes: 3 additions & 2 deletions src/openms/include/OpenMS/ANALYSIS/TOPDOWN/QScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

#pragma once

#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/KERNEL/Peak1D.h>
#include <OpenMS/METADATA/Precursor.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>


namespace OpenMS
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

#pragma once

#include <OpenMS/KERNEL/StandardTypes.h>
#include <OpenMS/CONCEPT/ProgressLogger.h>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/KERNEL/MassTrace.h>
#include <OpenMS/KERNEL/MSExperiment.h>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/CONCEPT/ProgressLogger.h>
#include <OpenMS/KERNEL/StandardTypes.h>

namespace OpenMS
{
Expand Down
31 changes: 8 additions & 23 deletions src/openms/include/OpenMS/FILTERING/TRANSFORMERS/SpectraMerger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
//
#pragma once

#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/COMPARISON/CLUSTERING/CompleteLinkage.h>
#include <OpenMS/COMPARISON/CLUSTERING/SingleLinkage.h>
#include <OpenMS/COMPARISON/CLUSTERING/ClusterAnalyzer.h>
#include <OpenMS/COMPARISON/CLUSTERING/ClusterHierarchical.h>
#include <OpenMS/COMPARISON/CLUSTERING/CompleteLinkage.h>
#include <OpenMS/COMPARISON/CLUSTERING/SingleLinkage.h>
#include <OpenMS/COMPARISON/SPECTRA/SpectrumAlignment.h>
#include <OpenMS/FILTERING/DATAREDUCTION/SplineInterpolatedPeaks.h>
#include <OpenMS/KERNEL/StandardTypes.h>
#include <OpenMS/KERNEL/RangeUtils.h>
#include <OpenMS/KERNEL/BaseFeature.h>
#include <OpenMS/CONCEPT/LogStream.h>
#include <OpenMS/CONCEPT/ProgressLogger.h>
#include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
#include <OpenMS/FILTERING/DATAREDUCTION/SplineInterpolatedPeaks.h>
#include <OpenMS/KERNEL/BaseFeature.h>
#include <OpenMS/KERNEL/RangeUtils.h>
#include <OpenMS/KERNEL/StandardTypes.h>

#include <vector>

namespace OpenMS
Expand Down Expand Up @@ -252,7 +253,6 @@ namespace OpenMS
DistanceMatrix<float> dist; // will be filled
ClusterHierarchical ch;

//ch.setThreshold(0.99);
// clustering ; threshold is implicitly at 1.0, i.e. distances of 1.0 (== similarity 0) will not be clustered
ch.cluster<BaseFeature, SpectraDistance_>(data, llc, sl, tree, dist);
}
Expand All @@ -275,9 +275,6 @@ namespace OpenMS
}
ca.cut(data_size - node_count, tree, clusters);

//std::cerr << "Treesize: " << (tree.size()+1) << " #clusters: " << clusters.size() << std::endl;
//std::cerr << "tree:\n" << ca.newickTree(tree, true) << "\n";

// convert to blocks
MergeBlocks spectra_to_merge;

Expand Down Expand Up @@ -629,10 +626,8 @@ namespace OpenMS
typename MapType::SpectrumType consensus_spec = exp[it->first];
consensus_spec.setMSLevel(ms_level);

//consensus_spec.unify(exp[it->first]); // append meta info
merged_indices.insert(it->first);

//typename MapType::SpectrumType all_peaks = exp[it->first];
double rt_average = consensus_spec.getRT();
double precursor_mz_average = 0.0;
Size precursor_count(0);
Expand Down Expand Up @@ -665,7 +660,6 @@ namespace OpenMS

// merge data points
sas.getSpectrumAlignment(alignment, consensus_spec, exp[*sit]);
//std::cerr << "alignment of " << it->first << " with " << *sit << " yielded " << alignment.size() << " common peaks!\n";
count_peaks_aligned += alignment.size();
count_peaks_overall += exp[*sit].size();

Expand Down Expand Up @@ -730,7 +724,6 @@ namespace OpenMS
precursor_mz_average /= precursor_count;
}
auto& pcs = consensus_spec.getPrecursors();
//if (pcs.size()>1) OPENMS_LOG_WARN << "Removing excessive precursors - leaving only one per MS2 spectrum.\n";
pcs.resize(1);
pcs[0].setMZ(precursor_mz_average);
consensus_spec.setPrecursors(pcs);
Expand Down Expand Up @@ -769,15 +762,11 @@ namespace OpenMS
}
}

//typedef std::vector<typename MapType::SpectrumType> Base;
//exp.Base::operator=(exp_tmp);
//Meta_Data will not be cleared
exp.clear(false);
exp.getSpectra().insert(exp.end(), std::make_move_iterator(exp_tmp.begin()),
std::make_move_iterator(exp_tmp.end()));

// exp.erase(remove_if(exp.begin(), exp.end(), InMSLevelRange<typename MapType::SpectrumType>(ListUtils::create<int>(String(ms_level)), false)), exp.end());

// ... and add consensus spectra
exp.getSpectra().insert(exp.end(), std::make_move_iterator(merged_spectra.begin()),
std::make_move_iterator(merged_spectra.end()));
Expand Down Expand Up @@ -873,7 +862,6 @@ namespace OpenMS
// update spectrum
typename MapType::SpectrumType average_spec = exp[it->first];
average_spec.clear(false); // Precursors are part of the meta data, which are not deleted.
//average_spec.setMSLevel(ms_level);

// refill spectrum
for (Size i = 0; i < mz_positions.size(); ++i)
Expand All @@ -892,11 +880,9 @@ namespace OpenMS

// loop over blocks
int n(0);
//typename MapType::SpectrumType empty_spec;
for (AverageBlocks::const_iterator it = spectra_to_average_over.begin(); it != spectra_to_average_over.end(); ++it)
{
exp[it->first] = exp_tmp[n];
//exp_tmp[n] = empty_spec;
++n;
}
}
Expand Down Expand Up @@ -990,7 +976,6 @@ namespace OpenMS
// update spectrum
typename MapType::SpectrumType average_spec = exp[it->first];
average_spec.clear(false); // Precursors are part of the meta data, which are not deleted.
//average_spec.setMSLevel(ms_level);

// refill spectrum
for (Size i = 0; i < mz_new.size(); ++i)
Expand Down
5 changes: 3 additions & 2 deletions src/openms/include/OpenMS/FORMAT/FLASHDeconvFeatureFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

#pragma once

#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS//TOPDOWN/PeakGroup.h>
#include <OpenMS/config.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/ANALYSIS/TOPDOWN/PeakGroup.h>

#include <iostream>
#include <iomanip>

Expand Down
4 changes: 2 additions & 2 deletions src/openms/include/OpenMS/FORMAT/FLASHDeconvSpectrumFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
// --------------------------------------------------------------------------
#pragma once

#include <OpenMS/config.h>
#include <OpenMS/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.h>
#include <OpenMS/ANALYSIS/TOPDOWN/FLASHDeconvHelperStructs.h>
#include <OpenMS/config.h>

#include <iomanip>

namespace OpenMS
Expand Down Expand Up @@ -99,7 +100,6 @@ namespace OpenMS
*/
// @param avg averagine information to calculate monoisotopic and average mass difference
static void writeTopFD(const DeconvolvedSpectrum& dspec, std::fstream& fs,
// const FLASHDeconvHelperStructs::PrecalculatedAveragine& avg,
const double snr_threshold = 1.0,
const double decoy_harmonic_factor = 1.0,
const double decoy_precursor_offset = .0);
Expand Down
3 changes: 0 additions & 3 deletions src/openms/source/ANALYSIS/TOPDOWN/DeconvolvedSpectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ namespace OpenMS
if (!precursor_peak_group_.empty() && !precursor_peak_.empty())
{
Precursor precursor(spec_.getPrecursors()[0]);
// precursor.setCharge((precursor_peak_group_.isPositive() ?
// precursor_peak_group_.getRepAbsCharge() :
// -precursor_peak_group_.getRepAbsCharge()));//getChargeMass
precursor.setCharge(to_charge);
precursor.setMZ(precursor_peak_group_.getMonoMass() + charge_mass_offset);
precursor.setIntensity(precursor_peak_group_.getIntensity());
Expand Down
Loading

0 comments on commit 411705a

Please sign in to comment.