use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class CombinedXICComponent method paint.
public void paint(Graphics g) {
super.paint(g);
// use Graphics2D for antialiasing
Graphics2D g2 = (Graphics2D) g;
// turn on antialiasing
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// get canvas size
Dimension size = getSize();
int colorIndex = 0;
for (Feature peak : peaks) {
// set color for current XIC
g2.setColor(plotColors[colorIndex]);
colorIndex = (colorIndex + 1) % plotColors.length;
// if we have no data, just return
if ((peak == null) || (peak.getScanNumbers().length == 0))
continue;
// get scan numbers, one data point per each scan
int[] scanNumbers = peak.getScanNumbers();
// for each datapoint, find [X:Y] coordinates of its point in
// painted image
int[] xValues = new int[scanNumbers.length + 2];
int[] yValues = new int[scanNumbers.length + 2];
// find one datapoint with maximum intensity in each scan
for (int i = 0; i < scanNumbers.length; i++) {
double dataPointIntensity = 0;
DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
if (dataPoint != null)
dataPointIntensity = dataPoint.getIntensity();
// get retention time (X value)
double retentionTime = peak.getDataFile().getScan(scanNumbers[i]).getRetentionTime();
// calculate [X:Y] coordinates
xValues[i + 1] = (int) Math.floor((retentionTime - rtRange.lowerEndpoint()) / (rtRange.upperEndpoint() - rtRange.lowerEndpoint()) * (size.width - 1));
yValues[i + 1] = size.height - (int) Math.floor(dataPointIntensity / maxIntensity * (size.height - 1));
}
// add first point
xValues[0] = xValues[1];
yValues[0] = size.height - 1;
// add terminal point
xValues[xValues.length - 1] = xValues[xValues.length - 2];
yValues[yValues.length - 1] = size.height - 1;
// draw the peak shape
g2.drawPolyline(xValues, yValues, xValues.length);
}
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class SingleRowPredictionTask method checkConstraints.
private void checkConstraints(IMolecularFormula cdkFormula) {
// Check elemental ratios
if (checkRatios) {
boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
if (!check)
return;
}
Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
// Check RDBE condition
if (checkRDBE && (rdbeValue != null)) {
boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
if (!check)
return;
}
// Calculate isotope similarity score
final IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
final String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
final String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
// Fixed min abundance
final double minPredictedAbundance = 0.00001;
final IsotopePattern predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
Double isotopeScore = null;
if ((checkIsotopes) && (detectedPattern != null)) {
isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
if (isotopeScore < minScore)
return;
}
// MS/MS evaluation is slowest, so let's do it last
Double msmsScore = null;
Feature bestPeak = peakListRow.getBestPeak();
RawDataFile dataFile = bestPeak.getDataFile();
Map<DataPoint, String> msmsAnnotations = null;
int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
if ((checkMSMS) && (msmsScanNumber > 0)) {
Scan msmsScan = dataFile.getScan(msmsScanNumber);
String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
MassList ms2MassList = msmsScan.getMassList(massListName);
if (ms2MassList == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
return;
}
MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
if (score != null) {
msmsScore = score.getScore();
msmsAnnotations = score.getAnnotation();
// Check the MS/MS condition
if (msmsScore < minMSMSScore)
return;
}
}
// Create a new formula entry
final ResultFormula resultEntry = new ResultFormula(cdkFormula, predictedIsotopePattern, rdbeValue, isotopeScore, msmsScore, msmsAnnotations);
// Add the new formula entry
resultWindow.addNewListItem(resultEntry);
foundFormulas++;
}
use of net.sf.mzmine.datamodel.Feature 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.datamodel.Feature in project mzmine2 by mzmine.
the class ResultWindow method actionPerformed.
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("ADD")) {
int index = IDList.getSelectedRow();
if (index < 0) {
MZmineCore.getDesktop().displayMessage(this, "Select one result to add as compound identity");
return;
}
index = IDList.convertRowIndexToModel(index);
peakListRow.addPeakIdentity(listElementModel.getCompoundAt(index), false);
// Notify the GUI about the change in the project
MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(peakListRow, false);
// Repaint the window to reflect the change in the feature list
MZmineCore.getDesktop().getMainWindow().repaint();
dispose();
}
if (command.equals("VIEWER")) {
int index = IDList.getSelectedRow();
if (index < 0) {
MZmineCore.getDesktop().displayMessage(this, "Select one result to display molecule structure");
return;
}
index = IDList.convertRowIndexToModel(index);
DBCompound compound = listElementModel.getCompoundAt(index);
URL url2D = compound.get2DStructureURL();
URL url3D = compound.get3DStructureURL();
String name = compound.getName() + " (" + compound.getPropertyValue(PeakIdentity.PROPERTY_ID) + ")";
MolStructureViewer viewer = new MolStructureViewer(name, url2D, url3D);
viewer.setVisible(true);
}
if (command.equals("ISOTOPE_VIEWER")) {
int index = IDList.getSelectedRow();
if (index < 0) {
MZmineCore.getDesktop().displayMessage(this, "Select one result to display the isotope pattern");
return;
}
index = IDList.convertRowIndexToModel(index);
final IsotopePattern predictedPattern = listElementModel.getCompoundAt(index).getIsotopePattern();
if (predictedPattern == null)
return;
Feature peak = peakListRow.getBestPeak();
RawDataFile dataFile = peak.getDataFile();
int scanNumber = peak.getRepresentativeScanNumber();
SpectraVisualizerModule.showNewSpectrumWindow(dataFile, scanNumber, null, peak.getIsotopePattern(), predictedPattern);
}
if (command.equals("BROWSER")) {
int index = IDList.getSelectedRow();
if (index < 0) {
MZmineCore.getDesktop().displayMessage(this, "Select one compound to display in a web browser");
return;
}
index = IDList.convertRowIndexToModel(index);
logger.finest("Launching default browser to display compound details");
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
DBCompound compound = listElementModel.getCompoundAt(index);
String urlString = compound.getPropertyValue(PeakIdentity.PROPERTY_URL);
if ((urlString == null) || (urlString.length() == 0))
return;
try {
URL compoundURL = new URL(urlString);
desktop.browse(compoundURL.toURI());
} catch (Exception ex) {
logger.severe("Error trying to launch default browser: " + ex.getMessage());
}
}
}
use of net.sf.mzmine.datamodel.Feature 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