Search in sources :

Example 1 with PrecursorDBPeakIdentity

use of net.sf.mzmine.util.spectraldb.entry.PrecursorDBPeakIdentity 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)

Aggregations

ArrayList (java.util.ArrayList)1 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)1 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)1 PrecursorDBPeakIdentity (net.sf.mzmine.util.spectraldb.entry.PrecursorDBPeakIdentity)1 SpectralDBEntry (net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)1 AutoLibraryParser (net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser)1 LibraryEntryProcessor (net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor)1