use of net.sf.mzmine.datamodel.MassList 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.MassList in project mzmine2 by mzmine.
the class Ms2SearchTask method simpleMS2similarity.
private Ms2SearchResult simpleMS2similarity(Scan scanMS2A, Scan scanMS2B, double intensityThreshold, MZTolerance mzRange, String massList) {
double runningScoreTotal = 0.0;
double mzRangePPM = mzRange.getPpmTolerance();
List<DataPoint> matchedIons = new ArrayList<DataPoint>();
if (scanMS2A == null || scanMS2B == null) {
return null;
}
// Fetch centroided data
MassList massListA = scanMS2A.getMassList(massListName);
MassList massListB = scanMS2B.getMassList(massListName);
if (massListA == null) {
// Will this work properly? As this function isn't directly the task?
setStatus(TaskStatus.ERROR);
setErrorMessage("Scan " + scanMS2A.getDataFile().getName() + " #" + scanMS2A.getScanNumber() + " does not have a mass list " + massListName);
return null;
}
if (massListB == null) {
// Will this work properly? As this function isn't directly the task?
setStatus(TaskStatus.ERROR);
setErrorMessage("Scan " + scanMS2B.getDataFile().getName() + " #" + scanMS2B.getScanNumber() + " does not have a mass list " + massListName);
return null;
}
DataPoint[] ionsA = null;
DataPoint[] ionsB = null;
ionsA = massListA.getDataPoints();
ionsB = massListB.getDataPoints();
if (ionsA == null || ionsB == null || ionsA.length == 0 || ionsB.length == 0) {
// ionsB = scanMS2B.getDataPointsOverIntensity(intensityThreshold);
return null;
}
// Compare every ion peak in MS2 scan A, to every ion peak in MS2 scan B.
double ionsBMaxMZ = ionsB[ionsB.length - 1].getMZ();
for (int i = 0; i < ionsA.length; i++) {
double iMZ = ionsA[i].getMZ();
double mzRangeAbsolute = iMZ * 1e-6 * mzRangePPM;
if (iMZ - mzRangeAbsolute > ionsBMaxMZ)
// Potential speedup heuristic. If any i is greater than the max of j, no more
break;
for (int j = 0; j < ionsB.length; j++) {
double jMZ = ionsB[j].getMZ();
if (iMZ < jMZ - mzRangeAbsolute)
// Potential speedup heuristic. iMZ smaller than jMZ. Skip the rest of the j's as
break;
if (Math.abs(iMZ - jMZ) < mzRangeAbsolute) {
runningScoreTotal += ionsA[i].getIntensity() * ionsB[j].getIntensity();
matchedIons.add(ionsA[i]);
}
}
}
Ms2SearchResult result = new Ms2SearchResult(runningScoreTotal, "simple", matchedIons);
return result;
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class MSMSExportModule method exportMSMS.
public static void exportMSMS(PeakListRow row) {
ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(MSMSExportModule.class);
ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
if (exitCode != ExitCode.OK)
return;
File outputFile = parameters.getParameter(MSMSExportParameters.outputFile).getValue();
String massListName = parameters.getParameter(MSMSExportParameters.massList).getValue();
if ((outputFile == null) || (massListName == null))
return;
// Best peak always exists, because feature list row has at least one peak
Feature bestPeak = row.getBestPeak();
// Get the MS/MS scan number
int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
if (msmsScanNumber < 1) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no MS/MS scan for peak " + bestPeak);
return;
}
// MS/MS scan must exist, because msmsScanNumber was > 0
Scan msmsScan = bestPeak.getDataFile().getScan(msmsScanNumber);
MassList massList = msmsScan.getMassList(massListName);
if (massList == null) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no mass list called " + massListName + " for MS/MS scan #" + msmsScanNumber + " (" + bestPeak.getDataFile() + ")");
return;
}
DataPoint[] peaks = massList.getDataPoints();
try {
FileWriter fileWriter = new FileWriter(outputFile);
BufferedWriter writer = new BufferedWriter(fileWriter);
for (DataPoint peak : peaks) {
writer.write(peak.getMZ() + " " + peak.getIntensity());
writer.newLine();
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error writing to file " + outputFile + ": " + ExceptionUtils.exceptionToString(e));
}
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class MZDistributionHistoTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Starting to build mz distribution histogram for " + dataFile);
// all selected scans
scans = scanSelection.getMatchingScans(dataFile);
totalScans = scans.length;
// histo data
DoubleArrayList data = new DoubleArrayList();
for (Scan scan : scans) {
if (isCanceled())
return;
// retention time in range
if (!useRTRange || rtRange.contains(scan.getRetentionTime())) {
// go through all mass lists
MassList massList = scan.getMassList(massListName);
if (massList == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
return;
}
DataPoint[] mzValues = massList.getDataPoints();
// insert all mz in order and count them
Arrays.stream(mzValues).mapToDouble(dp -> dp.getMZ()).filter(mz -> mzRange.contains(mz)).forEach(mz -> data.add(mz));
processedScans++;
}
}
if (!data.isEmpty()) {
// to array
double[] histo = new double[data.size()];
for (int i = 0; i < data.size(); i++) histo[i] = data.get(i);
// create histogram dialog
EHistogramDialog dialog = new EHistogramDialog("m/z distribution", "m/z", new HistogramData(histo), binWidth);
dialog.setVisible(true);
} else {
throw new MSDKRuntimeException("Data was empty. Review your selected filters.");
}
setStatus(TaskStatus.FINISHED);
logger.info("Finished mz distribution histogram on " + dataFile);
}
use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.
the class ProjectTreeMouseHandler method handleDoubleClickEvent.
private void handleDoubleClickEvent(MouseEvent e) {
TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY());
if (clickedPath == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent();
Object clickedObject = node.getUserObject();
if (clickedObject instanceof RawDataFile) {
RawDataFile clickedFile = (RawDataFile) clickedObject;
TICVisualizerModule.setupNewTICVisualizer(clickedFile);
}
if (clickedObject instanceof PeakList) {
PeakList clickedPeakList = (PeakList) clickedObject;
PeakListTableModule.showNewPeakListVisualizerWindow(clickedPeakList);
}
if (clickedObject instanceof Scan) {
Scan clickedScan = (Scan) clickedObject;
SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
}
if (clickedObject instanceof MassList) {
MassList clickedMassList = (MassList) clickedObject;
Scan clickedScan = clickedMassList.getScan();
SpectraVisualizerWindow window = SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
MassListDataSet dataset = new MassListDataSet(clickedMassList);
window.addDataSet(dataset, Color.green);
}
if (clickedObject instanceof PeakListRow) {
PeakListRow clickedPeak = (PeakListRow) clickedObject;
PeakSummaryVisualizerModule.showNewPeakSummaryWindow(clickedPeak);
}
}
Aggregations