Search in sources :

Example 51 with DataPoint

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

the class PeakListOpenHandler_2_5 method readPeakList.

/**
 * Load the feature list from the zip file reading the XML feature list file
 */
@Override
public PeakList readPeakList(InputStream peakListStream) throws IOException, ParserConfigurationException, SAXException {
    totalRows = 0;
    parsedRows = 0;
    charBuffer = new StringBuffer();
    appliedMethods = new Vector<String>();
    appliedMethodParameters = new Vector<String>();
    currentPeakListDataFiles = new Vector<RawDataFile>();
    currentIsotopes = new Vector<DataPoint>();
    currentAllMS2FragmentScans = new Vector<Integer>();
    buildingPeakList = null;
    // Parse the XML file
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse(peakListStream, this);
    // If there were no rows in the peaklist, it is still not initialized
    if (buildingPeakList == null) {
        initializePeakList();
    }
    return buildingPeakList;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 52 with DataPoint

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

the class RawDataFileOpenHandler_2_3 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <NAME>
    if (qName.equals(RawDataElementName_2_3.NAME.getElementName())) {
        // Adds the scan file and the name to the new raw data file
        String name = getTextOfElement();
        logger.info("Loading raw data file: " + name);
        newRawDataFile.setName(name);
    }
    if (qName.equals(RawDataElementName_2_3.QUANTITY_SCAN.getElementName())) {
        // number of scans - actually not used for anything
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.SCAN_ID.getElementName())) {
        scanNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.MS_LEVEL.getElementName())) {
        msLevel = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.PARENT_SCAN.getElementName())) {
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.PRECURSOR_MZ.getElementName())) {
        precursorMZ = Double.parseDouble(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.PRECURSOR_CHARGE.getElementName())) {
        precursorCharge = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.RETENTION_TIME.getElementName())) {
        // Before MZmine 2.6 retention time was saved in seconds, but now we
        // use
        // minutes, so we need to divide by 60
        retentionTime = Double.parseDouble(getTextOfElement()) / 60d;
    }
    if (qName.equals(RawDataElementName_2_3.CENTROIDED.getElementName())) {
        boolean centroided = Boolean.parseBoolean(getTextOfElement());
        if (centroided)
            spectrumType = MassSpectrumType.CENTROIDED;
        else
            spectrumType = MassSpectrumType.PROFILE;
    }
    if (qName.equals(RawDataElementName_2_3.QUANTITY_DATAPOINTS.getElementName())) {
        dataPointsNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.FRAGMENT_SCAN.getElementName())) {
        fragmentScan[fragmentCount++] = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_3.MASS_LIST.getElementName())) {
        char[] encodedDataPoints = getTextOfElement().toCharArray();
        DataPoint[] dataPoints = ScanUtils.decodeDataPointsBase64(encodedDataPoints);
        SimpleMassList newML = currentMassLists.get(currentMassLists.size() - 1);
        newML.setDataPoints(dataPoints);
    }
    if (qName.equals(RawDataElementName_2_3.SCAN.getElementName())) {
        try {
            int newStorageID = 1;
            TreeMap<Integer, Long> dataPointsOffsets = newRawDataFile.getDataPointsOffsets();
            TreeMap<Integer, Integer> dataPointsLengths = newRawDataFile.getDataPointsLengths();
            if (!dataPointsOffsets.isEmpty())
                newStorageID = dataPointsOffsets.lastKey().intValue() + 1;
            StorableScan storableScan = new StorableScan(newRawDataFile, newStorageID, dataPointsNumber, scanNumber, msLevel, retentionTime, precursorMZ, precursorCharge, fragmentScan, spectrumType, PolarityType.UNKNOWN, "", null);
            newRawDataFile.addScan(storableScan);
            dataPointsOffsets.put(newStorageID, storageFileOffset);
            dataPointsLengths.put(newStorageID, dataPointsNumber);
            for (SimpleMassList newML : currentMassLists) {
                newML.setScan(storableScan);
            }
            allMassLists.addAll(currentMassLists);
            currentMassLists.clear();
        } catch (IOException e) {
            throw new SAXException(e);
        }
        storageFileOffset += dataPointsNumber * 4 * 2;
    }
}
Also used : SimpleMassList(net.sf.mzmine.datamodel.impl.SimpleMassList) IOException(java.io.IOException) DataPoint(net.sf.mzmine.datamodel.DataPoint) SAXException(org.xml.sax.SAXException) DataPoint(net.sf.mzmine.datamodel.DataPoint) StorableScan(net.sf.mzmine.project.impl.StorableScan)

Example 53 with DataPoint

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

the class ShapeModelerTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    Class<?> shapeModelClass = shapeModelerType.getModelClass();
    Constructor<?> shapeModelConstruct;
    shapeModelConstruct = shapeModelClass.getConstructors()[0];
    // Get data file information
    RawDataFile dataFile = originalPeakList.getRawDataFile(0);
    // Create new feature list
    newPeakList = new SimplePeakList(originalPeakList + " " + suffix, dataFile);
    totalRows = originalPeakList.getNumberOfRows();
    int[] scanNumbers;
    double[] retentionTimes, intensities;
    SimplePeakListRow newRow;
    for (PeakListRow row : originalPeakList.getRows()) {
        if (isCanceled())
            return;
        newRow = new SimplePeakListRow(newPeakID);
        try {
            for (Feature peak : row.getPeaks()) {
                // Load the intensities into array
                dataFile = peak.getDataFile();
                scanNumbers = peak.getScanNumbers();
                retentionTimes = new double[scanNumbers.length];
                for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
                intensities = new double[scanNumbers.length];
                for (int i = 0; i < scanNumbers.length; i++) {
                    DataPoint dp = peak.getDataPoint(scanNumbers[i]);
                    if (dp != null)
                        intensities[i] = dp.getIntensity();
                    else
                        intensities[i] = 0;
                }
                Feature shapePeak = (Feature) shapeModelConstruct.newInstance(peak, scanNumbers, intensities, retentionTimes, resolution);
                newRow.addPeak(shapePeak.getDataFile(), shapePeak);
            }
        } catch (Exception e) {
            String message = "Error trying to make an instance of shape model class " + shapeModelClass;
            MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), message);
            logger.severe(message);
            return;
        }
        newPeakList.addRow(newRow);
        newPeakID++;
        processedRows++;
    }
    // Add new peaklist to the project
    project.addPeakList(newPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);
    // Remove the original peaklist if requested
    if (removeOriginal)
        project.removePeakList(originalPeakList);
    // Load previous applied methods
    for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
        newPeakList.addDescriptionOfAppliedTask(proc);
    }
    // Add task description to peakList
    newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks shaped by " + shapeModelerType + " function", parameters));
    logger.finest("Finished peak shape modeler " + processedRows + " rows processed");
    setStatus(TaskStatus.FINISHED);
}
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) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Example 54 with DataPoint

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

