Search in sources :

Example 31 with SimpleDataPoint

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

the class ScanUtils method decodeDataPointsFromBytes.

public static DataPoint[] decodeDataPointsFromBytes(byte[] bytes) {
    // each double is 8 bytes and we need one for m/z and one for intensity
    int dpCount = bytes.length / 2 / 8;
    // make a data input stream
    ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
    DataInputStream peakStream = new DataInputStream(byteStream);
    DataPoint[] dataPoints = new DataPoint[dpCount];
    for (int i = 0; i < dataPoints.length; i++) {
        try {
            double mz = peakStream.readDouble();
            double intensity = peakStream.readDouble();
            dataPoints[i] = new SimpleDataPoint(mz, intensity);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return dataPoints;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ByteArrayInputStream(java.io.ByteArrayInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 32 with SimpleDataPoint

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

the class Gap method noMoreOffers.

/**
 * Finalizes the gap, adds a peak
 *
 * @param lock A lock for multi threading purpose. null if single threaded
 */
public void noMoreOffers() {
    // Check peak that was last constructed
    if (currentPeakDataPoints != null) {
        checkCurrentPeak();
        currentPeakDataPoints = null;
    }
    // If we have best peak candidate, construct a SimpleChromatographicPeak
    if (bestPeakDataPoints != null) {
        double area = 0, height = 0, mz = 0, rt = 0;
        int[] scanNumbers = new int[bestPeakDataPoints.size()];
        DataPoint[] finalDataPoint = new DataPoint[bestPeakDataPoints.size()];
        Range<Double> finalRTRange = null, finalMZRange = null, finalIntensityRange = null;
        int representativeScan = 0;
        // Process all datapoints
        for (int i = 0; i < bestPeakDataPoints.size(); i++) {
            GapDataPoint dp = bestPeakDataPoints.get(i);
            if (i == 0) {
                finalRTRange = Range.singleton(dp.getRT());
                finalMZRange = Range.singleton(dp.getMZ());
                finalIntensityRange = Range.singleton(dp.getIntensity());
            } else {
                assert finalRTRange != null && finalMZRange != null && finalIntensityRange != null;
                finalRTRange = finalRTRange.span(Range.singleton(dp.getRT()));
                finalMZRange = finalMZRange.span(Range.singleton(dp.getMZ()));
                finalIntensityRange = finalIntensityRange.span(Range.singleton(dp.getIntensity()));
            }
            scanNumbers[i] = bestPeakDataPoints.get(i).getScanNumber();
            finalDataPoint[i] = new SimpleDataPoint(dp.getMZ(), dp.getIntensity());
            mz += bestPeakDataPoints.get(i).getMZ();
            // Check height
            if (bestPeakDataPoints.get(i).getIntensity() > height) {
                height = bestPeakDataPoints.get(i).getIntensity();
                rt = bestPeakDataPoints.get(i).getRT();
                representativeScan = bestPeakDataPoints.get(i).getScanNumber();
            }
            // Skip last data point
            if (i == bestPeakDataPoints.size() - 1)
                break;
            // X axis interval length
            double rtDifference = (bestPeakDataPoints.get(i + 1).getRT() - bestPeakDataPoints.get(i).getRT()) * 60d;
            // intensity at the beginning and end of the interval
            double intensityStart = bestPeakDataPoints.get(i).getIntensity();
            double intensityEnd = bestPeakDataPoints.get(i + 1).getIntensity();
            // calculate area of the interval
            area += (rtDifference * (intensityStart + intensityEnd) / 2);
        }
        // Calculate average m/z value
        mz /= bestPeakDataPoints.size();
        // Find the best fragmentation scan, if available
        int fragmentScan = ScanUtils.findBestFragmentScan(rawDataFile, finalRTRange, finalMZRange);
        // Find all MS2 level scans
        int[] allMS2FragmentScanNumbers = ScanUtils.findAllMS2FragmentScans(rawDataFile, finalRTRange, finalMZRange);
        SimpleFeature newPeak = new SimpleFeature(rawDataFile, mz, rt, height, area, scanNumbers, finalDataPoint, FeatureStatus.ESTIMATED, representativeScan, fragmentScan, allMS2FragmentScanNumbers, finalRTRange, finalMZRange, finalIntensityRange);
        // Fill the gap
        peakListRow.addPeak(rawDataFile, newPeak);
    }
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 33 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint 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 34 with SimpleDataPoint

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

the class AdapMgfExportTask method integerDataPoints.

/**
 * Round to nominal masses and select intensity
 *
 * @param dataPoints
 * @param mode
 * @return
 */
private DataPoint[] integerDataPoints(final DataPoint[] dataPoints, final String mode) {
    int size = dataPoints.length;
    Map<Double, Double> integerDataPoints = new HashMap<>();
    for (int i = 0; i < size; ++i) {
        double mz = Math.round(dataPoints[i].getMZ());
        double intensity = dataPoints[i].getIntensity();
        Double prevIntensity = integerDataPoints.get(mz);
        if (prevIntensity == null)
            prevIntensity = 0.0;
        switch(mode) {
            case AdapMgfExportParameters.ROUND_MODE_SUM:
                integerDataPoints.put(mz, prevIntensity + intensity);
                break;
            case AdapMgfExportParameters.ROUND_MODE_MAX:
                integerDataPoints.put(mz, Math.max(prevIntensity, intensity));
                break;
        }
    }
    DataPoint[] result = new DataPoint[integerDataPoints.size()];
    int count = 0;
    for (Entry<Double, Double> e : integerDataPoints.entrySet()) result[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
    return result;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) HashMap(java.util.HashMap) 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 35 with SimpleDataPoint

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

the class PeakListOpenHandler_2_5 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <NAME>
    if (qName.equals(PeakListElementName_2_5.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_5.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_5.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_5.RAWFILE.getElementName())) {
        rawDataFileID = getTextOfElement();
        RawDataFile dataFile = dataFilesIDMap.get(rawDataFileID);
        if (dataFile == null) {
            throw new SAXException("Cannot open feature list, because raw data file " + rawDataFileID + " is missing.");
        }
        currentPeakListDataFiles.add(dataFile);
    }
    // <SCAN_ID>
    if (qName.equals(PeakListElementName_2_5.SCAN_ID.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        scanNumbers = new int[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                scanNumbers[i] = dataInputStream.readInt();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <REPRESENTATIVE_SCAN>
    if (qName.equals(PeakListElementName_2_5.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    // <FRAGMENT_SCAN>
    if (qName.equals(PeakListElementName_2_5.FRAGMENT_SCAN.getElementName())) {
        fragmentScan = Integer.valueOf(getTextOfElement());
    }
    // <All_MS2_FRAGMENT_SCANS>
    if (qName.equals(PeakListElementName_2_5.ALL_MS2_FRAGMENT_SCANS.getElementName())) {
        Integer fragmentNumber = Integer.valueOf(getTextOfElement());
        currentAllMS2FragmentScans.add(fragmentNumber);
    }
    // <MASS>
    if (qName.equals(PeakListElementName_2_5.MZ.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        masses = new double[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                masses[i] = dataInputStream.readFloat();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <HEIGHT>
    if (qName.equals(PeakListElementName_2_5.HEIGHT.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        intensities = new double[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                intensities[i] = dataInputStream.readFloat();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <PEAK>
    if (qName.equals(PeakListElementName_2_5.PEAK.getElementName())) {
        DataPoint[] mzPeaks = new DataPoint[numOfMZpeaks];
        Range<Double> peakRTRange = null, peakMZRange = null, peakIntensityRange = null;
        RawDataFile dataFile = dataFilesIDMap.get(peakColumnID);
        if (dataFile == null)
            throw new SAXException("Error in project: data file " + peakColumnID + " not found");
        for (int i = 0; i < numOfMZpeaks; i++) {
            Scan sc = dataFile.getScan(scanNumbers[i]);
            double retentionTime = sc.getRetentionTime();
            double mz = masses[i];
            double intensity = intensities[i];
            if (peakIntensityRange == null) {
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            if (intensity > 0) {
                if (peakRTRange == null) {
                    peakRTRange = Range.singleton(retentionTime);
                } else {
                    peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                }
            }
            if (mz > 0.0) {
                mzPeaks[i] = new SimpleDataPoint(mz, intensity);
                if (peakMZRange == null)
                    peakMZRange = Range.singleton(mz);
                else
                    peakMZRange = peakMZRange.span(Range.singleton(mz));
            }
        }
        FeatureStatus status = FeatureStatus.valueOf(peakStatus);
        // convert vector of allMS2FragmentScans to array
        allMS2FragmentScanNumbers = new int[currentAllMS2FragmentScans.size()];
        for (int i = 0; i < allMS2FragmentScanNumbers.length; i++) {
            allMS2FragmentScanNumbers[i] = currentAllMS2FragmentScans.get(i);
        }
        // clear all MS2 fragment scan numbers list for next peak
        currentAllMS2FragmentScans.clear();
        SimpleFeature peak = new SimpleFeature(dataFile, mass, rt, height, area, scanNumbers, mzPeaks, status, representativeScan, fragmentScan, allMS2FragmentScanNumbers, peakRTRange, peakMZRange, peakIntensityRange);
        peak.setCharge(currentPeakCharge);
        if (currentIsotopes.size() > 0) {
            SimpleIsotopePattern newPattern = new SimpleIsotopePattern(currentIsotopes.toArray(new DataPoint[0]), currentIsotopePatternStatus, currentIsotopePatternDescription);
            peak.setIsotopePattern(newPattern);
            currentIsotopes.clear();
        }
        peak.setParentChromatogramRowID(parentChromatogramRowID);
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <INFO_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.INFO_PROPERTY.getElementName())) {
        informationProperties.put(infoPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_5.PEAK_IDENTITY.getElementName())) {
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    if (qName.equals(PeakListElementName_2_5.PEAK_INFORMATION.getElementName())) {
        PeakInformation information = new SimplePeakInformation(informationProperties);
        buildingRow.setPeakInformation(information);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_5.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_5.ISOTOPE.getElementName())) {
        String text = getTextOfElement();
        String[] items = text.split(":");
        double mz = Double.valueOf(items[0]);
        double intensity = Double.valueOf(items[1]);
        DataPoint isotope = new SimpleDataPoint(mz, intensity);
        currentIsotopes.add(isotope);
    }
    if (qName.equals(PeakListElementName_2_5.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_5.METHOD_PARAMETERS.getElementName())) {
        String appliedMethodParam = getTextOfElement();
        appliedMethodParameters.add(appliedMethodParam);
    }
}
Also used : FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) IOException(java.io.IOException) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) DataInputStream(java.io.DataInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SAXException(org.xml.sax.SAXException) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ByteArrayInputStream(java.io.ByteArrayInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation) PeakInformation(net.sf.mzmine.datamodel.PeakInformation) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation)

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