Search in sources :

Example 6 with PolarityType

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

the class MzMLReadTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started parsing file " + file);
    MzMLUnmarshaller unmarshaller = new MzMLUnmarshaller(file);
    totalScans = unmarshaller.getObjectCountForXpath("/run/spectrumList/spectrum");
    fillScanIdTable(unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class), totalScans);
    MzMLObjectIterator<Spectrum> spectrumIterator = unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class);
    try {
        while (spectrumIterator.hasNext()) {
            if (isCanceled())
                return;
            Spectrum spectrum = spectrumIterator.next();
            // Ignore scans that are not MS, e.g. UV
            if (!isMsSpectrum(spectrum)) {
                parsedScans++;
                continue;
            }
            String scanId = spectrum.getId();
            Integer scanNumber = scanIdTable.get(scanId);
            if (scanNumber == null)
                throw new IllegalStateException("Cannot determine scan number: " + scanId);
            // Extract scan data
            int msLevel = extractMSLevel(spectrum);
            double retentionTime = extractRetentionTime(spectrum);
            PolarityType polarity = extractPolarity(spectrum);
            int parentScan = extractParentScanNumber(spectrum);
            double precursorMz = extractPrecursorMz(spectrum);
            int precursorCharge = extractPrecursorCharge(spectrum);
            String scanDefinition = extractScanDefinition(spectrum);
            DataPoint[] dataPoints = extractDataPoints(spectrum);
            // Auto-detect whether this scan is centroided
            MassSpectrumType spectrumType = ScanUtils.detectSpectrumType(dataPoints);
            SimpleScan scan = new SimpleScan(null, scanNumber, msLevel, retentionTime, precursorMz, precursorCharge, null, dataPoints, spectrumType, polarity, scanDefinition, null);
            for (SimpleScan s : parentStack) {
                if (s.getScanNumber() == parentScan) {
                    s.addFragmentScan(scanNumber);
                }
            }
            /*
         * Verify the size of parentStack. The actual size of the window to cover possible
         * candidates is defined by limitSize.
         */
            if (parentStack.size() > PARENT_STACK_SIZE) {
                SimpleScan firstScan = parentStack.removeLast();
                newMZmineFile.addScan(firstScan);
            }
            parentStack.addFirst(scan);
            parsedScans++;
        }
        while (!parentStack.isEmpty()) {
            SimpleScan scan = parentStack.removeLast();
            newMZmineFile.addScan(scan);
        }
        finalRawDataFile = newMZmineFile.finishWriting();
        project.addFile(finalRawDataFile);
    } catch (Throwable e) {
        e.printStackTrace();
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Error parsing mzML: " + ExceptionUtils.exceptionToString(e));
        e.printStackTrace();
        return;
    }
    if (parsedScans == 0) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("No scans found");
        return;
    }
    logger.info("Finished parsing " + file + ", parsed " + parsedScans + " scans");
    setStatus(TaskStatus.FINISHED);
}
Also used : PolarityType(net.sf.mzmine.datamodel.PolarityType) MassSpectrumType(net.sf.mzmine.datamodel.MassSpectrumType) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Spectrum(uk.ac.ebi.jmzml.model.mzml.Spectrum) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) MzMLUnmarshaller(uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 7 with PolarityType

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

the class IsotopePatternCalculator method showIsotopePredictionDialog.

public static IsotopePattern showIsotopePredictionDialog(Window parent, boolean valueCheckRequired) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(IsotopePatternCalculator.class);
    ExitCode exitCode = parameters.showSetupDialog(parent, valueCheckRequired);
    if (exitCode != ExitCode.OK)
        return null;
    String formula = parameters.getParameter(IsotopePatternCalculatorParameters.formula).getValue();
    int charge = parameters.getParameter(IsotopePatternCalculatorParameters.charge).getValue();
    PolarityType polarity = parameters.getParameter(IsotopePatternCalculatorParameters.polarity).getValue();
    double minAbundance = parameters.getParameter(IsotopePatternCalculatorParameters.minAbundance).getValue();
    try {
        IsotopePattern predictedPattern = calculateIsotopePattern(formula, minAbundance, charge, polarity);
        return predictedPattern;
    } catch (Exception e) {
        MZmineCore.getDesktop().displayException(MZmineCore.getDesktop().getMainWindow(), e);
    }
    return null;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) PolarityType(net.sf.mzmine.datamodel.PolarityType) ExitCode(net.sf.mzmine.util.ExitCode) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

PolarityType (net.sf.mzmine.datamodel.PolarityType)7 MassSpectrumType (net.sf.mzmine.datamodel.MassSpectrumType)4 DataPoint (net.sf.mzmine.datamodel.DataPoint)3 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)3 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)2 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)2 ParameterSet (net.sf.mzmine.parameters.ParameterSet)2 ExitCode (net.sf.mzmine.util.ExitCode)2 IOException (java.io.IOException)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 Array (ucar.ma2.Array)1 Index (ucar.ma2.Index)1 Spectrum (uk.ac.ebi.jmzml.model.mzml.Spectrum)1 MzMLUnmarshaller (uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller)1