Search in sources :

Example 31 with SimplePeakListRow

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

the class PeakUtils method copyPeakRow.

/**
 * Creates a copy of a PeakListRow.
 * @param row A row.
 * @return A copy of row.
 */
public static PeakListRow copyPeakRow(final PeakListRow row) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    for (final Feature peak : row.getPeaks()) {
        final Feature newPeak = new SimpleFeature(peak);
        PeakUtils.copyPeakProperties(peak, newPeak);
        newRow.addPeak(peak.getDataFile(), newPeak);
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 32 with SimplePeakListRow

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

the class MzTabImportTask method importSmallMolecules.

private void importSmallMolecules(PeakList newPeakList, MZTabFile mzTabFile, Map<Integer, RawDataFile> rawDataFiles) {
    SortedMap<Integer, Assay> assayMap = mzTabFile.getMetadata().getAssayMap();
    Collection<SmallMolecule> smallMolecules = mzTabFile.getSmallMolecules();
    // Loop through SML data
    String formula, description, database, url = "";
    double mzExp = 0, abundance = 0, peak_mz = 0, peak_rt = 0, peak_height = 0, rtValue = 0;
    // int charge = 0;
    int rowCounter = 0;
    for (SmallMolecule smallMolecule : smallMolecules) {
        // Stop the process if cancel() was called
        if (isCanceled())
            return;
        rowCounter++;
        formula = smallMolecule.getChemicalFormula();
        // smile = smallMolecule.getSmiles();
        // inchiKey = smallMolecule.getInchiKey();
        description = smallMolecule.getDescription();
        // species = smallMolecule.getSpecies();
        database = smallMolecule.getDatabase();
        if (smallMolecule.getURI() != null) {
            url = smallMolecule.getURI().toString();
        }
        String identifier = smallMolecule.getIdentifier().toString();
        SplitList<Double> rt = smallMolecule.getRetentionTime();
        if (smallMolecule.getExpMassToCharge() != null) {
            mzExp = smallMolecule.getExpMassToCharge();
        }
        // Calculate average RT if multiple values are available
        if (rt != null && !rt.isEmpty()) {
            rtValue = DoubleMath.mean(rt);
        }
        if ((url != null) && (url.equals("null"))) {
            url = null;
        }
        if (identifier.equals("null")) {
            identifier = null;
        }
        if (description == null && identifier != null) {
            description = identifier;
        }
        // Add shared information to row
        SimplePeakListRow newRow = new SimplePeakListRow(rowCounter);
        newRow.setAverageMZ(mzExp);
        newRow.setAverageRT(rtValue);
        if (description != null) {
            SimplePeakIdentity newIdentity = new SimplePeakIdentity(description, formula, database, identifier, url);
            newRow.addPeakIdentity(newIdentity, false);
        }
        // Add raw data file entries to row
        for (Entry<Integer, RawDataFile> rawDataEntry : rawDataFiles.entrySet()) {
            RawDataFile rawData = rawDataEntry.getValue();
            Assay dataFileAssay = assayMap.get(rawDataEntry.getKey());
            abundance = 0;
            peak_mz = 0;
            peak_rt = 0;
            peak_height = 0;
            if (smallMolecule.getAbundanceColumnValue(dataFileAssay) != null) {
                abundance = smallMolecule.getAbundanceColumnValue(dataFileAssay);
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz") != null) {
                peak_mz = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz"));
            } else {
                peak_mz = mzExp;
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt") != null) {
                peak_rt = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt"));
            } else {
                peak_rt = rtValue;
            }
            if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height") != null) {
                peak_height = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height"));
            } else {
                peak_height = 0.0;
            }
            int[] scanNumbers = {};
            DataPoint[] finalDataPoint = new DataPoint[1];
            finalDataPoint[0] = new SimpleDataPoint(peak_mz, peak_height);
            int representativeScan = 0;
            int fragmentScan = 0;
            int[] allFragmentScans = new int[] { 0 };
            Range<Double> finalRTRange = Range.singleton(peak_rt);
            Range<Double> finalMZRange = Range.singleton(peak_mz);
            Range<Double> finalIntensityRange = Range.singleton(peak_height);
            FeatureStatus status = FeatureStatus.DETECTED;
            Feature peak = new SimpleFeature(rawData, peak_mz, peak_rt, peak_height, abundance, scanNumbers, finalDataPoint, status, representativeScan, fragmentScan, allFragmentScans, finalRTRange, finalMZRange, finalIntensityRange);
            if (abundance > 0) {
                newRow.addPeak(rawData, peak);
            }
        }
        // Add row to feature list
        newPeakList.addRow(newRow);
    }
}
Also used : FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Assay(uk.ac.ebi.pride.jmztab.model.Assay) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SmallMolecule(uk.ac.ebi.pride.jmztab.model.SmallMolecule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 33 with SimplePeakListRow

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

the class PeakListOpenHandler_2_5 method startElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
 *      java.lang.String, org.xml.sax.Attributes)
 */
