use of net.sf.mzmine.util.exceptions.MissingMassListException 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.exceptions.MissingMassListException in project mzmine2 by mzmine.
the class SiriusThread method run.
@Override
public void run() {
List<MsSpectrum> ms1list = new ArrayList<>(), ms2list = new ArrayList<>();
try {
Scan ms1Scan = peakListRow.getBestPeak().getRepresentativeScan();
Collection<Scan> top10ms2Scans = ScanUtils.selectBestMS2Scans(peakListRow, massListName, 10);
// Convert to MSDK data model
ms1list.add(new MZmineToMSDKMsScan(ms1Scan));
for (Scan s : top10ms2Scans) {
ms2list.add(new MZmineToMSDKMsScan(s));
}
} catch (MissingMassListException f) {
releaseResources();
task.remoteCancel("Scan does not have requested Mass List name [" + massListName + "]");
return;
}
FormulaConstraints constraints = ConstraintsGenerator.generateConstraint(range);
IonType siriusIon = IonTypeUtil.createIonType(ionType.toString());
List<IonAnnotation> siriusResults = null;
SiriusIdentificationMethod siriusMethod = null;
/*
* Code block below gives SiriusMethod specific amount of time to be executed, if it expires ->
* log error and continue
*/
try {
final SiriusIdentificationMethod method = new SiriusIdentificationMethod(ms1list, ms2list, peakListRow.getAverageMZ(), siriusIon, siriusCandidates, constraints, deviationPpm);
// On some spectra it may never stop (halting problem), that's why interruptable thread is
// used
final Future<List<IonAnnotation>> f = service.submit(() -> {
return method.execute();
});
siriusResults = f.get(siriusTimer, TimeUnit.SECONDS);
siriusMethod = method;
if (ms2list.isEmpty()) {
/* If no MSMS spectra - add sirius results */
addSiriusCompounds(siriusResults, peakListRow, siriusCandidates);
} else {
/* Initiate FingerId processing */
Ms2Experiment experiment = siriusMethod.getExperiment();
for (int index = 0; index < siriusCandidates; index++) {
SiriusIonAnnotation annotation = (SiriusIonAnnotation) siriusResults.get(index);
try {
FingerIdWebMethodTask task = new FingerIdWebMethodTask(annotation, experiment, fingeridCandidates, peakListRow);
MZmineCore.getTaskController().addTask(task, TaskPriority.NORMAL);
Thread.sleep(1000);
} catch (InterruptedException interrupt) {
logger.error("Processing of FingerWebMethods were interrupted");
/* If interrupted, store last item */
List<IonAnnotation> lastItem = new LinkedList<>();
lastItem.add(annotation);
addSiriusCompounds(lastItem, peakListRow, 1);
}
}
}
} catch (InterruptedException | TimeoutException ie) {
logger.error("Timeout on Sirius method expired, abort. Row id = {}", peakListRow.getID());
} catch (ExecutionException ce) {
logger.error("Concurrency error during Sirius method. Row id = {}", peakListRow.getID());
} finally {
// Do not forget to release resources!
releaseResources();
}
}
use of net.sf.mzmine.util.exceptions.MissingMassListException in project mzmine2 by mzmine.
the class SingleRowIdentificationTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
NumberFormat massFormater = MZmineCore.getConfiguration().getMZFormat();
ResultWindow window = new ResultWindow(peakListRow, this);
window.setTitle("SIRIUS/CSI-FingerID identification of " + massFormater.format(parentMass) + " m/z");
window.setVisible(true);
List<MsSpectrum> ms1list = new ArrayList<>(), ms2list = new ArrayList<>();
try {
Scan ms1Scan = peakListRow.getBestPeak().getRepresentativeScan();
Collection<Scan> top10ms2Scans = ScanUtils.selectBestMS2Scans(peakListRow, massListName, 10);
logger.debug("Adding MS1 scan " + ScanUtils.scanToString(ms1Scan, true) + " for SIRIUS identification");
// Convert to MSDK data model
ms1list.add(buildMSDKSpectrum(ms1Scan, massListName));
for (Scan ms2Scan : top10ms2Scans) {
logger.debug("Adding MS/MS scan " + ScanUtils.scanToString(ms2Scan, true) + " for SIRIUS identification");
ms2list.add(buildMSDKSpectrum(ms2Scan, massListName));
}
} catch (MissingMassListException f) {
showError(window, "Scan does not contain Mass List with requested name. [" + massListName + "]");
return;
}
// Use executor to run Sirius Identification Method as an Interruptable thread.
// Otherwise it may compute for too long (or even forever).
final ExecutorService service = Executors.newSingleThreadExecutor();
SiriusIdentificationMethod siriusMethod = null;
List<IonAnnotation> siriusResults = null;
/* Sirius processing */
try {
FormulaConstraints constraints = ConstraintsGenerator.generateConstraint(range);
IonType type = IonTypeUtil.createIonType(ionType.toString());
final SiriusIdentificationMethod method = new SiriusIdentificationMethod(ms1list, ms2list, parentMass, type, siriusCandidates, constraints, deviationPpm);
final Future<List<IonAnnotation>> f = service.submit(() -> {
return method.execute();
});
siriusResults = f.get(timer, TimeUnit.SECONDS);
siriusMethod = method;
} catch (InterruptedException | TimeoutException ie) {
logger.error("Timeout on Sirius method expired, abort.");
showError(window, String.format("Processing of the peaklist with mass %.2f by Sirius module expired.\n", parentMass) + "Reinitialize the task with larger Sirius Timer value.");
return;
} catch (ExecutionException ce) {
ce.printStackTrace();
logger.error("Concurrency error during Sirius method: " + ce.getMessage());
showError(window, String.format("Sirius failed to predict compounds from row with id = %d", peakListRow.getID()));
return;
}
/* FingerId processing */
if (!ms2list.isEmpty()) {
try {
latch = new CountDownLatch(siriusResults.size());
Ms2Experiment experiment = siriusMethod.getExperiment();
fingerTasks = new LinkedList<>();
/* Create a new FingerIdWebTask for each Sirius result */
for (IonAnnotation ia : siriusResults) {
SiriusIonAnnotation annotation = (SiriusIonAnnotation) ia;
FingerIdWebMethodTask task = new FingerIdWebMethodTask(annotation, experiment, fingerCandidates, window);
task.setLatch(latch);
fingerTasks.add(task);
MZmineCore.getTaskController().addTask(task, TaskPriority.NORMAL);
}
// Sleep for not overloading boecker-labs servers
Thread.sleep(1000);
} catch (InterruptedException interrupt) {
logger.error("Processing of FingerWebMethods were interrupted");
}
} else {
/* MS/MS spectrum is not present */
window.addListofItems(siriusMethod.getResult());
}
// If there was a FingerId processing, wait until subtasks finish
try {
if (latch != null)
latch.await();
} catch (InterruptedException e) {
}
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.util.exceptions.MissingMassListException 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.exceptions.MissingMassListException in project mzmine2 by mzmine.
the class ScanUtils method listAllScans.
/**
* List of all scans with n signals >= noiseLevel in the specified or first massList, if none was
* specified
*
* @param massListName the name or null/empty to always use the first masslist
* @param noiseLevel
* @param minNumberOfSignals
* @return
*/
@Nonnull
public static List<Scan> listAllScans(Scan[] scans, @Nullable String massListName, double noiseLevel, int minNumberOfSignals) throws MissingMassListException {
List<Scan> filtered = new ArrayList<>();
for (Scan scan : scans) {
// find mass list: with name or first
final MassList massList = getMassListOrFirst(scan, massListName);
if (massList == null)
throw new MissingMassListException("", massListName);
// minimum number of signals >= noiseLevel
int signals = 0;
for (DataPoint dp : massList.getDataPoints()) if (dp.getIntensity() >= noiseLevel)
signals++;
if (signals >= minNumberOfSignals)
filtered.add(scan);
}
return filtered;
}
Aggregations