Search in sources :

Example 1 with AutoLibraryParser

use of net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser in project mzmine2 by mzmine.

the class SelectedRowsLocalSpectralDBSearchTask method parseFile.

/**
 * Load all library entries from data base file
 *
 * @param dataBaseFile
 * @return
 */
private List<RowsSpectralMatchTask> parseFile(File dataBaseFile) throws UnsupportedFormatException, IOException {
    // 
    List<RowsSpectralMatchTask> tasks = new ArrayList<>();
    AutoLibraryParser parser = new AutoLibraryParser(100, new LibraryEntryProcessor() {

        @Override
        public void processNextEntries(List<SpectralDBEntry> list, int alreadyProcessed) {
            // start last task
            RowsSpectralMatchTask task = new RowsSpectralMatchTask(peakListRows.length + " rows", peakListRows, parameters, alreadyProcessed + 1, list, (match) -> {
                // one selected row -> show in dialog
                if (resultWindow != null) {
                    resultWindow.addMatches(match);
                    resultWindow.revalidate();
                    resultWindow.repaint();
                }
            });
            MZmineCore.getTaskController().addTask(task);
            tasks.add(task);
        }
    });
    // return tasks
    parser.parse(this, dataBaseFile);
    return tasks;
}
Also used : MZmineCore(net.sf.mzmine.main.MZmineCore) AutoLibraryParser(net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) LibraryEntryProcessor(net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor) IOException(java.io.IOException) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) Logger(java.util.logging.Logger) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) File(java.io.File) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) List(java.util.List) ParameterSet(net.sf.mzmine.parameters.ParameterSet) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) Desktop(net.sf.mzmine.desktop.Desktop) Nonnull(javax.annotation.Nonnull) PeakListTable(net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTable) AutoLibraryParser(net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser) ArrayList(java.util.ArrayList) LibraryEntryProcessor(net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)

Example 2 with AutoLibraryParser

use of net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser in project mzmine2 by mzmine.

the class SpectraIdentificationSpectralDatabaseTask method parseFile.

/**
 * Load all library entries from data base file
 *
 * @param dataBaseFile
 * @return
 */
private List<SpectralMatchTask> parseFile(File dataBaseFile) {
    // one task for every 1000 entries
    List<SpectralMatchTask> tasks = new ArrayList<>();
    AutoLibraryParser parser = new AutoLibraryParser(1000, new LibraryEntryProcessor() {

        @Override
        public void processNextEntries(List<SpectralDBEntry> list, int alreadyProcessed) {
            // start last task
            SpectralMatchTask task = new SpectralMatchTask(parameters, alreadyProcessed + 1, list, spectraPlot, currentScan, resultWindow);
            MZmineCore.getTaskController().addTask(task);
            tasks.add(task);
        }
    });
    // return tasks
    try {
        // parse and create spectral matching tasks for batches of entries
        parser.parse(this, dataBaseFile);
        return tasks;
    } catch (UnsupportedFormatException | IOException e) {
        logger.log(Level.WARNING, "Library parsing error for file " + dataBaseFile.getAbsolutePath(), e);
        return new ArrayList<>();
    }
}
Also used : ArrayList(java.util.ArrayList) LibraryEntryProcessor(net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) AutoLibraryParser(net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser)

Example 3 with AutoLibraryParser

use of net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser in project mzmine2 by mzmine.

the class PrecursorDBSearchTask method parseFile.

/**
 * Load all library entries from data base file
 *
 * @param dataBaseFile
 * @return
 */
private List<AbstractTask> parseFile(File dataBaseFile) throws UnsupportedFormatException, IOException {
    // 
    List<AbstractTask> tasks = new ArrayList<>();
    AutoLibraryParser parser = new AutoLibraryParser(100, new LibraryEntryProcessor() {

        @Override
        public void processNextEntries(List<SpectralDBEntry> list, int alreadyProcessed) {
            AbstractTask task = new AbstractTask() {

                private int total = peakList.getNumberOfRows();

                private int done = 0;

                @Override
                public void run() {
                    for (PeakListRow row : peakList.getRows()) {
                        if (this.isCanceled())
                            break;
                        for (SpectralDBEntry db : list) {
                            if (this.isCanceled())
                                break;
                            if (checkRT(row, (Double) db.getField(DBEntryField.RT).orElse(null)) && checkMZ(row, db.getPrecursorMZ())) {
                                // add identity
                                row.addPeakIdentity(new PrecursorDBPeakIdentity(db, PrecursorDBSearchModule.MODULE_NAME), false);
                                matches.getAndIncrement();
                            }
                        }
                        done++;
                    }
                    if (!this.isCanceled())
                        setStatus(TaskStatus.FINISHED);
                }

                @Override
                public String getTaskDescription() {
                    return "Checking for precursors: " + alreadyProcessed + 1 + " - " + alreadyProcessed + list.size();
                }

                @Override
                public double getFinishedPercentage() {
                    if (total == 0)
                        return 0;
                    return done / (double) total;
                }
            };
            // start last task
            MZmineCore.getTaskController().addTask(task);
            tasks.add(task);
        }
    });
    // return tasks
    parser.parse(this, dataBaseFile);
    return tasks;
}
Also used : PrecursorDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.PrecursorDBPeakIdentity) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) AutoLibraryParser(net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser) ArrayList(java.util.ArrayList) LibraryEntryProcessor(net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)

Example 4 with AutoLibraryParser

use of net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser in project mzmine2 by mzmine.

the class LocalSpectralDBSearchTask method parseFile.

/**
 * Load all library entries from data base file
 *
 * @param dataBaseFile
 * @return
 */
private List<RowsSpectralMatchTask> parseFile(File dataBaseFile) throws UnsupportedFormatException, IOException {
    // 
    List<RowsSpectralMatchTask> tasks = new ArrayList<>();
    AutoLibraryParser parser = new AutoLibraryParser(100, new LibraryEntryProcessor() {

        @Override
        public void processNextEntries(List<SpectralDBEntry> list, int alreadyProcessed) {
            // start last task
            RowsSpectralMatchTask task = new RowsSpectralMatchTask(peakList.getName(), rows, parameters, alreadyProcessed + 1, list);
            MZmineCore.getTaskController().addTask(task);
            tasks.add(task);
        }
    });
    // return tasks
    parser.parse(this, dataBaseFile);
    return tasks;
}
Also used : AutoLibraryParser(net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser) ArrayList(java.util.ArrayList) LibraryEntryProcessor(net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)

Aggregations

ArrayList (java.util.ArrayList)4 SpectralDBEntry (net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)4 AutoLibraryParser (net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser)4 LibraryEntryProcessor (net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor)4 IOException (java.io.IOException)2 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)2 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)2 File (java.io.File)1 List (java.util.List)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Nonnull (javax.annotation.Nonnull)1 Desktop (net.sf.mzmine.desktop.Desktop)1 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)1 MZmineCore (net.sf.mzmine.main.MZmineCore)1 PeakListTable (net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTable)1 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)1 ParameterSet (net.sf.mzmine.parameters.ParameterSet)1 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)1