use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class FormulaPredictionPeakListTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
totalRows = peakList.getNumberOfRows();
for (PeakListRow row : peakList.getRows()) {
if (row.getPeakIdentities().length > 0) {
continue;
}
this.searchedMass = (row.getAverageMZ() - ionType.getAddedMass()) * charge;
message = "Formula prediction for " + MZmineCore.getConfiguration().getMZFormat().format(searchedMass);
massRange = mzTolerance.getToleranceRange(searchedMass);
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
IMolecularFormula cdkFormula;
// create a map to store ResultFormula and relative mass deviation for sorting
Map<Double, String> possibleFormulas = new TreeMap<>();
while ((cdkFormula = generator.getNextFormula()) != null) {
if (isCanceled())
return;
// Mass is ok, so test other constraints
if (checkConstraints(cdkFormula, row) == true) {
String formula = MolecularFormulaManipulator.getString(cdkFormula);
// calc rel mass deviation
Double relMassDev = ((searchedMass - (FormulaUtils.calculateExactMass(formula))) / searchedMass) * 1000000;
// write to map
possibleFormulas.put(relMassDev, formula);
}
}
if (isCanceled())
return;
// create a map to store ResultFormula and relative mass deviation for sorting
Map<Double, String> possibleFormulasSorted = new TreeMap<>((Comparator<Double>) (o1, o2) -> Double.compare(Math.abs(o1), Math.abs(o2)));
possibleFormulasSorted.putAll(possibleFormulas);
// Add the new formula entry top results
int ctr = 0;
for (Map.Entry<Double, String> entry : possibleFormulasSorted.entrySet()) {
if (ctr < maxBestFormulasPerPeak) {
SimplePeakIdentity newIdentity = new SimplePeakIdentity(entry.getValue(), entry.getValue(), this.getClass().getName(), null, null);
row.addPeakIdentity(newIdentity, false);
ctr++;
}
}
if (isCanceled())
return;
finishedRows++;
}
if (isCanceled())
return;
logger.finest("Finished formula search for all the peaks");
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakListRow 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.datamodel.PeakListRow in project mzmine2 by mzmine.
the class NistMsSearchTask method groupPeakRows.
/**
* Determines the contemporaneity between all pairs of non-identical peak rows.
*
* @return a map holding pairs of adjacent (non-identical) peak rows. (x,y) <=> (y,x)
*/
private Map<PeakListRow, Set<PeakListRow>> groupPeakRows() {
// Determine contemporaneity.
final int numRows = peakList.getNumberOfRows();
final Map<PeakListRow, Set<PeakListRow>> rowHoods = new HashMap<PeakListRow, Set<PeakListRow>>(numRows);
for (int i = 0; i < numRows; i++) {
// Get this row's neighbours list - create it if necessary.
final PeakListRow row1 = peakList.getRow(i);
if (!rowHoods.containsKey(row1)) {
rowHoods.put(row1, new HashSet<PeakListRow>(4));
}
// Holds neighbours.
final Set<PeakListRow> neighbours = rowHoods.get(row1);
// Contemporaneous with self.
neighbours.add(row1);
// Find contemporaneous peaks.
final double rt = row1.getAverageRT();
for (int j = i + 1; j < numRows; j++) {
// Are peak rows contemporaneous?
final PeakListRow row2 = peakList.getRow(j);
if (rtTolerance.checkWithinTolerance(rt, row2.getAverageRT()) && (!sameIds || checkSameIds(row1, row2))) {
// Add rows to each others' neighbours lists.
neighbours.add(row2);
if (!rowHoods.containsKey(row2)) {
rowHoods.put(row2, new HashSet<PeakListRow>(4));
}
rowHoods.get(row2).add(row1);
}
}
}
return rowHoods;
}
use of net.sf.mzmine.datamodel.PeakListRow 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);
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class PeakListTablePopupMenu method show.
@Override
public void show(final Component invoker, final int x, final int y) {
// Select the row where clicked?
final Point clickedPoint = new Point(x, y);
final int clickedRow = table.rowAtPoint(clickedPoint);
if (table.getSelectedRowCount() < 2) {
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionInterval(clickedRow, clickedRow);
}
// First, disable all the Show... items
show2DItem.setEnabled(false);
show3DItem.setEnabled(false);
manuallyDefineItem.setEnabled(false);
showMSMSItem.setEnabled(false);
showMSMSMirrorItem.setEnabled(false);
showSpectralDBResults.setEnabled(false);
showAllMSMSItem.setEnabled(false);
showIsotopePatternItem.setEnabled(false);
showPeakRowSummaryItem.setEnabled(false);
exportIsotopesItem.setEnabled(false);
exportMSMSItem.setEnabled(false);
exportMenu.setEnabled(false);
// Enable row items if applicable
final int[] selectedRows = table.getSelectedRows();
final boolean rowsSelected = selectedRows.length > 0;
deleteRowsItem.setEnabled(rowsSelected);
clearIdsItem.setEnabled(rowsSelected);
pasteIdsItem.setEnabled(rowsSelected && copiedId != null);
plotRowsItem.setEnabled(rowsSelected);
showMenu.setEnabled(rowsSelected);
idsMenu.setEnabled(rowsSelected);
exportIsotopesItem.setEnabled(rowsSelected);
exportToSirius.setEnabled(rowsSelected);
exportMSMSLibrary.setEnabled(rowsSelected);
exportMS1Library.setEnabled(rowsSelected);
exportMenu.setEnabled(rowsSelected);
final boolean oneRowSelected = selectedRows.length == 1;
searchMenu.setEnabled(true);
// search methods for single rows
onlineDbSearchItem.setEnabled(oneRowSelected);
nistSearchItem.setEnabled(oneRowSelected);
formulaItem.setEnabled(oneRowSelected);
siriusItem.setEnabled(oneRowSelected);
// search methods for single and multiple rows
spectralDbSearchItem.setEnabled(true);
// Find the row and column where the user clicked
clickedDataFile = null;
final int clickedColumn = columnModel.getColumn(table.columnAtPoint(clickedPoint)).getModelIndex();
if (clickedRow >= 0 && clickedColumn >= 0) {
final int rowIndex = table.convertRowIndexToModel(clickedRow);
clickedPeakListRow = getPeakListRow(rowIndex);
allClickedPeakListRows = new PeakListRow[selectedRows.length];
for (int i = 0; i < selectedRows.length; i++) {
allClickedPeakListRows[i] = getPeakListRow(table.convertRowIndexToModel(selectedRows[i]));
}
// Enable items.
show2DItem.setEnabled(oneRowSelected);
show3DItem.setEnabled(oneRowSelected);
showPeakRowSummaryItem.setEnabled(oneRowSelected);
if (clickedPeakListRow.getBestPeak() != null) {
exportMSMSItem.setEnabled(oneRowSelected && clickedPeakListRow.getBestPeak().getMostIntenseFragmentScanNumber() > 0);
}
// If we clicked on data file columns, check the peak
if (clickedColumn >= CommonColumnType.values().length) {
// Enable manual peak picking
manuallyDefineItem.setEnabled(oneRowSelected);
// Find the actual peak, if we have it.
clickedDataFile = peakList.getRawDataFile((clickedColumn - CommonColumnType.values().length) / DataFileColumnType.values().length);
final Feature clickedPeak = getPeakListRow(table.convertRowIndexToModel(clickedRow)).getPeak(clickedDataFile);
// If we have the peak, enable Show... items
if (clickedPeak != null && oneRowSelected) {
showIsotopePatternItem.setEnabled(clickedPeak.getIsotopePattern() != null);
}
} else {
showIsotopePatternItem.setEnabled(clickedPeakListRow.getBestIsotopePattern() != null && oneRowSelected);
}
long nRowsWithFragmentation = Arrays.stream(allClickedPeakListRows).filter(r -> r.getBestFragmentation() != null).count();
// always show for multi MSMS window
showMSMSItem.setEnabled((oneRowSelected && getSelectedPeakForMSMS() != null && getSelectedPeakForMSMS().getMostIntenseFragmentScanNumber() > 0) || (selectedRows.length > 1 && nRowsWithFragmentation > 1));
// always show if at least one fragmentation is available
showAllMSMSItem.setEnabled(clickedPeakListRow.getBestFragmentation() != null && oneRowSelected);
// only show if selected rows == 2 and both have MS2
boolean bothMS2 = selectedRows.length == 2 && nRowsWithFragmentation == 2;
showMSMSMirrorItem.setEnabled(bothMS2);
// has identity of spectral database match
showSpectralDBResults.setEnabled(hasSpectralDBIdentities(clickedPeakListRow));
// open id url if available
PeakIdentity pi = clickedPeakListRow.getPreferredPeakIdentity();
String url = null;
if (pi != null)
url = pi.getPropertyValue(PeakIdentity.PROPERTY_URL);
openCompoundIdUrl.setEnabled(url != null && !url.isEmpty());
}
copyIdsItem.setEnabled(oneRowSelected && allClickedPeakListRows[0].getPreferredPeakIdentity() != null);
super.show(invoker, x, y);
}
Aggregations