Search in sources :

Example 1 with StorableScan

use of net.sf.mzmine.project.impl.StorableScan in project mzmine2 by mzmine.

the class RawDataFileOpenHandler_2_5 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_5.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_5.QUANTITY_SCAN.getElementName())) {
        // number of scans - actually not used for anything
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.SCAN_ID.getElementName())) {
        scanNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.STORED_DATA.getElementName())) {
        long offset = Long.parseLong(getTextOfElement());
        dataPointsOffsets.put(storedDataID, offset);
        dataPointsLengths.put(storedDataID, storedDataNumDP);
    }
    if (qName.equals(RawDataElementName_2_5.MS_LEVEL.getElementName())) {
        msLevel = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.PARENT_SCAN.getElementName())) {
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.POLARITY.getElementName())) {
        String txt = getTextOfElement();
        try {
            polarity = PolarityType.valueOf(txt);
        } catch (Exception e) {
            polarity = PolarityType.fromSingleChar(txt);
        }
    }
    if (qName.equals(RawDataElementName_2_5.SCAN_DESCRIPTION.getElementName())) {
        scanDescription = getTextOfElement();
    }
    if (qName.equals(RawDataElementName_2_5.SCAN_MZ_RANGE.getElementName())) {
        final String text = getTextOfElement();
        scanMZRange = RangeUtils.parseRange(text);
    }
    if (qName.equals(RawDataElementName_2_5.PRECURSOR_CHARGE.getElementName())) {
        precursorCharge = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.PRECURSOR_MZ.getElementName())) {
        precursorMZ = Double.parseDouble(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.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_5.QUANTITY_DATAPOINTS.getElementName())) {
        dataPointsNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.FRAGMENT_SCAN.getElementName())) {
        fragmentScan[fragmentCount++] = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_5.SCAN.getElementName())) {
        StorableScan storableScan = new StorableScan(newRawDataFile, currentStorageID, dataPointsNumber, scanNumber, msLevel, retentionTime, precursorMZ, precursorCharge, fragmentScan, null, polarity, scanDescription, scanMZRange);
        try {
            newRawDataFile.addScan(storableScan);
        } catch (IOException e) {
            throw new SAXException(e);
        }
        for (StorableMassList newML : massLists) {
            newML.setScan(storableScan);
            storableScan.addMassList(newML);
        }
        // Cleanup
        massLists.clear();
        currentStorageID = -1;
        dataPointsNumber = -1;
        scanNumber = -1;
        msLevel = -1;
        retentionTime = -1;
        precursorMZ = -1;
        precursorCharge = -1;
        fragmentScan = null;
        polarity = PolarityType.UNKNOWN;
        scanDescription = "";
        scanMZRange = null;
    }
}
Also used : StorableScan(net.sf.mzmine.project.impl.StorableScan) IOException(java.io.IOException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) StorableMassList(net.sf.mzmine.project.impl.StorableMassList) SAXException(org.xml.sax.SAXException)

Example 2 with StorableScan

use of net.sf.mzmine.project.impl.StorableScan in project mzmine2 by mzmine.

the class RawDataFileOpenHandler_2_0 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_0.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_0.QUANTITY_SCAN.getElementName())) {
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.SCAN_ID.getElementName())) {
        scanNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.MS_LEVEL.getElementName())) {
        msLevel = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.PARENT_SCAN.getElementName())) {
        Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.PRECURSOR_MZ.getElementName())) {
        precursorMZ = Double.parseDouble(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.PRECURSOR_CHARGE.getElementName())) {
        precursorCharge = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.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_0.CENTROIDED.getElementName())) {
        boolean centroided = Boolean.parseBoolean(getTextOfElement());
        if (centroided)
            spectrumType = MassSpectrumType.CENTROIDED;
        else
            spectrumType = MassSpectrumType.PROFILE;
    }
    if (qName.equals(RawDataElementName_2_0.QUANTITY_DATAPOINTS.getElementName())) {
        dataPointsNumber = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.FRAGMENT_SCAN.getElementName())) {
        fragmentScan[fragmentCount++] = Integer.parseInt(getTextOfElement());
    }
    if (qName.equals(RawDataElementName_2_0.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);
        } catch (IOException e) {
            throw new SAXException(e);
        }
        storageFileOffset += dataPointsNumber * 4 * 2;
    }
}
Also used : StorableScan(net.sf.mzmine.project.impl.StorableScan) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 3 with StorableScan

