Search in sources :

Example 16 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class ResolvedPeak method getDataPoint.

/**
 * This method returns a representative datapoint of this peak in a given scan
 */
@Override
public DataPoint getDataPoint(int scanNumber) {
    int index = Arrays.binarySearch(scanNumbers, scanNumber);
    if (index < 0)
        return null;
    SimpleDataPoint dp = new SimpleDataPoint(dataPointMZValues[index], dataPointIntensityValues[index]);
    return dp;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 17 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class MascotParserUtils method parseScanIons.

/**
 * Parse the information of data points (MS/MS peaks) and generate a new PeptideScan
 *
 * @param queryNumber
 * @param HashMap sectionMap with the data points info
 * @param pepDataFile
 * @return
 */
public static PeptideScan parseScanIons(int queryNumber, HashMap<?, ?> sectionMap, PeptideIdentityDataFile pepDataFile) {
    String titleScan = (String) sectionMap.get("title");
    titleScan = titleScan.replace("%2e", ",");
    String[] tokens = titleScan.split(",");
    String rawFileName = tokens[0];
    int rawScanNumber = Integer.parseInt(tokens[1]);
    PeptideScan scan = new PeptideScan(pepDataFile, rawFileName, queryNumber, rawScanNumber);
    Vector<SimpleDataPoint> dataPoints = new Vector<SimpleDataPoint>();
    double mass, intensity;
    String ions = (String) sectionMap.get("Ions1");
    StringTokenizer tokenizer = new StringTokenizer(ions, ",");
    while (tokenizer.hasMoreTokens()) {
        tokens = tokenizer.nextToken().split(":");
        mass = Double.parseDouble(tokens[0]);
        intensity = Double.parseDouble(tokens[1]);
        dataPoints.add(new SimpleDataPoint(mass, intensity));
    }
    scan.setDataPoints(dataPoints.toArray(new SimpleDataPoint[0]));
    return scan;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) StringTokenizer(java.util.StringTokenizer) PeptideScan(net.sf.mzmine.modules.peaklistmethods.identification.mascot.data.PeptideScan) Vector(java.util.Vector) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 18 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class IsotopePatternUtils method checkOverlappingIsotopes.

public static IsotopePattern checkOverlappingIsotopes(IsotopePattern pattern, IIsotope[] isotopes, double mergeWidth, double minAbundance) {
    DataPoint[] dp = pattern.getDataPoints();
    double basemz = dp[0].getMZ();
    List<DataPoint> newPeaks = new ArrayList<DataPoint>();
    double isotopeBaseMass = 0d;
    for (IIsotope isotope : isotopes) {
        if (isotope.getNaturalAbundance() > minAbundance) {
            isotopeBaseMass = isotope.getExactMass();
            logger.info("isotopeBaseMass of " + isotope.getSymbol() + " = " + isotopeBaseMass);
            break;
        }
    }
    // loop all new isotopes
    for (IIsotope isotope : isotopes) {
        if (isotope.getNaturalAbundance() < minAbundance)
            continue;
        // the difference added by the heavier isotope peak
        double possiblemzdiff = isotope.getExactMass() - isotopeBaseMass;
        if (possiblemzdiff < 0.000001)
            continue;
        boolean add = true;
        for (DataPoint patternDataPoint : dp) {
            // here check for every peak in the pattern, if a new peak would overlap
            // if it overlaps good, we dont need to add a new peak
            int i = 1;
            do {
                if (Math.abs(patternDataPoint.getMZ() * i - possiblemzdiff) <= mergeWidth) {
                    // TODO: maybe we should do a average of the masses? i can'T say if it makes sense,
                    // since
                    // we're just looking for isotope mass differences and dont look at the total
                    // composition,
                    // so we dont know the intensity ratios
                    logger.info("possible overlap found: " + i + " * pattern dp = " + patternDataPoint.getMZ() + "\toverlaps with " + isotope.getMassNumber() + isotope.getSymbol() + " (" + (isotopeBaseMass - isotope.getExactMass()) + ")\tdiff: " + Math.abs(patternDataPoint.getMZ() * i - possiblemzdiff));
                    add = false;
                }
                i++;
            // logger.info("do");
            } while (patternDataPoint.getMZ() * i <= possiblemzdiff + mergeWidth && patternDataPoint.getMZ() != 0.0);
        }
        if (add)
            newPeaks.add(new SimpleDataPoint(possiblemzdiff, 1));
    }
    // DataPoint[] newDataPoints = new SimpleDataPoint[dp.length + newPeaks.size()];
    for (DataPoint p : dp) {
        newPeaks.add(p);
    }
    newPeaks.sort((o1, o2) -> {
        return Double.compare(o1.getMZ(), o2.getMZ());
    });
    return new SimpleIsotopePattern(newPeaks.toArray(new DataPoint[0]), IsotopePatternStatus.PREDICTED, "");
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ArrayList(java.util.ArrayList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 19 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class SameRangeTask method fillGap.

private Feature fillGap(PeakListRow row, RawDataFile column) {
    SameRangePeak newPeak = new SameRangePeak(column);
    Range<Double> mzRange = null, rtRange = null;
    // Check the peaks for selected data files
    for (RawDataFile dataFile : row.getRawDataFiles()) {
        Feature peak = row.getPeak(dataFile);
        if (peak == null)
            continue;
        if ((mzRange == null) || (rtRange == null)) {
            mzRange = peak.getRawDataPointsMZRange();
            rtRange = peak.getRawDataPointsRTRange();
        } else {
            mzRange = mzRange.span(peak.getRawDataPointsMZRange());
            rtRange = rtRange.span(peak.getRawDataPointsRTRange());
        }
    }
    assert mzRange != null;
    assert rtRange != null;
    Range<Double> mzRangeWithTol = mzTolerance.getToleranceRange(mzRange);
    // Get scan numbers
    int[] scanNumbers = column.getScanNumbers(1, rtRange);
    boolean dataPointFound = false;
    for (int scanNumber : scanNumbers) {
        if (isCanceled())
            return null;
        // Get next scan
        Scan scan = column.getScan(scanNumber);
        // Find most intense m/z peak
        DataPoint basePeak = ScanUtils.findBasePeak(scan, mzRangeWithTol);
        if (basePeak != null) {
            if (basePeak.getIntensity() > 0)
                dataPointFound = true;
            newPeak.addDatapoint(scan.getScanNumber(), basePeak);
        } else {
            DataPoint fakeDataPoint = new SimpleDataPoint(RangeUtils.rangeCenter(mzRangeWithTol), 0);
            newPeak.addDatapoint(scan.getScanNumber(), fakeDataPoint);
        }
    }
    if (dataPointFound) {
        newPeak.finalizePeak();
        if (newPeak.getArea() == 0)
            return null;
        return newPeak;
    }
    return null;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 20 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class CameraSearchTask method groupPeaksByIsotope.

/**
 * Uses Isotope-field in PeakIdentity to group isotopes and build spectrum
 *
 * @param peakList PeakList object
 * @return new PeakList object
 */
private PeakList groupPeaksByIsotope(PeakList peakList) {
    // Create new feature list.
    final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
    // Load previous applied methods.
    for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        combinedPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
    // ------------------------------------------------
    // Find unique isotopes belonging to the same group
    // ------------------------------------------------
    Set<String> isotopeGroups = new HashSet<>();
    for (PeakListRow row : peakList.getRows()) {
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        String isotope = identity.getPropertyValue("Isotope");
        if (isotope == null)
            continue;
        String isotopeGroup = isotope.substring(1, isotope.indexOf("]"));
        if (isotopeGroup == null || isotopeGroup.length() == 0)
            continue;
        isotopeGroups.add(isotopeGroup);
    }
    List<PeakListRow> groupRows = new ArrayList<>();
    Set<String> groupNames = new HashSet<>();
    Map<Double, Double> spectrum = new HashMap<>();
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    for (String isotopeGroup : isotopeGroups) {
        // -----------------------------------------
        // Find all peaks belonging to isotopeGroups
        // -----------------------------------------
        groupRows.clear();
        groupNames.clear();
        spectrum.clear();
        int minLength = Integer.MAX_VALUE;
        PeakListRow groupRow = null;
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String isotope = identity.getPropertyValue("Isotope");
            if (isotope == null)
                continue;
            String isoGroup = isotope.substring(1, isotope.indexOf("]"));
            if (isoGroup == null)
                continue;
            if (isoGroup.equals(isotopeGroup)) {
                groupRows.add(row);
                groupNames.add(identity.getName());
                spectrum.put(row.getAverageMZ(), row.getAverageHeight());
                if (isoGroup.length() < minLength) {
                    minLength = isoGroup.length();
                    groupRow = row;
                }
            }
        }
        // Skip peaks that have different identity names (belong to different pcgroup)
        if (groupRow == null || groupNames.size() != 1)
            continue;
        if (groupRow == null)
            continue;
        PeakIdentity identity = groupRow.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        DataPoint[] dataPoints = new DataPoint[spectrum.size()];
        int count = 0;
        for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
        IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
        groupRow.getBestPeak().setIsotopePattern(pattern);
        // combinedPeakList.addRow(groupRow);
        newPeakListRows.add(groupRow);
    }
    if (includeSingletons) {
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String isotope = identity.getPropertyValue("Isotope");
            if (isotope == null || isotope.length() == 0) {
                DataPoint[] dataPoints = new DataPoint[1];
                dataPoints[0] = new SimpleDataPoint(row.getAverageMZ(), row.getAverageHeight());
                IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
                row.getBestPeak().setIsotopePattern(pattern);
                newPeakListRows.add(row);
            }
        }
    }
    // ------------------------------------
    // Sort new peak rows by retention time
    // ------------------------------------
    Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {

        @Override
        public int compare(PeakListRow row1, PeakListRow row2) {
            double retTime1 = row1.getAverageRT();
            double retTime2 = row2.getAverageRT();
            return Double.compare(retTime1, retTime2);
        }
    });
    for (PeakListRow row : newPeakListRows) combinedPeakList.addRow(row);
    return combinedPeakList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashSet(java.util.HashSet)

Aggregations

SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)58 DataPoint (net.sf.mzmine.datamodel.DataPoint)56 Scan (net.sf.mzmine.datamodel.Scan)15 ArrayList (java.util.ArrayList)13 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)13 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)12 IOException (java.io.IOException)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)10 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)10 Feature (net.sf.mzmine.datamodel.Feature)8 HashMap (java.util.HashMap)7 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)7 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)5 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 Vector (java.util.Vector)4