@Override
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // This will remove any remaining characters from previous elements
    getTextOfElement();
    // <ROW>
    if (qName.equals(PeakListElementName_2_5.ROW.getElementName())) {
        if (buildingPeakList == null) {
            initializePeakList();
        }
        int rowID = Integer.parseInt(attrs.getValue(PeakListElementName_2_5.ID.getElementName()));
        buildingRow = new SimplePeakListRow(rowID);
        String comment = attrs.getValue(PeakListElementName_2_5.COMMENT.getElementName());
        buildingRow.setComment(comment);
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_5.PEAK_IDENTITY.getElementName())) {
        identityProperties = new Hashtable<String, String>();
        preferred = Boolean.parseBoolean(attrs.getValue(PeakListElementName_2_5.PREFERRED.getElementName()));
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.IDPROPERTY.getElementName())) {
        identityPropertyName = attrs.getValue(PeakListElementName_2_5.NAME.getElementName());
    }
    // <PEAK_INFORMATION>
    if (qName.equals(PeakListElementName_2_5.PEAK_INFORMATION.getElementName())) {
        informationProperties = new HashMap<>();
    }
    // <INFO_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.INFO_PROPERTY.getElementName())) {
        infoPropertyName = attrs.getValue(PeakListElementName_2_5.NAME.getElementName());
    }
    // <PEAK>
    if (qName.equals(PeakListElementName_2_5.PEAK.getElementName())) {
        peakColumnID = attrs.getValue(PeakListElementName_2_5.COLUMN.getElementName());
        mass = Double.parseDouble(attrs.getValue(PeakListElementName_2_5.MZ.getElementName()));
        // Before MZmine 2.6 retention time was saved in seconds, but now we
        // use minutes, so we need to divide by 60
        rt = Double.parseDouble(attrs.getValue(PeakListElementName_2_5.RT.getElementName())) / 60d;
        height = Double.parseDouble(attrs.getValue(PeakListElementName_2_5.HEIGHT.getElementName()));
        area = Double.parseDouble(attrs.getValue(PeakListElementName_2_5.AREA.getElementName()));
        peakStatus = attrs.getValue(PeakListElementName_2_5.STATUS.getElementName());
        String chargeString = attrs.getValue(PeakListElementName_2_5.CHARGE.getElementName());
        if (chargeString != null)
            currentPeakCharge = Integer.valueOf(chargeString);
        else
            currentPeakCharge = 0;
        try {
            parentChromatogramRowID = Integer.parseInt(attrs.getValue(PeakListElementName_2_5.PARENT_CHROMATOGRAM_ROW_ID.getElementName()));
        } catch (NumberFormatException e) {
            parentChromatogramRowID = null;
        }
    }
    // <MZPEAK>
    if (qName.equals(PeakListElementName_2_5.MZPEAKS.getElementName())) {
        numOfMZpeaks = Integer.parseInt(attrs.getValue(PeakListElementName_2_5.QUANTITY.getElementName()));
    }
    // <ISOTOPE_PATTERN>
    if (qName.equals(PeakListElementName_2_5.ISOTOPE_PATTERN.getElementName())) {
        currentIsotopes.clear();
        currentIsotopePatternStatus = IsotopePatternStatus.valueOf(attrs.getValue(PeakListElementName_2_5.STATUS.getElementName()));
        currentIsotopePatternDescription = attrs.getValue(PeakListElementName_2_5.DESCRIPTION.getElementName());
    }
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SAXException(org.xml.sax.SAXException)

