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);
}
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);
}
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);
}
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;
}
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<>();
}
}
Aggregations