use of net.sf.mzmine.datamodel.PeakIdentity 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);
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class PeakListTableModel method setValueAt.
public void setValueAt(Object value, int row, int col) {
CommonColumnType columnType = getCommonColumn(col);
PeakListRow peakListRow = peakList.getRow(row);
if (columnType == CommonColumnType.COMMENT) {
peakListRow.setComment((String) value);
}
if (columnType == CommonColumnType.IDENTITY) {
if (value instanceof PeakIdentity)
peakListRow.setPreferredPeakIdentity((PeakIdentity) value);
}
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class CompoundIdentityCellRenderer method getTableCellRendererComponent.
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
* java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel newLabel = new JLabel();
newLabel.setHorizontalAlignment(JLabel.LEFT);
newLabel.setFont(defaultFont);
newLabel.setOpaque(true);
Color bgColor;
if (isSelected)
bgColor = table.getSelectionBackground();
else
bgColor = table.getBackground();
newLabel.setBackground(bgColor);
if (hasFocus) {
Border border = null;
if (isSelected)
border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
if (border == null)
border = UIManager.getBorder("Table.focusCellHighlightBorder");
/*
* The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
* otherwise setBorder() may throw a NullPointerException
*/
if ((border != null) && (border.getBorderInsets(newLabel) != null)) {
newLabel.setBorder(border);
}
}
if (value instanceof PeakIdentity) {
PeakIdentity identity = (PeakIdentity) value;
newLabel.setText(identity.getName());
String toolTipText = identity.getDescription();
newLabel.setToolTipText(toolTipText);
}
return newLabel;
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class SQLExportTask method exportPeakListRow.
private void exportPeakListRow(PeakListRow row) throws SQLException {
// Cancel?
if (isCanceled()) {
return;
}
// Value for looping through raw data files
boolean loopDataFiles = false;
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ");
sql.append(tableName);
sql.append(" (");
for (int i = 0; i < exportColumns.getRowCount(); i++) {
sql.append(exportColumns.getValueAt(i, 0));
if (i < exportColumns.getRowCount() - 1)
sql.append(",");
}
sql.append(" ) VALUES (");
for (int i = 0; i < exportColumns.getRowCount(); i++) {
sql.append("?");
if (i < exportColumns.getRowCount() - 1)
sql.append(",");
}
sql.append(")");
PreparedStatement statement = dbConnection.prepareStatement(sql.toString());
if (row == null) {
for (int i = 0; i < exportColumns.getRowCount(); i++) {
SQLExportDataType dataType = (SQLExportDataType) exportColumns.getValueAt(i, 1);
String dataValue = (String) exportColumns.getValueAt(i, 2);
switch(dataType) {
case CONSTANT:
statement.setString(i + 1, dataValue);
break;
case RAWFILE:
RawDataFile[] rawdatafiles = peakList.getRawDataFiles();
statement.setString(i + 1, rawdatafiles[0].getName());
break;
default:
statement.setString(i + 1, null);
break;
}
}
statement.executeUpdate();
} else {
for (RawDataFile rawDataFile : row.getRawDataFiles()) {
Feature peak = row.getPeak(rawDataFile);
for (int i = 0; i < exportColumns.getRowCount(); i++) {
SQLExportDataType dataType = (SQLExportDataType) exportColumns.getValueAt(i, 1);
String dataValue = (String) exportColumns.getValueAt(i, 2);
switch(dataType) {
case CONSTANT:
statement.setString(i + 1, dataValue);
break;
case MZ:
statement.setDouble(i + 1, row.getAverageMZ());
break;
case RT:
statement.setDouble(i + 1, row.getAverageRT());
break;
case ID:
statement.setInt(i + 1, row.getID());
break;
case PEAKCHARGE:
statement.setDouble(i + 1, peak.getCharge());
loopDataFiles = true;
break;
case PEAKDURATION:
statement.setDouble(i + 1, RangeUtils.rangeLength(peak.getRawDataPointsRTRange()));
loopDataFiles = true;
break;
case PEAKSTATUS:
statement.setString(i + 1, peak.getFeatureStatus().name());
loopDataFiles = true;
break;
case PEAKMZ:
statement.setDouble(i + 1, peak.getMZ());
loopDataFiles = true;
break;
case PEAKRT:
statement.setDouble(i + 1, peak.getRT());
loopDataFiles = true;
break;
case PEAKRT_START:
statement.setDouble(i + 1, peak.getRawDataPointsRTRange().lowerEndpoint());
loopDataFiles = true;
break;
case PEAKRT_END:
statement.setDouble(i + 1, peak.getRawDataPointsRTRange().upperEndpoint());
loopDataFiles = true;
break;
case PEAKHEIGHT:
statement.setDouble(i + 1, peak.getHeight());
loopDataFiles = true;
break;
case PEAKAREA:
statement.setDouble(i + 1, peak.getArea());
loopDataFiles = true;
break;
case DATAPOINTS:
statement.setDouble(i + 1, peak.getScanNumbers().length);
loopDataFiles = true;
break;
case FWHM:
statement.setDouble(i + 1, peak.getFWHM());
loopDataFiles = true;
break;
case TAILINGFACTOR:
statement.setDouble(i + 1, peak.getTailingFactor());
loopDataFiles = true;
break;
case ASYMMETRYFACTOR:
statement.setDouble(i + 1, peak.getAsymmetryFactor());
loopDataFiles = true;
break;
case RAWFILE:
statement.setString(i + 1, rawDataFile.getName());
loopDataFiles = true;
break;
case HEIGHT:
statement.setDouble(i + 1, row.getAverageHeight());
break;
case AREA:
statement.setDouble(i + 1, row.getAverageArea());
break;
case COMMENT:
statement.setString(i + 1, row.getComment());
break;
case IDENTITY:
PeakIdentity id = row.getPreferredPeakIdentity();
if (id != null) {
statement.setString(i + 1, id.getName());
} else {
statement.setNull(i + 1, Types.VARCHAR);
}
break;
case ISOTOPEPATTERN:
IsotopePattern isotopes = row.getBestIsotopePattern();
if (isotopes == null) {
statement.setNull(i + 1, Types.BLOB);
break;
}
DataPoint[] dataPoints = isotopes.getDataPoints();
byte[] bytes = ScanUtils.encodeDataPointsToBytes(dataPoints);
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
statement.setBlob(i + 1, is);
break;
case MSMS:
int msmsScanNum = row.getBestPeak().getMostIntenseFragmentScanNumber();
// Check if there is any MS/MS scan
if (msmsScanNum <= 0) {
statement.setNull(i + 1, Types.BLOB);
break;
}
RawDataFile dataFile = row.getBestPeak().getDataFile();
Scan msmsScan = dataFile.getScan(msmsScanNum);
MassList msmsMassList = msmsScan.getMassList(dataValue);
// Check if there is a masslist for the scan
if (msmsMassList == null) {
statement.setNull(i + 1, Types.BLOB);
break;
}
dataPoints = msmsMassList.getDataPoints();
bytes = ScanUtils.encodeDataPointsToBytes(dataPoints);
is = new ByteArrayInputStream(bytes);
statement.setBlob(i + 1, is);
break;
default:
break;
}
}
statement.executeUpdate();
// data files in feature list
if (!loopDataFiles) {
break;
}
}
}
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class RTCalibrationTask method normalizePeakList.
/**
* Normalize retention time of all rows in given feature list and save normalized rows into new peak
* list.
*
* @param originalPeakList Feature list to be normalized
* @param normalizedPeakList New feature list, where normalized rows are to be saved
* @param standards Standard rows in same feature list
* @param normalizedStdRTs Normalized retention times of standard rows
*/
private void normalizePeakList(PeakList originalPeakList, PeakList normalizedPeakList, PeakListRow[] standards, double[] normalizedStdRTs) {
PeakListRow[] originalRows = originalPeakList.getRows();
// Iterate feature list rows
for (PeakListRow originalRow : originalRows) {
// Cancel?
if (isCanceled()) {
return;
}
// Normalize one row
PeakListRow normalizedRow = normalizeRow(originalRow, standards, normalizedStdRTs);
// Copy comment and identification
normalizedRow.setComment(originalRow.getComment());
for (PeakIdentity ident : originalRow.getPeakIdentities()) normalizedRow.addPeakIdentity(ident, false);
normalizedRow.setPreferredPeakIdentity(originalRow.getPreferredPeakIdentity());
// Add the new row to normalized feature list
normalizedPeakList.addRow(normalizedRow);
processedRows++;
}
}
Aggregations