Example 34 with SimplePeakListRow

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

the class SmoothingTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    try {
        // Get filter weights.
        final double[] filterWeights = SavitzkyGolayFilter.getNormalizedWeights(filterWidth);
        // Create new feature list
        newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
        // Process each row.
        for (final PeakListRow row : origPeakList.getRows()) {
            if (!isCanceled()) {
                // Create a new peak-list row.
                final int originalID = row.getID();
                final PeakListRow newRow = new SimplePeakListRow(originalID);
                // Process each peak.
                for (final Feature peak : row.getPeaks()) {
                    if (!isCanceled()) {
                        // Copy original peak intensities.
                        final int[] scanNumbers = peak.getScanNumbers();
                        final int numScans = scanNumbers.length;
                        final double[] intensities = new double[numScans];
                        for (int i = 0; i < numScans; i++) {
                            final DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
                            intensities[i] = dataPoint == null ? 0.0 : dataPoint.getIntensity();
                        }
                        // Smooth peak.
                        final double[] smoothed = convolve(intensities, filterWeights);
                        // Measure peak (max, ranges, area etc.)
                        final RawDataFile dataFile = peak.getDataFile();
                        final DataPoint[] newDataPoints = new DataPoint[numScans];
                        double maxIntensity = 0.0;
                        int maxScanNumber = -1;
                        DataPoint maxDataPoint = null;
                        Range<Double> intensityRange = null;
                        double area = 0.0;
                        for (int i = 0; i < numScans; i++) {
                            final int scanNumber = scanNumbers[i];
                            final DataPoint dataPoint = peak.getDataPoint(scanNumber);
                            final double intensity = smoothed[i];
                            if (dataPoint != null && intensity > 0.0) {
                                // Create a new data point.
                                final double mz = dataPoint.getMZ();
                                final double rt = dataFile.getScan(scanNumber).getRetentionTime();
                                final DataPoint newDataPoint = new SimpleDataPoint(mz, intensity);
                                newDataPoints[i] = newDataPoint;
                                // Track maximum intensity data point.
                                if (intensity > maxIntensity) {
                                    maxIntensity = intensity;
                                    maxScanNumber = scanNumber;
                                    maxDataPoint = newDataPoint;
                                }
                                // Update ranges.
                                if (intensityRange == null) {
                                    intensityRange = Range.singleton(intensity);
                                } else {
                                    intensityRange = intensityRange.span(Range.singleton(intensity));
                                }
                                // Accumulate peak area.
                                if (i != 0) {
                                    final DataPoint lastDP = newDataPoints[i - 1];
                                    final double lastIntensity = lastDP == null ? 0.0 : lastDP.getIntensity();
                                    final double lastRT = dataFile.getScan(scanNumbers[i - 1]).getRetentionTime();
                                    area += (rt - lastRT) * 60d * (intensity + lastIntensity) / 2.0;
                                }
                            }
                        }
                        assert maxDataPoint != null;
                        if (!isCanceled() && maxScanNumber >= 0) {
                            // Create a new peak.
                            newRow.addPeak(dataFile, new SimpleFeature(dataFile, maxDataPoint.getMZ(), peak.getRT(), maxIntensity, area, scanNumbers, newDataPoints, peak.getFeatureStatus(), maxScanNumber, peak.getMostIntenseFragmentScanNumber(), peak.getAllMS2FragmentScanNumbers(), peak.getRawDataPointsRTRange(), peak.getRawDataPointsMZRange(), intensityRange));
                        }
                    }
                }
                newPeakList.addRow(newRow);
                progress++;
            }
        }
        // Finish up.
        if (!isCanceled()) {
            // Add new peak-list to the project.
            project.addPeakList(newPeakList);
            // Add quality parameters to peaks
            QualityParameters.calculateQualityParameters(newPeakList);
            // Remove the original peak-list if requested.
            if (removeOriginal) {
                project.removePeakList(origPeakList);
            }
            // Copy previously applied methods
            for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
                newPeakList.addDescriptionOfAppliedTask(method);
            }
            // Add task description to peak-list.
            newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks smoothed by Savitzky-Golay filter", parameters));
            LOG.finest("Finished peak smoothing: " + progress + " rows processed");
            setStatus(TaskStatus.FINISHED);
        }
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "Smoothing error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Example 35 with SimplePeakListRow

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

