Search in sources :

Example 6 with SpectralSimilarity

use of net.sf.mzmine.util.scans.similarity.SpectralSimilarity in project mzmine2 by mzmine.

the class WeightedCosineSpectralSimilarity method getSimilarity.

/**
 * Returns mass and intensity values detected in given scan
 */
@Override
public SpectralSimilarity getSimilarity(ParameterSet parameters, MZTolerance mzTol, int minMatch, DataPoint[] library, DataPoint[] query) {
    Weights weights = parameters.getParameter(WeightedCosineSpectralSimilarityParameters.weight).getValue();
    double minCos = parameters.getParameter(WeightedCosineSpectralSimilarityParameters.minCosine).getValue();
    boolean removeUnmatched = parameters.getParameter(WeightedCosineSpectralSimilarityParameters.removeUnmatched).getValue();
    // align
    List<DataPoint[]> aligned = alignDataPoints(mzTol, library, query);
    // removes all signals which were not found in both masslists
    if (removeUnmatched)
        aligned = removeUnaligned(aligned);
    // overlapping within mass tolerance
    int overlap = calcOverlap(aligned);
    if (overlap >= minMatch) {
        // weighted cosine
        double[][] diffArray = ScanAlignment.toIntensityMatrixWeighted(aligned, weights.getIntensity(), weights.getMz());
        double diffCosine = Similarity.COSINE.calc(diffArray);
        if (diffCosine >= minCos)
            return new SpectralSimilarity(getName(), diffCosine, overlap, library, query, aligned);
        else
            return null;
    }
    return null;
}
Also used : Weights(net.sf.mzmine.util.scans.similarity.Weights) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)6 SpectralSimilarity (net.sf.mzmine.util.scans.similarity.SpectralSimilarity)6 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 MissingMassListException (net.sf.mzmine.util.exceptions.MissingMassListException)2 Weights (net.sf.mzmine.util.scans.similarity.Weights)2 SpectralDBEntry (net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)2 SpectralDBPeakIdentity (net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity)2 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 TreeSet (java.util.TreeSet)1 Vector (java.util.Vector)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)1 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)1 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)1 ParameterSet (net.sf.mzmine.parameters.ParameterSet)1