Skip to content
43 changes: 29 additions & 14 deletions src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/MRMScoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <string>

#include <OpenMS/OPENSWATHALGO/DATASTRUCTURES/Matrix.h>
#include <OpenMS/OPENSWATHALGO/OpenSwathAlgoConfig.h>

#include "OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace OpenSwath
/// Cross Correlation array
typedef OpenSwath::Scoring::XCorrArrayType XCorrArrayType;
/// Cross Correlation matrix
typedef std::vector<std::vector<XCorrArrayType> > XCorrMatrixType;
typedef OpenMS::Matrix<XCorrArrayType> XCorrMatrixType;

typedef std::string String;

Expand Down Expand Up @@ -218,29 +219,29 @@ namespace OpenSwath
std::vector<OpenSwath::ISignalToNoisePtr>& signal_noise_estimators);

/// non-mutable access to the MI matrix
const std::vector< std::vector<double> > & getMIMatrix() const;
const OpenMS::Matrix<double> & getMIMatrix() const;
//@}

/// non-mutable access to the MI contrast matrix
const std::vector< std::vector<double> > & getMIContrastMatrix() const;
const OpenMS::Matrix<double> & getMIContrastMatrix() const;
//@}

/// non-mutable access to the MI precursor contrast matrix
const std::vector< std::vector<double> > & getMIPrecursorContrastMatrix() const;
const OpenMS::Matrix<double> & getMIPrecursorContrastMatrix() const;
//@}

/// non-mutable access to the MI precursor combined matrix
const std::vector< std::vector<double> > & getMIPrecursorCombinedMatrix() const;
const OpenMS::Matrix<double> & getMIPrecursorCombinedMatrix() const;
//@}

/// Initialize the scoring object and building the MI matrix
void initializeMIMatrix(OpenSwath::IMRMFeature* mrmfeature, std::vector<String> native_ids);
void initializeMIMatrix(OpenSwath::IMRMFeature* mrmfeature, const std::vector<String>& native_ids);

/// Initialize the scoring object and building the MI matrix of chromatograms of set1 (e.g. identification transitions) vs set2 (e.g. detection transitions)
void initializeMIContrastMatrix(OpenSwath::IMRMFeature* mrmfeature, std::vector<String> native_ids_set1, std::vector<String> native_ids_set2);
void initializeMIContrastMatrix(OpenSwath::IMRMFeature* mrmfeature, const std::vector<String>& native_ids_set1, const std::vector<String>& native_ids_set2);

/// Initialize the scoring object and building the MI matrix
void initializeMIPrecursorMatrix(OpenSwath::IMRMFeature* mrmfeature, std::vector<String> precursor_ids);
void initializeMIPrecursorMatrix(OpenSwath::IMRMFeature* mrmfeature, const std::vector<String>& precursor_ids);

/// Initialize the mutual information vector against the MS1 trace
void initializeMIPrecursorContrastMatrix(OpenSwath::IMRMFeature* mrmfeature, const std::vector<String>& precursor_ids, const std::vector<String>& native_ids);
Expand All @@ -264,36 +265,50 @@ namespace OpenSwath
/// the precomputed cross correlation matrix
XCorrMatrixType xcorr_matrix_;

/// contains max Peaks from xcorr_matrix_
OpenMS::Matrix<int> xcorr_matrix_max_peak_;
OpenMS::Matrix<double> xcorr_matrix_max_peak_sec_;
/// the precomputed contrast cross correlation
XCorrMatrixType xcorr_contrast_matrix_;
//@}

/// contains max Peaks from xcorr_contrast_matrix_
OpenMS::Matrix<int> xcorr_contrast_matrix_max_peak_;
OpenMS::Matrix<double > xcorr_contrast_matrix_max_peak_sec_;
/// the precomputed cross correlation matrix of the MS1 trace
XCorrMatrixType xcorr_precursor_matrix_;

