Search in sources :

Example 1 with MassList

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

the class SingleRowPredictionTask method checkConstraints.

private void checkConstraints(IMolecularFormula cdkFormula) {
    // Check elemental ratios
    if (checkRatios) {
        boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
        if (!check)
            return;
    }
    Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
    // Check RDBE condition
    if (checkRDBE && (rdbeValue != null)) {
        boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
        if (!check)
            return;
    }
    // Calculate isotope similarity score
    final IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
    final String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
    final String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
    final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
    // Fixed min abundance
    final double minPredictedAbundance = 0.00001;
    final IsotopePattern predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
    Double isotopeScore = null;
    if ((checkIsotopes) && (detectedPattern != null)) {
        isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
        final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
        if (isotopeScore < minScore)
            return;
    }
    // MS/MS evaluation is slowest, so let's do it last
    Double msmsScore = null;
    Feature bestPeak = peakListRow.getBestPeak();
    RawDataFile dataFile = bestPeak.getDataFile();
    Map<DataPoint, String> msmsAnnotations = null;
    int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
    if ((checkMSMS) && (msmsScanNumber > 0)) {
        Scan msmsScan = dataFile.getScan(msmsScanNumber);
        String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
        MassList ms2MassList = msmsScan.getMassList(massListName);
        if (ms2MassList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
            return;
        }
        MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
        double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
        if (score != null) {
            msmsScore = score.getScore();
            msmsAnnotations = score.getAnnotation();
            // Check the MS/MS condition
            if (msmsScore < minMSMSScore)
                return;
        }
    }
    // Create a new formula entry
    final ResultFormula resultEntry = new ResultFormula(cdkFormula, predictedIsotopePattern, rdbeValue, isotopeScore, msmsScore, msmsAnnotations);
    // Add the new formula entry
    resultWindow.addNewListItem(resultEntry);
    foundFormulas++;
}
Also used : IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList) MSMSScore(net.sf.mzmine.modules.peaklistmethods.msms.msmsscore.MSMSScore)

Example 2 with MassList

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

the class Ms2SearchTask method simpleMS2similarity.

private Ms2SearchResult simpleMS2similarity(Scan scanMS2A, Scan scanMS2B, double intensityThreshold, MZTolerance mzRange, String massList) {
    double runningScoreTotal = 0.0;
    double mzRangePPM = mzRange.getPpmTolerance();
    List<DataPoint> matchedIons = new ArrayList<DataPoint>();
    if (scanMS2A == null || scanMS2B == null) {
        return null;
    }
    // Fetch centroided data
    MassList massListA = scanMS2A.getMassList(massListName);
    MassList massListB = scanMS2B.getMassList(massListName);
    if (massListA == null) {
        // Will this work properly? As this function isn't directly the task?
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Scan " + scanMS2A.getDataFile().getName() + " #" + scanMS2A.getScanNumber() + " does not have a mass list " + massListName);
        return null;
    }
    if (massListB == null) {
        // Will this work properly? As this function isn't directly the task?
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Scan " + scanMS2B.getDataFile().getName() + " #" + scanMS2B.getScanNumber() + " does not have a mass list " + massListName);
        return null;
    }
    DataPoint[] ionsA = null;
    DataPoint[] ionsB = null;
    ionsA = massListA.getDataPoints();
    ionsB = massListB.getDataPoints();
    if (ionsA == null || ionsB == null || ionsA.length == 0 || ionsB.length == 0) {
        // ionsB = scanMS2B.getDataPointsOverIntensity(intensityThreshold);
        return null;
    }
    // Compare every ion peak in MS2 scan A, to every ion peak in MS2 scan B.
    double ionsBMaxMZ = ionsB[ionsB.length - 1].getMZ();
    for (int i = 0; i < ionsA.length; i++) {
        double iMZ = ionsA[i].getMZ();
        double mzRangeAbsolute = iMZ * 1e-6 * mzRangePPM;
        if (iMZ - mzRangeAbsolute > ionsBMaxMZ)
            // Potential speedup heuristic. If any i is greater than the max of j, no more
            break;
        for (int j = 0; j < ionsB.length; j++) {
            double jMZ = ionsB[j].getMZ();
            if (iMZ < jMZ - mzRangeAbsolute)
                // Potential speedup heuristic. iMZ smaller than jMZ. Skip the rest of the j's as
                break;
            if (Math.abs(iMZ - jMZ) < mzRangeAbsolute) {
                runningScoreTotal += ionsA[i].getIntensity() * ionsB[j].getIntensity();
                matchedIons.add(ionsA[i]);
            }
        }
    }
    Ms2SearchResult result = new Ms2SearchResult(runningScoreTotal, "simple", matchedIons);
    return result;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 3 with MassList

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

the class MSMSExportModule method exportMSMS.

public static void exportMSMS(PeakListRow row) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(MSMSExportModule.class);
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return;
    File outputFile = parameters.getParameter(MSMSExportParameters.outputFile).getValue();
    String massListName = parameters.getParameter(MSMSExportParameters.massList).getValue();
    if ((outputFile == null) || (massListName == null))
        return;
    // Best peak always exists, because feature list row has at least one peak
    Feature bestPeak = row.getBestPeak();
    // Get the MS/MS scan number
    int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
    if (msmsScanNumber < 1) {
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no MS/MS scan for peak " + bestPeak);
        return;
    }
    // MS/MS scan must exist, because msmsScanNumber was > 0
    Scan msmsScan = bestPeak.getDataFile().getScan(msmsScanNumber);
    MassList massList = msmsScan.getMassList(massListName);
    if (massList == null) {
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no mass list called " + massListName + " for MS/MS scan #" + msmsScanNumber + " (" + bestPeak.getDataFile() + ")");
        return;
    }
    DataPoint[] peaks = massList.getDataPoints();
    try {
        FileWriter fileWriter = new FileWriter(outputFile);
        BufferedWriter writer = new BufferedWriter(fileWriter);
        for (DataPoint peak : peaks) {
            writer.write(peak.getMZ() + " " + peak.getIntensity());
            writer.newLine();
        }
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error writing to file " + outputFile + ": " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode) FileWriter(java.io.FileWriter) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) BufferedWriter(java.io.BufferedWriter) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) File(java.io.File) MassList(net.sf.mzmine.datamodel.MassList)

Example 4 with MassList

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

the class MZDistributionHistoTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting to build mz distribution histogram for " + dataFile);
    // all selected scans
    scans = scanSelection.getMatchingScans(dataFile);
    totalScans = scans.length;
    // histo data
    DoubleArrayList data = new DoubleArrayList();
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        // retention time in range
        if (!useRTRange || rtRange.contains(scan.getRetentionTime())) {
            // go through all mass lists
            MassList massList = scan.getMassList(massListName);
            if (massList == null) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
                return;
            }
            DataPoint[] mzValues = massList.getDataPoints();
            // insert all mz in order and count them
            Arrays.stream(mzValues).mapToDouble(dp -> dp.getMZ()).filter(mz -> mzRange.contains(mz)).forEach(mz -> data.add(mz));
            processedScans++;
        }
    }
    if (!data.isEmpty()) {
        // to array
        double[] histo = new double[data.size()];
        for (int i = 0; i < data.size(); i++) histo[i] = data.get(i);
        // create histogram dialog
        EHistogramDialog dialog = new EHistogramDialog("m/z distribution", "m/z", new HistogramData(histo), binWidth);
        dialog.setVisible(true);
    } else {
        throw new MSDKRuntimeException("Data was empty. Review your selected filters.");
    }
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished mz distribution histogram on " + dataFile);
}
Also used : HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) Scan(net.sf.mzmine.datamodel.Scan) Arrays(java.util.Arrays) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) Range(com.google.common.collect.Range) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Logger(java.util.logging.Logger) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) ParameterSet(net.sf.mzmine.parameters.ParameterSet) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) DataPoint(net.sf.mzmine.datamodel.DataPoint) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) Scan(net.sf.mzmine.datamodel.Scan) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 5 with MassList

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

