Search in sources :

Example 6 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class SelectedRowsLocalSpectralDBSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    if (peakListRows.length == 1) {
        // add result frame
        resultWindow = new SpectraIdentificationResultsWindow();
        resultWindow.setVisible(true);
    } else {
        resultWindow = null;
    }
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        count += tasks.get(i).getCount();
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + count + " spectral library matches");
    if (resultWindow != null) {
        resultWindow.setTitle("Matched " + count + " compounds for feature list row: " + peakListRows[0]);
        resultWindow.setMatchingFinished();
        resultWindow.revalidate();
        resultWindow.repaint();
    }
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    // work around to update feature list identities
    if (table.getRowCount() > 0)
        table.setRowSelectionInterval(0, 0);
    setStatus(TaskStatus.FINISHED);
}
Also used : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 7 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class LocalSpectralDBSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        count += tasks.get(i).getCount();
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + count + " spectral library matches");
    // Add task description to peakList
    peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak identification using MS/MS spectral database " + dataBaseFile, parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
}
Also used : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 8 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class FragmentSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting fragments search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Start with the highest peaks
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
    // Compare each two rows against each other
    for (int i = 0; i < totalRows; i++) {
        for (int j = i + 1; j < rows.length; j++) {
            // Task canceled?
            if (isCanceled())
                return;
            // smaller one may be a fragment
            if (rows[i].getAverageMZ() > rows[j].getAverageMZ()) {
                if (checkFragment(rows[i], rows[j]))
                    addFragmentInfo(rows[i], rows[j]);
            } else {
                if (checkFragment(rows[j], rows[i]))
                    addFragmentInfo(rows[j], rows[i]);
            }
        }
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of fragments", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished fragments search in " + peakList);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter) DataPoint(net.sf.mzmine.datamodel.DataPoint) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 9 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class PeakListIdentificationTask method retrieveIdentification.

/**
 * Search the database for the peak's identity.
 *
 * @param row the feature list row.
 * @throws IOException if there are i/o problems.
 */
private void retrieveIdentification(final PeakListRow row) throws IOException {
    currentRow = row;
    // Determine peak charge.
    final Feature bestPeak = row.getBestPeak();
    int charge = bestPeak.getCharge();
    if (charge <= 0) {
        charge = 1;
    }
    // Calculate mass value.
    final double massValue = row.getAverageMZ() * (double) charge - ionType.getAddedMass();
    // Isotope pattern.
    final IsotopePattern rowIsotopePattern = bestPeak.getIsotopePattern();
    // Process each one of the result ID's.
    final String[] findCompounds = gateway.findCompounds(massValue, mzTolerance, numOfResults, db.getParameterSet());
    for (int i = 0; !isCanceled() && i < findCompounds.length; i++) {
        final DBCompound compound = gateway.getCompound(findCompounds[i], db.getParameterSet());
        // In case we failed to retrieve data, skip this compound
        if (compound == null)
            continue;
        final String formula = compound.getPropertyValue(PeakIdentity.PROPERTY_FORMULA);
        // If required, check isotope score.
        if (isotopeFilter && rowIsotopePattern != null && formula != null) {
            // First modify the formula according to ionization.
            final String adjustedFormula = FormulaUtils.ionizeFormula(formula, ionType, charge);
            LOG.finest("Calculating isotope pattern for compound formula " + formula + " adjusted to " + adjustedFormula);
            // Generate IsotopePattern for this compound
            final IsotopePattern compoundIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, MIN_ABUNDANCE, charge, ionType.getPolarity());
            // Check isotope pattern match
            boolean check = IsotopePatternScoreCalculator.checkMatch(rowIsotopePattern, compoundIsotopePattern, isotopeFilterParameters);
            if (!check)
                continue;
        }
        // Add the retrieved identity to the feature list row
        row.addPeakIdentity(compound, false);
        // Notify the GUI about the change in the project
        MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(row, false);
        // Repaint the window to reflect the change in the feature list
        Desktop desktop = MZmineCore.getDesktop();
        if (!(desktop instanceof HeadLessDesktop))
            desktop.getMainWindow().repaint();
    }
}
Also used : HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Feature(net.sf.mzmine.datamodel.Feature) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 10 with HeadLessDesktop

use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.

the class Ms2SearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting MS2 similarity search between " + peakList1 + " and " + peakList2 + " with mz tolerance:" + mzTolerance.getPpmTolerance());
    Ms2SearchResult searchResult;
    PeakListRow[] rows1 = peakList1.getRows();
    PeakListRow[] rows2 = peakList2.getRows();
    int rows1Length = rows1.length;
    int rows2Length = rows2.length;
    totalRows = rows1Length;
    for (int i = 0; i < rows1Length; i++) {
        for (int j = 0; j < rows2Length; j++) {
            Feature featureA = rows1[i].getBestPeak();
            Feature featureB = rows2[j].getBestPeak();
            // Complication. The "best" peak, may not have the "best" fragmentation
            Scan scanA = rows1[i].getBestFragmentation();
            Scan scanB = rows2[j].getBestFragmentation();
            searchResult = simpleMS2similarity(scanA, scanB, intensityThreshold, mzTolerance, massListName);
            // Report the final score to the peaklist identity
            if (searchResult != null && searchResult.getScore() > scoreThreshold && searchResult.getNumIonsMatched() >= minimumIonsMatched)
                this.addMS2Identity(rows1[i], featureA, featureB, searchResult);
            if (isCanceled())
                return;
        }
        // Update progress bar
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList1).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of similar MS2s", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished MS2 similarity search for " + peakList1 + "against" + peakList2);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Aggregations

Desktop (net.sf.mzmine.desktop.Desktop)17 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)10 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 IOException (java.io.IOException)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)4 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)4 DataPoint (net.sf.mzmine.datamodel.DataPoint)3 Feature (net.sf.mzmine.datamodel.Feature)2 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)2 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)2 File (java.io.File)1 FileReader (java.io.FileReader)1 Locale (java.util.Locale)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 Scan (net.sf.mzmine.datamodel.Scan)1 MainWindow (net.sf.mzmine.desktop.impl.MainWindow)1 MZmineConfigurationImpl (net.sf.mzmine.main.impl.MZmineConfigurationImpl)1