Search in sources :

Example 1 with SpectralDBEntry

use of net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry in project mzmine2 by mzmine.

the class GnpsJsonParser method getDBEntry.

public SpectralDBEntry getDBEntry(JsonObject main) {
    // extract dps
    DataPoint[] dps = getDataPoints(main);
    if (dps == null)
        return null;
    // extract meta data
    Map<DBEntryField, Object> map = new EnumMap<>(DBEntryField.class);
    for (DBEntryField f : DBEntryField.values()) {
        String id = f.getGnpsJsonID();
        if (id != null && !id.isEmpty()) {
            try {
                Object o = null;
                if (f.getObjectClass() == Double.class || f.getObjectClass() == Integer.class || f.getObjectClass() == Float.class) {
                    o = main.getJsonNumber(id);
                } else {
                    o = main.getString(id, null);
                    if (o != null && o.equals("N/A"))
                        o = null;
                }
                // add value
                if (o != null) {
                    if (o instanceof JsonNumber) {
                        if (f.getObjectClass().equals(Integer.class)) {
                            o = ((JsonNumber) o).intValue();
                        } else {
                            o = ((JsonNumber) o).doubleValue();
                        }
                    }
                    // add
                    map.put(f, o);
                }
            } catch (Exception e) {
                logger.log(Level.WARNING, "Cannot convert value to its type", e);
            }
        }
    }
    return new SpectralDBEntry(map, dps);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) JsonNumber(javax.json.JsonNumber) JsonObject(javax.json.JsonObject) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) DBEntryField(net.sf.mzmine.util.spectraldb.entry.DBEntryField) EnumMap(java.util.EnumMap) IOException(java.io.IOException)

Example 2 with SpectralDBEntry

use of net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry in project mzmine2 by mzmine.

the class SpectralMatchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    // check for mass list
    DataPoint[] spectraMassList;
    try {
        spectraMassList = getDataPoints(currentScan);
    } catch (MissingMassListException e) {
        // no mass list
        setStatus(TaskStatus.ERROR);
        setErrorMessage(MessageFormat.format("No masslist for name: {0} in scan {1} of raw file {2}", massListName, currentScan.getScanNumber(), currentScan.getDataFile().getName()));
        return;
    }
    // remove 13C isotopes
    if (removeIsotopes)
        spectraMassList = removeIsotopes(spectraMassList);
    setStatus(TaskStatus.PROCESSING);
    try {
        totalSteps = list.size();
        matches = new ArrayList<>();
        for (SpectralDBEntry ident : list) {
            if (isCanceled()) {
                logger.info("Added " + count + " spectral library matches (before being cancelled)");
                repaintWindow();
                return;
            }
            SpectralSimilarity sim = spectraDBMatch(spectraMassList, ident);
            if (sim != null && (!needsIsotopePattern || checkForIsotopePattern(sim, mzToleranceSpectra, minMatchedIsoSignals))) {
                count++;
                // use SpectralDBPeakIdentity to store all results similar to peaklist method
                matches.add(new SpectralDBPeakIdentity(currentScan, massListName, ident, sim, SpectraIdentificationSpectralDatabaseModule.MODULE_NAME));
            }
            // next row
            finishedSteps++;
        }
        addIdentities(matches);
        logger.info("Added " + count + " spectral library matches");
        // check if no match was found
        if (count == 0) {
            logger.log(Level.WARNING, "No data base matches found");
            setErrorMessage("No data base matches found. Spectral data base matching failed");
            list = null;
            return;
        }
    } catch (Exception e) {
        setStatus(TaskStatus.ERROR);
        logger.log(Level.SEVERE, "Spectral data base matching failed", e);
        setErrorMessage("Spectral data base matching failed");
        return;
    }
    // Repaint the window to reflect the change in the feature list
    repaintWindow();
    list = null;
    setStatus(TaskStatus.FINISHED);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException)

Example 3 with SpectralDBEntry

use of net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry in project mzmine2 by mzmine.

the class RowsSpectralMatchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    for (PeakListRow row : rows) {
        if (isCanceled()) {
            logger.info("Added " + count + " spectral library matches (before being cancelled)");
            repaintWindow();
            return;
        }
        try {
            // All MS2 or only best MS2 scan
            // best MS1 scan
            // check for MS1 or MSMS scan
            List<Scan> scans = getScans(row);
            List<DataPoint[]> rowMassLists = new ArrayList<>();
            for (Scan scan : scans) {
                // get mass list and perform deisotoping if active
                DataPoint[] rowMassList = getDataPoints(scan, true);
                if (removeIsotopes)
                    rowMassList = removeIsotopes(rowMassList);
                rowMassLists.add(rowMassList);
            }
            // match against all library entries
            for (SpectralDBEntry ident : list) {
                SpectralDBPeakIdentity best = null;
                // match all scans against this ident to find best match
                for (int i = 0; i < scans.size(); i++) {
                    SpectralSimilarity sim = spectraDBMatch(row, rowMassLists.get(i), ident);
                    if (sim != null && (!needsIsotopePattern || SpectralMatchTask.checkForIsotopePattern(sim, mzToleranceSpectra, minMatchedIsoSignals)) && (best == null || best.getSimilarity().getScore() < sim.getScore())) {
                        best = new SpectralDBPeakIdentity(scans.get(i), massListName, ident, sim, METHOD);
                    }
                }
                // has match?
                if (best != null) {
                    addIdentity(row, best);
                    count++;
                }
            }
            // sort identities based on similarity score
            SortSpectralDBIdentitiesTask.sortIdentities(row);
        } catch (MissingMassListException e) {
            logger.log(Level.WARNING, "No mass list in spectrum for rowID=" + row.getID(), e);
            errorCounter++;
        }
        // check for max error (missing masslist)
        if (errorCounter > MAX_ERROR) {
            logger.log(Level.WARNING, "Data base matching failed. To many missing mass lists ");
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Data base matching failed. To many missing mass lists ");
            list = null;
            return;
        }
        // next row
        finishedRows++;
    }
    if (count > 0)
        logger.info("Added " + count + " spectral library matches");
    // Repaint the window to reflect the change in the feature list
    repaintWindow();
    list = null;
    setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) ArrayList(java.util.ArrayList) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) Scan(net.sf.mzmine.datamodel.Scan) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) DataPoint(net.sf.mzmine.datamodel.DataPoint) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException)

Example 4 with SpectralDBEntry

use of net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry 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 5 with SpectralDBEntry

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

Aggregations

SpectralDBEntry (net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry)11 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)7 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)5 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 EnumMap (java.util.EnumMap)4 DBEntryField (net.sf.mzmine.util.spectraldb.entry.DBEntryField)4 AutoLibraryParser (net.sf.mzmine.util.spectraldb.parser.AutoLibraryParser)4 LibraryEntryProcessor (net.sf.mzmine.util.spectraldb.parser.LibraryEntryProcessor)4 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)3 JsonObject (javax.json.JsonObject)2 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)2 MissingMassListException (net.sf.mzmine.util.exceptions.MissingMassListException)2 SpectralSimilarity (net.sf.mzmine.util.scans.similarity.SpectralSimilarity)2 SpectralDBPeakIdentity (net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity)2 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)2 File (java.io.File)1 StringReader (java.io.StringReader)1