the class ProjectTreeMouseHandler method handleDoubleClickEvent.

private void handleDoubleClickEvent(MouseEvent e) {
    TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY());
    if (clickedPath == null)
        return;
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent();
    Object clickedObject = node.getUserObject();
    if (clickedObject instanceof RawDataFile) {
        RawDataFile clickedFile = (RawDataFile) clickedObject;
        TICVisualizerModule.setupNewTICVisualizer(clickedFile);
    }
    if (clickedObject instanceof PeakList) {
        PeakList clickedPeakList = (PeakList) clickedObject;
        PeakListTableModule.showNewPeakListVisualizerWindow(clickedPeakList);
    }
    if (clickedObject instanceof Scan) {
        Scan clickedScan = (Scan) clickedObject;
        SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
    }
    if (clickedObject instanceof MassList) {
        MassList clickedMassList = (MassList) clickedObject;
        Scan clickedScan = clickedMassList.getScan();
        SpectraVisualizerWindow window = SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
        MassListDataSet dataset = new MassListDataSet(clickedMassList);
        window.addDataSet(dataset, Color.green);
    }
    if (clickedObject instanceof PeakListRow) {
        PeakListRow clickedPeak = (PeakListRow) clickedObject;
        PeakSummaryVisualizerModule.showNewPeakSummaryWindow(clickedPeak);
    }
}
Also used : SpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerWindow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassListDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.MassListDataSet) MassList(net.sf.mzmine.datamodel.MassList)

Aggregations

MassList (net.sf.mzmine.datamodel.MassList)36 Scan (net.sf.mzmine.datamodel.Scan)25 DataPoint (net.sf.mzmine.datamodel.DataPoint)24 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)14 Feature (net.sf.mzmine.datamodel.Feature)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)9 ArrayList (java.util.ArrayList)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 PeakList (net.sf.mzmine.datamodel.PeakList)5 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)4 Range (com.google.common.collect.Range)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 TreePath (javax.swing.tree.TreePath)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 MergedSpectrum (net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum)3 MsMsSpectraMergeModule (net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule)3 BufferedWriter (java.io.BufferedWriter)2