the class PeakListOpenHandler_2_0 method startElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String,
 *      java.lang.String, org.xml.sax.Attributes)
 */
@Override
public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // This will remove any remaining characters from previous elements
    getTextOfElement();
    // <ROW>
    if (qName.equals(PeakListElementName_2_0.ROW.getElementName())) {
        if (buildingPeakList == null) {
            initializePeakList();
        }
        int rowID = Integer.parseInt(attrs.getValue(PeakListElementName_2_0.ID.getElementName()));
        buildingRow = new SimplePeakListRow(rowID);
        String comment = attrs.getValue(PeakListElementName_2_0.COMMENT.getElementName());
        buildingRow.setComment(comment);
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_0.PEAK_IDENTITY.getElementName())) {
        identityProperties = new Hashtable<String, String>();
        preferred = Boolean.parseBoolean(attrs.getValue(PeakListElementName_2_0.PREFERRED.getElementName()));
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_0.IDPROPERTY.getElementName())) {
        identityPropertyName = attrs.getValue(PeakListElementName_2_0.NAME.getElementName());
    }
    // <PEAK>
    if (qName.equals(PeakListElementName_2_0.PEAK.getElementName())) {
        peakColumnID = attrs.getValue(PeakListElementName_2_0.COLUMN.getElementName());
        mass = Double.parseDouble(attrs.getValue(PeakListElementName_2_0.MZ.getElementName()));
        // Before MZmine 2.6 retention time was saved in seconds, but now we
        // use minutes, so we need to divide by 60
        rt = Double.parseDouble(attrs.getValue(PeakListElementName_2_0.RT.getElementName())) / 60d;
        height = Double.parseDouble(attrs.getValue(PeakListElementName_2_0.HEIGHT.getElementName()));
        area = Double.parseDouble(attrs.getValue(PeakListElementName_2_0.AREA.getElementName()));
        peakStatus = attrs.getValue(PeakListElementName_2_0.STATUS.getElementName());
        String chargeString = attrs.getValue(PeakListElementName_2_0.CHARGE.getElementName());
        if (chargeString != null)
            currentPeakCharge = Integer.valueOf(chargeString);
        else
            currentPeakCharge = 0;
    }
    // <MZPEAK>
    if (qName.equals(PeakListElementName_2_0.MZPEAKS.getElementName())) {
        numOfMZpeaks = Integer.parseInt(attrs.getValue(PeakListElementName_2_0.QUANTITY.getElementName()));
    }
    // <ISOTOPE_PATTERN>
    if (qName.equals(PeakListElementName_2_0.ISOTOPE_PATTERN.getElementName())) {
        currentIsotopes.clear();
        currentIsotopePatternStatus = IsotopePatternStatus.valueOf(attrs.getValue(PeakListElementName_2_0.STATUS.getElementName()));
        currentIsotopePatternDescription = attrs.getValue(PeakListElementName_2_0.DESCRIPTION.getElementName());
    }
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SAXException(org.xml.sax.SAXException)

Aggregations

SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)38 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)31 Feature (net.sf.mzmine.datamodel.Feature)29 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)22 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)19 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)17 DataPoint (net.sf.mzmine.datamodel.DataPoint)15 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)14 Scan (net.sf.mzmine.datamodel.Scan)9 ArrayList (java.util.ArrayList)8 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)8 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 Hashtable (java.util.Hashtable)3 List (java.util.List)3 Vector (java.util.Vector)3 ParameterSet (net.sf.mzmine.parameters.ParameterSet)3 PeakSorter (net.sf.mzmine.util.PeakSorter)3 SAXException (org.xml.sax.SAXException)3