Search in sources :

Example 1 with FeatureStatus

use of net.sf.mzmine.datamodel.Feature.FeatureStatus in project mzmine2 by mzmine.

the class PeakStatusCellRenderer method getTableCellRendererComponent.

/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JPanel newPanel = new JPanel();
    newPanel.setLayout(new OverlayLayout(newPanel));
    Color bgColor;
    if (isSelected)
        bgColor = table.getSelectionBackground();
    else
        bgColor = table.getBackground();
    newPanel.setBackground(bgColor);
    if (hasFocus) {
        Border border = null;
        if (isSelected)
            border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
        if (border == null)
            border = UIManager.getBorder("Table.focusCellHighlightBorder");
        /*
       * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
       * otherwise setBorder() may throw a NullPointerException
       */
        if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
            newPanel.setBorder(border);
        }
    }
    if (value != null) {
        FeatureStatus status = (FeatureStatus) value;
        switch(status) {
            case DETECTED:
                newPanel.add(greenCircle);
                break;
            case ESTIMATED:
                newPanel.add(yellowCircle);
                break;
            case MANUAL:
                newPanel.add(orangeCircle);
                break;
            default:
                newPanel.add(redCircle);
                break;
        }
        newPanel.setToolTipText(status.toString());
    } else {
        newPanel.add(redCircle);
    }
    return newPanel;
}
Also used : JPanel(javax.swing.JPanel) FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) Color(java.awt.Color) OverlayLayout(javax.swing.OverlayLayout) Border(javax.swing.border.Border)

Example 2 with FeatureStatus

use of net.sf.mzmine.datamodel.Feature.FeatureStatus 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 3 with FeatureStatus

use of net.sf.mzmine.datamodel.Feature.FeatureStatus 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)

Example 4 with FeatureStatus

use of net.sf.mzmine.datamodel.Feature.FeatureStatus in project mzmine2 by mzmine.

the class PeakListOpenHandler_2_0 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_0.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_0.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_0.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_0.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_0.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_0.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    if (qName.equals(PeakListElementName_2_0.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_0.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_0.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_0.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 ((peakRTRange == null) || (peakIntensityRange == null)) {
                peakRTRange = Range.singleton(retentionTime);
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            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();
        }
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_0.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_0.PEAK_IDENTITY.getElementName())) {
        String content = getTextOfElement();
        if (identityProperties.get(PeakIdentity.PROPERTY_NAME) == null)
            identityProperties.put(PeakIdentity.PROPERTY_NAME, content);
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_0.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_0.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_0.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_0.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) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Example 5 with FeatureStatus

use of net.sf.mzmine.datamodel.Feature.FeatureStatus in project mzmine2 by mzmine.

the class PeakListOpenHandler_2_3 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_3.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_3.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_3.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_3.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_3.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_3.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    if (qName.equals(PeakListElementName_2_3.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_3.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_3.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_3.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 ((peakRTRange == null) || (peakIntensityRange == null)) {
                peakRTRange = Range.singleton(retentionTime);
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            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();
        }
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_3.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_3.PEAK_IDENTITY.getElementName())) {
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_3.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_3.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_3.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_3.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) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Aggregations

FeatureStatus (net.sf.mzmine.datamodel.Feature.FeatureStatus)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)4 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)4 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 Scan (net.sf.mzmine.datamodel.Scan)3 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)3 SAXException (org.xml.sax.SAXException)3 Color (java.awt.Color)1 JPanel (javax.swing.JPanel)1 OverlayLayout (javax.swing.OverlayLayout)1 Border (javax.swing.border.Border)1 Feature (net.sf.mzmine.datamodel.Feature)1 PeakInformation (net.sf.mzmine.datamodel.PeakInformation)1 SimplePeakInformation (net.sf.mzmine.datamodel.impl.SimplePeakInformation)1 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)1