Search in sources :

Example 1 with PeakIdentity

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);
}
Also used : SiriusExportModule(net.sf.mzmine.modules.peaklistmethods.io.siriusexport.SiriusExportModule) Arrays(java.util.Arrays) IntensityPlotModule(net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotModule) URISyntaxException(java.net.URISyntaxException) Point(java.awt.Point) SpectraVisualizerModule(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerModule) DataFileColumnType(net.sf.mzmine.modules.visualization.peaklisttable.table.DataFileColumnType) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) SiriusProcessingModule(net.sf.mzmine.modules.peaklistmethods.identification.sirius.SiriusProcessingModule) Map(java.util.Map) URI(java.net.URI) PeakListTable(net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTable) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) Fx3DVisualizerModule(net.sf.mzmine.modules.visualization.fx3d.Fx3DVisualizerModule) SortingProperty(net.sf.mzmine.util.SortingProperty) FormulaPredictionModule(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.FormulaPredictionModule) Range(com.google.common.collect.Range) JMenu(javax.swing.JMenu) GUIUtils(net.sf.mzmine.util.GUIUtils) CommonColumnType(net.sf.mzmine.modules.visualization.peaklisttable.table.CommonColumnType) Component(java.awt.Component) Collectors(java.util.stream.Collectors) List(java.util.List) PeakSummaryVisualizerModule(net.sf.mzmine.modules.visualization.peaksummary.PeakSummaryVisualizerModule) MirrorScanWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.mirrorspectra.MirrorScanWindow) ListSelectionModel(javax.swing.ListSelectionModel) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) MZmineCore(net.sf.mzmine.main.MZmineCore) ActionListener(java.awt.event.ActionListener) TICVisualizerModule(net.sf.mzmine.modules.visualization.tic.TICVisualizerModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) HashMap(java.util.HashMap) PeakList(net.sf.mzmine.datamodel.PeakList) ArrayList(java.util.ArrayList) MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) SwingUtilities(javax.swing.SwingUtilities) MultiSpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.MultiSpectraVisualizerWindow) Feature(net.sf.mzmine.datamodel.Feature) JMenuItem(javax.swing.JMenuItem) AbstractTableModel(javax.swing.table.AbstractTableModel) XICManualPickerModule(net.sf.mzmine.modules.rawdatamethods.peakpicking.manual.XICManualPickerModule) MSMSExportModule(net.sf.mzmine.modules.visualization.peaklisttable.export.MSMSExportModule) NistMsSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.nist.NistMsSearchModule) ManualPeakPickerModule(net.sf.mzmine.modules.rawdatamethods.peakpicking.manual.ManualPeakPickerModule) PeakListTableColumnModel(net.sf.mzmine.modules.visualization.peaklisttable.table.PeakListTableColumnModel) Desktop(java.awt.Desktop) MultiMSMSWindow(net.sf.mzmine.modules.visualization.spectra.multimsms.MultiMSMSWindow) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) JPopupMenu(javax.swing.JPopupMenu) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) TwoDVisualizerModule(net.sf.mzmine.modules.visualization.twod.TwoDVisualizerModule) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) IsotopePatternExportModule(net.sf.mzmine.modules.visualization.peaklisttable.export.IsotopePatternExportModule) SortingDirection(net.sf.mzmine.util.SortingDirection) OnlineDBSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.OnlineDBSearchModule) LocalSpectralDBSearchModule(net.sf.mzmine.modules.peaklistmethods.identification.spectraldbsearch.LocalSpectralDBSearchModule) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) ListSelectionModel(javax.swing.ListSelectionModel) Point(java.awt.Point) Feature(net.sf.mzmine.datamodel.Feature) Point(java.awt.Point)

Example 2 with PeakIdentity

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);
    }
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) PeakListRow(net.sf.mzmine.datamodel.PeakListRow)

Example 3 with PeakIdentity

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;
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) Color(java.awt.Color) JLabel(javax.swing.JLabel) Border(javax.swing.border.Border)

Example 4 with PeakIdentity

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;
            }
        }
    }
}
Also used : IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) PreparedStatement(java.sql.PreparedStatement) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 5 with PeakIdentity

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++;
    }
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow)

Aggregations

PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)32 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)19 Feature (net.sf.mzmine.datamodel.Feature)14 ArrayList (java.util.ArrayList)9 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)9 PeakList (net.sf.mzmine.datamodel.PeakList)8 HashMap (java.util.HashMap)7 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)7 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)6 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)6 IOException (java.io.IOException)5 List (java.util.List)5 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)5 File (java.io.File)4 HashSet (java.util.HashSet)4 Scan (net.sf.mzmine.datamodel.Scan)4 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 Range (com.google.common.collect.Range)3