use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.
the class SelectedRowsLocalSpectralDBSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
int count = 0;
if (peakListRows.length == 1) {
// add result frame
resultWindow = new SpectraIdentificationResultsWindow();
resultWindow.setVisible(true);
} else {
resultWindow = null;
}
try {
tasks = parseFile(dataBaseFile);
totalTasks = tasks.size();
if (!tasks.isEmpty()) {
// wait for the tasks to finish
while (!isCanceled() && !tasks.isEmpty()) {
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
count += tasks.get(i).getCount();
tasks.remove(i);
i--;
}
}
// wait for all sub tasks to finish
try {
Thread.sleep(100);
} catch (Exception e) {
cancel();
}
}
// cancelled
if (isCanceled()) {
tasks.stream().forEach(AbstractTask::cancel);
}
} else {
setStatus(TaskStatus.ERROR);
setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
setStatus(TaskStatus.ERROR);
setErrorMessage(e.toString());
}
logger.info("Added " + count + " spectral library matches");
if (resultWindow != null) {
resultWindow.setTitle("Matched " + count + " compounds for feature list row: " + peakListRows[0]);
resultWindow.setMatchingFinished();
resultWindow.revalidate();
resultWindow.repaint();
}
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
// work around to update feature list identities
if (table.getRowCount() > 0)
table.setRowSelectionInterval(0, 0);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.
the class LocalSpectralDBSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
int count = 0;
try {
tasks = parseFile(dataBaseFile);
totalTasks = tasks.size();
if (!tasks.isEmpty()) {
// wait for the tasks to finish
while (!isCanceled() && !tasks.isEmpty()) {
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
count += tasks.get(i).getCount();
tasks.remove(i);
i--;
}
}
// wait for all sub tasks to finish
try {
Thread.sleep(100);
} catch (Exception e) {
cancel();
}
}
// cancelled
if (isCanceled()) {
tasks.stream().forEach(AbstractTask::cancel);
}
} else {
setStatus(TaskStatus.ERROR);
setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
setStatus(TaskStatus.ERROR);
setErrorMessage(e.toString());
}
logger.info("Added " + count + " spectral library matches");
// Add task description to peakList
peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak identification using MS/MS spectral database " + dataBaseFile, parameters));
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.
the class FragmentSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Starting fragments search in " + peakList);
PeakListRow[] rows = peakList.getRows();
totalRows = rows.length;
// Start with the highest peaks
Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
// Compare each two rows against each other
for (int i = 0; i < totalRows; i++) {
for (int j = i + 1; j < rows.length; j++) {
// Task canceled?
if (isCanceled())
return;
// smaller one may be a fragment
if (rows[i].getAverageMZ() > rows[j].getAverageMZ()) {
if (checkFragment(rows[i], rows[j]))
addFragmentInfo(rows[i], rows[j]);
} else {
if (checkFragment(rows[j], rows[i]))
addFragmentInfo(rows[j], rows[i]);
}
}
finishedRows++;
}
// Add task description to peakList
((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of fragments", parameters));
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
setStatus(TaskStatus.FINISHED);
logger.info("Finished fragments search in " + peakList);
}
use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.
the class PeakListIdentificationTask method retrieveIdentification.
/**
* Search the database for the peak's identity.
*
* @param row the feature list row.
* @throws IOException if there are i/o problems.
*/
private void retrieveIdentification(final PeakListRow row) throws IOException {
currentRow = row;
// Determine peak charge.
final Feature bestPeak = row.getBestPeak();
int charge = bestPeak.getCharge();
if (charge <= 0) {
charge = 1;
}
// Calculate mass value.
final double massValue = row.getAverageMZ() * (double) charge - ionType.getAddedMass();
// Isotope pattern.
final IsotopePattern rowIsotopePattern = bestPeak.getIsotopePattern();
// Process each one of the result ID's.
final String[] findCompounds = gateway.findCompounds(massValue, mzTolerance, numOfResults, db.getParameterSet());
for (int i = 0; !isCanceled() && i < findCompounds.length; i++) {
final DBCompound compound = gateway.getCompound(findCompounds[i], db.getParameterSet());
// In case we failed to retrieve data, skip this compound
if (compound == null)
continue;
final String formula = compound.getPropertyValue(PeakIdentity.PROPERTY_FORMULA);
// If required, check isotope score.
if (isotopeFilter && rowIsotopePattern != null && formula != null) {
// First modify the formula according to ionization.
final String adjustedFormula = FormulaUtils.ionizeFormula(formula, ionType, charge);
LOG.finest("Calculating isotope pattern for compound formula " + formula + " adjusted to " + adjustedFormula);
// Generate IsotopePattern for this compound
final IsotopePattern compoundIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, MIN_ABUNDANCE, charge, ionType.getPolarity());
// Check isotope pattern match
boolean check = IsotopePatternScoreCalculator.checkMatch(rowIsotopePattern, compoundIsotopePattern, isotopeFilterParameters);
if (!check)
continue;
}
// Add the retrieved identity to the feature list row
row.addPeakIdentity(compound, false);
// Notify the GUI about the change in the project
MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(row, false);
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
}
}
use of net.sf.mzmine.desktop.impl.HeadLessDesktop in project mzmine2 by mzmine.
the class Ms2SearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Starting MS2 similarity search between " + peakList1 + " and " + peakList2 + " with mz tolerance:" + mzTolerance.getPpmTolerance());
Ms2SearchResult searchResult;
PeakListRow[] rows1 = peakList1.getRows();
PeakListRow[] rows2 = peakList2.getRows();
int rows1Length = rows1.length;
int rows2Length = rows2.length;
totalRows = rows1Length;
for (int i = 0; i < rows1Length; i++) {
for (int j = 0; j < rows2Length; j++) {
Feature featureA = rows1[i].getBestPeak();
Feature featureB = rows2[j].getBestPeak();
// Complication. The "best" peak, may not have the "best" fragmentation
Scan scanA = rows1[i].getBestFragmentation();
Scan scanB = rows2[j].getBestFragmentation();
searchResult = simpleMS2similarity(scanA, scanB, intensityThreshold, mzTolerance, massListName);
// Report the final score to the peaklist identity
if (searchResult != null && searchResult.getScore() > scoreThreshold && searchResult.getNumIonsMatched() >= minimumIonsMatched)
this.addMS2Identity(rows1[i], featureA, featureB, searchResult);
if (isCanceled())
return;
}
// Update progress bar
finishedRows++;
}
// Add task description to peakList
((SimplePeakList) peakList1).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of similar MS2s", parameters));
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
setStatus(TaskStatus.FINISHED);
logger.info("Finished MS2 similarity search for " + peakList1 + "against" + peakList2);
}
Aggregations