Search in sources :

Example 96 with DataPoint

use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.

the class ScanUtils method findMzRange.

/**
 * Find the m/z range of the data points in the array. We assume there is at least one data point,
 * and the data points are sorted by m/z.
 */
@Nonnull
public static Range<Double> findMzRange(@Nonnull DataPoint[] dataPoints) {
    assert dataPoints.length > 0;
    double lowMz = dataPoints[0].getMZ();
    double highMz = lowMz;
    for (int i = 1; i < dataPoints.length; i++) {
        if (dataPoints[i].getMZ() < lowMz) {
            lowMz = dataPoints[i].getMZ();
            continue;
        }
        if (dataPoints[i].getMZ() > highMz)
            highMz = dataPoints[i].getMZ();
    }
    return Range.closed(lowMz, highMz);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nonnull(javax.annotation.Nonnull)

Example 97 with DataPoint

use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.

the class ScanUtils method findBasePeak.

/**
 * Find a base peak of a given scan in a given m/z range
 *
 * @param scan Scan to search
 * @param mzRange mz range to search in
 * @return double[2] containing base peak m/z and intensity
 */
@Nonnull
public static DataPoint findBasePeak(@Nonnull Scan scan, @Nonnull Range<Double> mzRange) {
    DataPoint[] dataPoints = scan.getDataPointsByMass(mzRange);
    DataPoint basePeak = null;
    for (DataPoint dp : dataPoints) {
        if ((basePeak == null) || (dp.getIntensity() > basePeak.getIntensity()))
            basePeak = dp;
    }
    return basePeak;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nonnull(javax.annotation.Nonnull)

Example 98 with DataPoint

use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.

the class ScanUtils method encodeDataPointsToBytes.

public static byte[] encodeDataPointsToBytes(DataPoint[] dataPoints) {
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    DataOutputStream peakStream = new DataOutputStream(byteStream);
    for (int i = 0; i < dataPoints.length; i++) {
        try {
            peakStream.writeDouble(dataPoints[i].getMZ());
            peakStream.writeDouble(dataPoints[i].getIntensity());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    byte[] peakBytes = byteStream.toByteArray();
    return peakBytes;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 99 with DataPoint

use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.

the class ScanUtils method probabilityProductUnnormalized.

/**
 * Calculates the probability product without normalization. Usually, this method is only useful
 * if you plan to normalize the spectra (or value) yourself.
 *
 * @see #probabilityProduct(DataPoint[], DataPoint[], MZTolerance, double, Range)
 */
public static double probabilityProductUnnormalized(DataPoint[] scanLeft, DataPoint[] scanRight, MZTolerance expectedMassDeviationInPPM, double noiseLevel, @Nullable Range<Double> mzRange) {
    int i, j;
    double score = 0d;
    // =left.length, nr=right.length;
    final int nl, nr;
    if (mzRange == null) {
        nl = scanLeft.length;
        nr = scanRight.length;
        i = 0;
        j = 0;
    } else {
        nl = findLastPeakWithin(scanLeft, mzRange) + 1;
        nr = findLastPeakWithin(scanRight, mzRange) + 1;
        i = findFirstPeakWithin(scanLeft, mzRange);
        j = findFirstPeakWithin(scanRight, mzRange);
        if (i < 0 || j < 0)
            return 0d;
    }
    // gaussians are set to zero above allowedDifference to speed up computation
    final double allowedDifference = expectedMassDeviationInPPM.getMzToleranceForMass(1000d) * 5;
    while (i < nl && j < nr) {
        DataPoint lp = scanLeft[i];
        if (lp.getIntensity() < noiseLevel) {
            ++i;
            continue;
        }
        DataPoint rp = scanRight[j];
        if (rp.getIntensity() < noiseLevel) {
            ++j;
            continue;
        }
        final double difference = lp.getMZ() - rp.getMZ();
        if (Math.abs(difference) <= allowedDifference) {
            final double mzabs = expectedMassDeviationInPPM.getMzToleranceForMass(Math.round((lp.getMZ() + rp.getMZ()) / 2d));
            final double variance = mzabs * mzabs;
            double matchScore = probabilityProductScore(lp, rp, variance);
            score += matchScore;
            for (int k = i + 1; k < nl; ++k) {
                DataPoint lp2 = scanLeft[k];
                final double difference2 = lp2.getMZ() - rp.getMZ();
                if (Math.abs(difference2) <= allowedDifference) {
                    matchScore = probabilityProductScore(lp2, rp, variance);
                    score += matchScore;
                } else
                    break;
            }
            for (int l = j + 1; l < nr; ++l) {
                DataPoint rp2 = scanRight[l];
                final double difference2 = lp.getMZ() - rp2.getMZ();
                if (Math.abs(difference2) <= allowedDifference) {
                    matchScore = probabilityProductScore(lp, rp2, variance);
                    score += matchScore;
                } else
                    break;
            }
            ++i;
            ++j;
        } else if (difference > 0) {
            ++j;
        } else {
            ++i;
        }
    }
    return score;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 100 with DataPoint

use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.

the class CompositeCosineSpectralSimilarity method calcRelativeNeighbourFactor.

/**
 * sum of relative ratios of neighbours in both mass lists
 *
 * @param aligned
 * @return
 */
private double calcRelativeNeighbourFactor(List<DataPoint[]> aligned) {
    // remove all unaligned signals
    List<DataPoint[]> filtered = removeUnaligned(aligned);
    // sort by mz
    sortByMZ(filtered);
    // overlapping within mass tolerance
    int overlap = calcOverlap(aligned);
    // sum of relative ratios of neighbours in both mass lists
    double factor = 0;
    for (int i = 1; i < filtered.size(); i++) {
        DataPoint[] match1 = filtered.get(i - 1);
        DataPoint[] match2 = filtered.get(i);
        // 0 is library
        // 1 is query
        double ratioLibrary = match2[0].getIntensity() / match1[0].getIntensity();
        double ratioQuery = match2[1].getIntensity() / match1[1].getIntensity();
        factor += Math.min(ratioLibrary, ratioQuery) / Math.max(ratioLibrary, ratioQuery);
    }
    // factor ranges from 0-1 * overlap
    return factor / (overlap);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)214 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)98 Scan (net.sf.mzmine.datamodel.Scan)64 ArrayList (java.util.ArrayList)50 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)44 Feature (net.sf.mzmine.datamodel.Feature)27 MassList (net.sf.mzmine.datamodel.MassList)24 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)22 IOException (java.io.IOException)20 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)18 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)17 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)16 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)15 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)15 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)12 DataPointSorter (net.sf.mzmine.util.DataPointSorter)12 HashMap (java.util.HashMap)10 Vector (java.util.Vector)10 Range (com.google.common.collect.Range)8 TreeMap (java.util.TreeMap)8