use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class FormulaPredictionPeakListTask method checkConstraints.
private boolean checkConstraints(IMolecularFormula cdkFormula, PeakListRow peakListRow) {
// Check elemental ratios
if (checkRatios) {
boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
if (!check) {
return false;
}
}
Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
// Check RDBE condition
if (checkRDBE && (rdbeValue != null)) {
boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
if (!check) {
return false;
}
}
// Calculate isotope similarity score
IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
IsotopePattern predictedIsotopePattern = null;
Double isotopeScore = null;
if ((checkIsotopes) && (detectedPattern != null)) {
String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
if (isotopeScore < minScore) {
return false;
}
}
// MS/MS evaluation is slowest, so let's do it last
Double msmsScore = null;
Feature bestPeak = peakListRow.getBestPeak();
RawDataFile dataFile = bestPeak.getDataFile();
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 false;
}
MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
if (score != null) {
msmsScore = score.getScore();
// Check the MS/MS condition
if (msmsScore < minMSMSScore) {
return false;
}
}
}
return true;
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class AdapMgfExportTask method exportPeakList.
private void exportPeakList(PeakList peakList, FileWriter writer) throws IOException {
for (PeakListRow row : peakList.getRows()) {
IsotopePattern ip = row.getBestIsotopePattern();
if (ip == null)
continue;
exportRow(writer, row, ip);
finishedRows++;
}
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class PeakListSaveHandler method fillPeakElement.
/**
* Add the peaks information into the XML document
*
* @param peak
* @param element
* @param dataFileID
* @throws IOException
*/
private void fillPeakElement(Feature peak, TransformerHandler hd) throws SAXException, IOException {
AttributesImpl atts = new AttributesImpl();
// <REPRESENTATIVE_SCAN>
hd.startElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName(), atts);
hd.characters(String.valueOf(peak.getRepresentativeScanNumber()).toCharArray(), 0, String.valueOf(peak.getRepresentativeScanNumber()).length());
hd.endElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName());
// <FRAGMENT_SCAN>
hd.startElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName(), atts);
hd.characters(String.valueOf(peak.getMostIntenseFragmentScanNumber()).toCharArray(), 0, String.valueOf(peak.getMostIntenseFragmentScanNumber()).length());
hd.endElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName());
// <ALL_MS2_FRAGMENT_SCANS>
fillAllMS2FragmentScanNumbers(peak.getAllMS2FragmentScanNumbers(), hd);
int[] scanNumbers = peak.getScanNumbers();
// <ISOTOPE_PATTERN>
IsotopePattern isotopePattern = peak.getIsotopePattern();
if (isotopePattern != null) {
atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", String.valueOf(isotopePattern.getStatus()));
atts.addAttribute("", "", PeakListElementName.DESCRIPTION.getElementName(), "CDATA", isotopePattern.getDescription());
hd.startElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName(), atts);
atts.clear();
fillIsotopePatternElement(isotopePattern, hd);
hd.endElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName());
}
// <MZPEAK>
atts.addAttribute("", "", PeakListElementName.QUANTITY.getElementName(), "CDATA", String.valueOf(scanNumbers.length));
hd.startElement("", "", PeakListElementName.MZPEAKS.getElementName(), atts);
atts.clear();
// <SCAN_ID> <MASS> <HEIGHT>
ByteArrayOutputStream byteScanStream = new ByteArrayOutputStream();
DataOutputStream dataScanStream = new DataOutputStream(byteScanStream);
ByteArrayOutputStream byteMassStream = new ByteArrayOutputStream();
DataOutputStream dataMassStream = new DataOutputStream(byteMassStream);
ByteArrayOutputStream byteHeightStream = new ByteArrayOutputStream();
DataOutputStream dataHeightStream = new DataOutputStream(byteHeightStream);
float mass, height;
for (int scan : scanNumbers) {
dataScanStream.writeInt(scan);
dataScanStream.flush();
DataPoint mzPeak = peak.getDataPoint(scan);
if (mzPeak != null) {
mass = (float) mzPeak.getMZ();
height = (float) mzPeak.getIntensity();
} else {
mass = 0f;
height = 0f;
}
dataMassStream.writeFloat(mass);
dataMassStream.flush();
dataHeightStream.writeFloat(height);
dataHeightStream.flush();
}
byte[] bytes = Base64.encode(byteScanStream.toByteArray());
hd.startElement("", "", PeakListElementName.SCAN_ID.getElementName(), atts);
String sbytes = new String(bytes);
hd.characters(sbytes.toCharArray(), 0, sbytes.length());
hd.endElement("", "", PeakListElementName.SCAN_ID.getElementName());
bytes = Base64.encode(byteMassStream.toByteArray());
hd.startElement("", "", PeakListElementName.MZ.getElementName(), atts);
sbytes = new String(bytes);
hd.characters(sbytes.toCharArray(), 0, sbytes.length());
hd.endElement("", "", PeakListElementName.MZ.getElementName());
bytes = Base64.encode(byteHeightStream.toByteArray());
hd.startElement("", "", PeakListElementName.HEIGHT.getElementName(), atts);
sbytes = new String(bytes);
hd.characters(sbytes.toCharArray(), 0, sbytes.length());
hd.endElement("", "", PeakListElementName.HEIGHT.getElementName());
hd.endElement("", "", PeakListElementName.MZPEAKS.getElementName());
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class SpectraVisualizerWindow method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("PEAKLIST_CHANGE")) {
// If no scan is loaded yet, ignore
if (currentScan == null)
return;
PeakList selectedPeakList = bottomPanel.getSelectedPeakList();
loadPeaks(selectedPeakList);
}
if (command.equals("PREVIOUS_SCAN")) {
if (dataFile == null)
return;
int msLevel = currentScan.getMSLevel();
int[] scanNumbers = dataFile.getScanNumbers(msLevel);
int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
if (scanIndex > 0) {
final int prevScanIndex = scanNumbers[scanIndex - 1];
Runnable newThreadRunnable = new Runnable() {
@Override
public void run() {
loadRawData(dataFile.getScan(prevScanIndex));
}
};
Thread newThread = new Thread(newThreadRunnable);
newThread.start();
}
}
if (command.equals("NEXT_SCAN")) {
if (dataFile == null)
return;
int msLevel = currentScan.getMSLevel();
int[] scanNumbers = dataFile.getScanNumbers(msLevel);
int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
if (scanIndex < (scanNumbers.length - 1)) {
final int nextScanIndex = scanNumbers[scanIndex + 1];
Runnable newThreadRunnable = new Runnable() {
@Override
public void run() {
loadRawData(dataFile.getScan(nextScanIndex));
}
};
Thread newThread = new Thread(newThreadRunnable);
newThread.start();
}
}
if (command.equals("SHOW_MSMS")) {
String selectedScanString = (String) bottomPanel.getMSMSSelector().getSelectedItem();
if (selectedScanString == null)
return;
int sharpIndex = selectedScanString.indexOf('#');
int commaIndex = selectedScanString.indexOf(',');
selectedScanString = selectedScanString.substring(sharpIndex + 1, commaIndex);
int selectedScan = Integer.valueOf(selectedScanString);
SpectraVisualizerModule.showNewSpectrumWindow(dataFile, selectedScan);
}
if (command.equals("TOGGLE_PLOT_MODE")) {
if (spectrumPlot.getPlotMode() == MassSpectrumType.CENTROIDED) {
spectrumPlot.setPlotMode(MassSpectrumType.PROFILE);
toolBar.setCentroidButton(MassSpectrumType.PROFILE);
} else {
spectrumPlot.setPlotMode(MassSpectrumType.CENTROIDED);
toolBar.setCentroidButton(MassSpectrumType.CENTROIDED);
}
}
if (command.equals("SHOW_DATA_POINTS")) {
spectrumPlot.switchDataPointsVisible();
}
if (command.equals("SHOW_ANNOTATIONS")) {
spectrumPlot.switchItemLabelsVisible();
}
if (command.equals("SHOW_PICKED_PEAKS")) {
spectrumPlot.switchPickedPeaksVisible();
}
if (command.equals("SHOW_ISOTOPE_PEAKS")) {
spectrumPlot.switchIsotopePeaksVisible();
}
if (command.equals("SETUP_AXES")) {
AxesSetupDialog dialog = new AxesSetupDialog(this, spectrumPlot.getXYPlot());
dialog.setVisible(true);
}
// library entry creation
if (command.equals("CREATE_LIBRARY_ENTRY")) {
// open window with all selected rows
MSMSLibrarySubmissionWindow libraryWindow = new MSMSLibrarySubmissionWindow();
libraryWindow.setData(currentScan);
libraryWindow.setVisible(true);
}
if (command.equals("EXPORT_SPECTRA")) {
ExportScansModule.showSetupDialog(currentScan);
}
if (command.equals("ADD_ISOTOPE_PATTERN")) {
IsotopePattern newPattern = IsotopePatternCalculator.showIsotopePredictionDialog(this, true);
if (newPattern == null)
return;
loadIsotopes(newPattern);
}
if ((command.equals("ZOOM_IN")) || (command.equals("ZOOM_IN_BOTH_COMMAND"))) {
spectrumPlot.getXYPlot().getDomainAxis().resizeRange(1 / zoomCoefficient);
}
if ((command.equals("ZOOM_OUT")) || (command.equals("ZOOM_OUT_BOTH_COMMAND"))) {
spectrumPlot.getXYPlot().getDomainAxis().resizeRange(zoomCoefficient);
}
if (command.equals("SET_SAME_RANGE")) {
// Get current axes range
NumberAxis xAxis = (NumberAxis) spectrumPlot.getXYPlot().getDomainAxis();
NumberAxis yAxis = (NumberAxis) spectrumPlot.getXYPlot().getRangeAxis();
double xMin = xAxis.getRange().getLowerBound();
double xMax = xAxis.getRange().getUpperBound();
double xTick = xAxis.getTickUnit().getSize();
double yMin = yAxis.getRange().getLowerBound();
double yMax = yAxis.getRange().getUpperBound();
double yTick = yAxis.getTickUnit().getSize();
// Get all frames of my class
Window[] spectraFrames = JFrame.getWindows();
// Set the range of these frames
for (Window frame : spectraFrames) {
if (!(frame instanceof SpectraVisualizerWindow))
continue;
SpectraVisualizerWindow spectraFrame = (SpectraVisualizerWindow) frame;
spectraFrame.setAxesRange(xMin, xMax, xTick, yMin, yMax, yTick);
}
}
if (command.equals("ONLINEDATABASESEARCH")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
OnlineDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
}
});
}
if (command.equals("CUSTOMDATABASESEARCH")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
CustomDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
}
});
}
if (command.equals("LIPIDSEARCH")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LipidSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
}
});
}
if (command.equals("SUMFORMULA")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SumFormulaSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
}
});
}
if (command.equals("SPECTRALDATABASESEARCH")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SpectraIdentificationSpectralDatabaseModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
}
});
}
if (command.equals("SET_PROCESSING_PARAMETERS")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (!dppmWindowOpen) {
dppmWindowOpen = true;
ExitCode exitCode = DataPointProcessingManager.getInst().getParameters().showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
dppmWindowOpen = false;
if (exitCode == ExitCode.OK && DataPointProcessingManager.getInst().isEnabled()) {
// if processing was run before, this removes the previous results.
getSpectrumPlot().removeDataPointProcessingResultDataSets();
getSpectrumPlot().checkAndRunController();
}
}
}
});
}
if (command.equals("ENABLE_PROCESSING")) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DataPointProcessingManager inst = DataPointProcessingManager.getInst();
inst.setEnabled(!inst.isEnabled());
bottomPanel.updateProcessingButton();
getSpectrumPlot().checkAndRunController();
// if the tick is removed, set the data back to default
if (!inst.isEnabled()) {
getSpectrumPlot().removeDataPointProcessingResultDataSets();
// loadRawData(currentScan);
}
}
});
}
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class PseudoSpectrum method createDataSet.
public static PseudoSpectrumDataSet createDataSet(PeakListRow[] group, RawDataFile raw, boolean sum) {
// data
PseudoSpectrumDataSet series = new PseudoSpectrumDataSet(true, "pseudo");
// add all isotopes as a second series:
XYSeries isoSeries = new XYSeries("Isotopes", true);
// raw isotopes in a different color
XYSeries rawIsoSeries = new XYSeries("Raw isotope pattern", true);
// for each row
for (PeakListRow row : group) {
String annotation = null;
// sum -> heighest peak
if (sum)
series.addDP(row.getAverageMZ(), row.getBestPeak().getHeight(), annotation);
else {
Feature f = raw == null ? row.getBestPeak() : row.getPeak(raw);
if (f != null)
series.addDP(f.getMZ(), f.getHeight(), null);
}
// add isotopes
IsotopePattern pattern = row.getBestIsotopePattern();
if (pattern != null) {
for (DataPoint dp : pattern.getDataPoints()) isoSeries.add(dp.getMZ(), dp.getIntensity());
}
}
series.addSeries(isoSeries);
series.addSeries(rawIsoSeries);
return series;
}
Aggregations