the class PeakExtenderTask method getExtendedPeak.

private Feature getExtendedPeak(Feature oldPeak) {
    double maxHeight = oldPeak.getHeight();
    int originScanNumber = oldPeak.getRepresentativeScanNumber();
    RawDataFile rawFile = oldPeak.getDataFile();
    ExtendedPeak newPeak = new ExtendedPeak(rawFile);
    int totalScanNumber = rawFile.getNumOfScans();
    Range<Double> mzRange = mzTolerance.getToleranceRange(oldPeak.getMZ());
    Scan scan;
    DataPoint dataPoint;
    // Look for dataPoint related to this peak to the left
    int scanNumber = originScanNumber;
    scanNumber--;
    while (scanNumber > 0) {
        scan = rawFile.getScan(scanNumber);
        if (scan == null) {
            scanNumber--;
            continue;
        }
        if (scan.getMSLevel() != 1) {
            scanNumber--;
            continue;
        }
        dataPoint = ScanUtils.findBasePeak(scan, mzRange);
        if (dataPoint == null)
            break;
        if (dataPoint.getIntensity() < minimumHeight)
            break;
        newPeak.addMzPeak(scanNumber, dataPoint);
        if (dataPoint.getIntensity() > maxHeight)
            maxHeight = dataPoint.getIntensity();
        scanNumber--;
    }
    // Add original dataPoint
    newPeak.addMzPeak(originScanNumber, oldPeak.getDataPoint(originScanNumber));
    // Look to the right
    scanNumber = originScanNumber;
    scanNumber++;
    while (scanNumber <= totalScanNumber) {
        scan = rawFile.getScan(scanNumber);
        if (scan == null) {
            scanNumber++;
            continue;
        }
        if (scan.getMSLevel() != 1) {
            scanNumber++;
            continue;
        }
        dataPoint = ScanUtils.findBasePeak(scan, mzRange);
        if (dataPoint == null)
            break;
        if (dataPoint.getIntensity() < minimumHeight)
            break;
        newPeak.addMzPeak(scanNumber, dataPoint);
        if (dataPoint.getIntensity() > maxHeight)
            maxHeight = dataPoint.getIntensity();
        scanNumber++;
    }
    newPeak.finishExtendedPeak();
    newPeak.setMostIntenseFragmentScanNumber(oldPeak.getMostIntenseFragmentScanNumber());
    int[] scanNumbers = newPeak.getScanNumbers();
    logger.finest("Extended peak original " + originScanNumber + " from " + scanNumbers[0] + " - " + scanNumbers[scanNumbers.length - 1] + " height " + maxHeight);
    return newPeak;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 55 with DataPoint

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

the class ShapeModelerSetupDialog method loadPreviewPeak.

private void loadPreviewPeak() {
    PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
    if (previewRow == null)
        return;
    logger.finest("Loading new preview peak " + previewRow);
    Feature previewPeak = previewRow.getPeaks()[0];
    ticPlot.removeAllTICDataSets();
    // Load the intensities into array
    RawDataFile dataFile = previewPeak.getDataFile();
    int[] scanNumbers = previewPeak.getScanNumbers();
    double[] retentionTimes = new double[scanNumbers.length];
    for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
    double[] intensities = new double[scanNumbers.length];
    for (int i = 0; i < scanNumbers.length; i++) {
        DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0;
    }
    // Create shape model
    updateParameterSetFromComponents();
    JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType);
    ShapeModel model = (ShapeModel) component.getSelectedItem();
    JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution);
    double resolution = ((Number) resolutionField.getValue()).doubleValue();
    try {
        Class<?> shapeModelClass = model.getModelClass();
        Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0];
        // shapePeakModel(ChromatographicPeak originalDetectedShape, int[]
        // scanNumbers,
        // double[] intensities, double[] retentionTimes, double resolution)
        Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution);
        PeakDataSet peakDataSet = new PeakDataSet(shapePeak);
        ticPlot.addPeakDataset(peakDataSet);
        ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]);
        ticPlot.addTICDataset(ticDataset);
        // Set auto range to axes
        ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
        ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
        ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
    } catch (Exception e) {
        String message = "Error trying to make an instance of Peak Builder " + model;
        MZmineCore.getDesktop().displayErrorMessage(this, message);
        logger.severe(message);
        e.printStackTrace();
        return;
    }
}
Also used : PeakDataSet(net.sf.mzmine.modules.visualization.tic.PeakDataSet) JComboBox(javax.swing.JComboBox) JFormattedTextField(javax.swing.JFormattedTextField) ChromatogramTICDataSet(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ChromatogramTICDataSet) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) 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