use of net.sf.mzmine.project.impl.StorableScan 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 4 with StorableScan

use of net.sf.mzmine.project.impl.StorableScan in project mzmine2 by mzmine.

the class RawDataFileSaveHandler method saveRawDataInformation.

/**
 * Function which creates an XML file with the descripcion of the raw data
 *
 * @param rawDataFile
 * @param hd
 * @throws SAXException
 * @throws java.lang.Exception
 */
private void saveRawDataInformation(RawDataFileImpl rawDataFile, TransformerHandler hd) throws SAXException, IOException {
    AttributesImpl atts = new AttributesImpl();
    hd.startElement("", "", RawDataElementName.RAWDATA.getElementName(), atts);
    // <NAME>
    hd.startElement("", "", RawDataElementName.NAME.getElementName(), atts);
    hd.characters(rawDataFile.getName().toCharArray(), 0, rawDataFile.getName().length());
    hd.endElement("", "", RawDataElementName.NAME.getElementName());
    // <STORED_DATAPOINTS>
    atts.addAttribute("", "", RawDataElementName.QUANTITY.getElementName(), "CDATA", String.valueOf(dataPointsOffsets.size()));
    hd.startElement("", "", RawDataElementName.STORED_DATAPOINTS.getElementName(), atts);
    atts.clear();
    for (Integer storageID : dataPointsOffsets.keySet()) {
        if (canceled)
            return;
        int length = dataPointsLengths.get(storageID);
        long offset = consolidatedDataPointsOffsets.get(storageID);
        atts.addAttribute("", "", RawDataElementName.STORAGE_ID.getElementName(), "CDATA", String.valueOf(storageID));
        atts.addAttribute("", "", RawDataElementName.QUANTITY_DATAPOINTS.getElementName(), "CDATA", String.valueOf(length));
        hd.startElement("", "", RawDataElementName.STORED_DATA.getElementName(), atts);
        atts.clear();
        hd.characters(String.valueOf(offset).toCharArray(), 0, String.valueOf(offset).length());
        hd.endElement("", "", RawDataElementName.STORED_DATA.getElementName());
    }
    hd.endElement("", "", RawDataElementName.STORED_DATAPOINTS.getElementName());
    // <QUANTITY>
    hd.startElement("", "", RawDataElementName.QUANTITY_SCAN.getElementName(), atts);
    hd.characters(String.valueOf(numOfScans).toCharArray(), 0, String.valueOf(numOfScans).length());
    hd.endElement("", "", RawDataElementName.QUANTITY_SCAN.getElementName());
    // <SCAN>
    for (int scanNumber : rawDataFile.getScanNumbers()) {
        if (canceled)
            return;
        StorableScan scan = (StorableScan) rawDataFile.getScan(scanNumber);
        int storageID = scan.getStorageID();
        atts.addAttribute("", "", RawDataElementName.STORAGE_ID.getElementName(), "CDATA", String.valueOf(storageID));
        hd.startElement("", "", RawDataElementName.SCAN.getElementName(), atts);
        fillScanElement(scan, hd);
        hd.endElement("", "", RawDataElementName.SCAN.getElementName());
        atts.clear();
        completedScans++;
        progress = 0.9 + (0.1 * ((double) completedScans / numOfScans));
    }
    hd.endElement("", "", RawDataElementName.RAWDATA.getElementName());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) StorableScan(net.sf.mzmine.project.impl.StorableScan)

Aggregations

StorableScan (net.sf.mzmine.project.impl.StorableScan)4 IOException (java.io.IOException)3 SAXException (org.xml.sax.SAXException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 SimpleMassList (net.sf.mzmine.datamodel.impl.SimpleMassList)1 StorableMassList (net.sf.mzmine.project.impl.StorableMassList)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1