/// contains max Peaks from xcorr_precursor_matrix_
OpenMS::Matrix<int> xcorr_precursor_matrix_max_peak_;
OpenMS::Matrix<double> xcorr_precursor_matrix_max_peak_sec_;
/// the precomputed cross correlation against the MS1 trace
XCorrMatrixType xcorr_precursor_contrast_matrix_;
//@}

/// contains max Peaks from xcorr_precursor_contrast_matrix_
OpenMS::Matrix<int> xcorr_precursor_contrast_matrix_max_peak_;
OpenMS::Matrix<double > xcorr_precursor_contrast_matrix_max_peak_sec_;
/// the precomputed cross correlation with the MS1 trace
XCorrMatrixType xcorr_precursor_combined_matrix_;
//@}

/// contains max Peaks from xcorr_precursor_combined_matrix_;
OpenMS::Matrix<int> xcorr_precursor_combined_matrix_max_peak_;
OpenMS::Matrix<double> xcorr_precursor_combined_matrix_max_peak_sec_;
/// the precomputed mutual information matrix
std::vector< std::vector<double> > mi_matrix_;

OpenMS::Matrix<double> mi_matrix_;
/// the precomputed contrast mutual information matrix
std::vector< std::vector<double> > mi_contrast_matrix_;
OpenMS::Matrix<double> mi_contrast_matrix_;

/// the precomputed mutual information matrix of the MS1 trace
std::vector< std::vector<double> > mi_precursor_matrix_;
OpenMS::Matrix<double> mi_precursor_matrix_;

/// the precomputed contrast mutual information matrix against the MS1 trace
std::vector< std::vector<double> > mi_precursor_contrast_matrix_;
OpenMS::Matrix<double> mi_precursor_contrast_matrix_;
//@}

/// the precomputed contrast mutual information matrix with the MS1 trace
std::vector< std::vector<double> > mi_precursor_combined_matrix_;
OpenMS::Matrix<double> mi_precursor_combined_matrix_;
//@}

};
Expand Down
9 changes: 6 additions & 3 deletions src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ namespace OpenSwath
/// Calculate crosscorrelation on std::vector data (which is first normalized)
/// NOTE: this replaces calcxcorr
OPENSWATHALGO_DLLAPI XCorrArrayType normalizedCrossCorrelation(std::vector<double>& data1,
std::vector<double>& data2, const int& maxdelay, const int& lag);
std::vector<double>& data2, const int maxdelay, const int lag);

/// Calculate crosscorrelation on std::vector data without normalization
OPENSWATHALGO_DLLAPI XCorrArrayType calculateCrossCorrelation(const std::vector<double>& data1,
const std::vector<double>& data2, const int& maxdelay, const int& lag);
const std::vector<double>& data2, const int maxdelay, const int lag);

/// Find best peak in an cross-correlation (highest apex)
OPENSWATHALGO_DLLAPI XCorrArrayType::const_iterator xcorrArrayGetMaxPeak(const XCorrArrayType & array);
Expand All @@ -131,11 +131,14 @@ namespace OpenSwath
OPENSWATHALGO_DLLAPI void normalize_sum(double x[], unsigned int n);

// Compute rank of vector elements
OPENSWATHALGO_DLLAPI std::vector<unsigned int> computeRank(const std::vector<double>& w);
OPENSWATHALGO_DLLAPI void computeRank(const std::vector<double>& v_temp, std::vector<unsigned int>& result);

// Estimate rank-transformed mutual information between two vectors of data points
OPENSWATHALGO_DLLAPI double rankedMutualInformation(std::vector<double>& data1, std::vector<double>& data2);

// Estimate rank-transformed mutual information between two vectors of rank
OPENSWATHALGO_DLLAPI double preCalcRankedMutualInformation(std::vector<unsigned int>& rank_vector1, std::vector<unsigned int>& rank_vector2);

//@}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2021.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Timo Sachsenberg $
// $Authors: $
// --------------------------------------------------------------------------

#include <OPENSWATHALGO/DATASTRUCTURES/Matrix.h>

namespace OpenMS
{
Matrix<int> default_matrix_int;
Matrix<double> default_matrix_double;
}
Loading