Search in sources :

Example 1 with HeatMapTableModel

use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method addRankings.

private void addRankings() {
    HeatMapTableModel model = (HeatMapTableModel) table.getModel();
    EnrichmentMap map = model.getEnrichmentMap();
    AddRanksDialog dialog = ranksDialogFactory.create(map);
    Optional<String> ranksName = dialog.open();
    if (ranksName.isPresent()) {
        this.moreRankOptions = parent.getMediator().getDataSetRankOptions(map);
    }
}
Also used : HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)

Example 2 with HeatMapTableModel

use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method createTableHeader.

private void createTableHeader(int expressionColumnWidth) {
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);
    HeatMapTableModel tableModel = (HeatMapTableModel) table.getModel();
    TableColumnModel columnModel = table.getColumnModel();
    TableCellRenderer vertRenderer = new ColumnHeaderVerticalRenderer();
    TableCellRenderer vertRendererPheno1 = new ColumnHeaderVerticalRenderer(EMStyleBuilder.Colors.LIGHTEST_PHENOTYPE_1);
    TableCellRenderer vertRendererPheno2 = new ColumnHeaderVerticalRenderer(EMStyleBuilder.Colors.LIGHTEST_PHENOTYPE_2);
    TableColumn rankColumn = columnModel.getColumn(HeatMapTableModel.RANK_COL);
    rankColumn.setHeaderRenderer(columnHeaderRankOptionRendererFactory.create(this, HeatMapTableModel.RANK_COL));
    rankColumn.setPreferredWidth(100);
    ((TableRowSorter<?>) table.getRowSorter()).setSortable(HeatMapTableModel.RANK_COL, false);
    int colCount = tableModel.getColumnCount();
    for (int col = HeatMapTableModel.DESC_COL_COUNT; col < colCount; col++) {
        EMDataSet dataset = tableModel.getDataSet(col);
        String pheno1 = dataset.getEnrichments().getPhenotype1();
        String pheno2 = dataset.getEnrichments().getPhenotype2();
        Optional<String> pheno = tableModel.getPhenotype(col);
        TableCellRenderer renderer;
        if (pheno.filter(p -> p.equals(pheno1)).isPresent())
            renderer = vertRendererPheno1;
        else if (pheno.filter(p -> p.equals(pheno2)).isPresent())
            renderer = vertRendererPheno2;
        else
            renderer = vertRenderer;
        TableColumn column = columnModel.getColumn(col);
        column.setHeaderRenderer(renderer);
        column.setPreferredWidth(expressionColumnWidth);
    }
}
Also used : Arrays(java.util.Arrays) Inject(com.google.inject.Inject) AfterInjection(org.baderlab.csplugins.enrichmentmap.AfterInjection) HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) Operator(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Operator) JTableHeader(javax.swing.table.JTableHeader) TableCellRenderer(javax.swing.table.TableCellRenderer) IconManager(org.cytoscape.util.swing.IconManager) Assisted(com.google.inject.assistedinject.Assisted) ComboItem(org.baderlab.csplugins.enrichmentmap.view.util.ComboItem) Map(java.util.Map) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) DEFAULT_SIZE(javax.swing.GroupLayout.DEFAULT_SIZE) Set(java.util.Set) ColorAndValueRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColorAndValueRenderer) Distance(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Distance) Component(java.awt.Component) Collectors(java.util.stream.Collectors) TableRowSorter(javax.swing.table.TableRowSorter) Sets(com.google.common.collect.Sets) PREFERRED_SIZE(javax.swing.GroupLayout.PREFERRED_SIZE) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) SwingUtil(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil) ColumnHeaderRankOptionRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderRankOptionRenderer) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) ColumnHeaderVerticalRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderVerticalRenderer) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) ActionListener(java.awt.event.ActionListener) TableColumnModel(javax.swing.table.TableColumnModel) SortKey(javax.swing.RowSorter.SortKey) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CompletableFuture(java.util.concurrent.CompletableFuture) GradientLegendPanel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.GradientLegendPanel) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) EMStyleBuilder(org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder) JButton(javax.swing.JButton) Transform(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Transform) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) ActionEvent(java.awt.event.ActionEvent) RankOptionErrorHeader(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankOptionErrorHeader) RankValueRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValueRenderer) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) ColorRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColorRenderer) Comparator(java.util.Comparator) TableCellRenderer(javax.swing.table.TableCellRenderer) HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) ColumnHeaderVerticalRenderer(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.ColumnHeaderVerticalRenderer) TableColumn(javax.swing.table.TableColumn) TableRowSorter(javax.swing.table.TableRowSorter)

Example 3 with HeatMapTableModel

use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel in project EnrichmentMapApp by BaderLab.

the class ExportTXTAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ae) {
    File file = promptForFile();
    if (file == null)
        return;
    HeatMapTableModel tableModel = (HeatMapTableModel) table.getModel();
    boolean leadingEdgeOnly = promptForLeadingEdgeOnly(tableModel);
    try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
        int numCols = tableModel.getColumnCount();
        // Print column headers
        out.append(tableModel.getColumnName(HeatMapTableModel.GENE_COL));
        out.append("\t");
        // Skip the ranks column
        for (int col = HeatMapTableModel.DESC_COL_COUNT; col < numCols; col++) {
            out.append(tableModel.getColumnName(col));
            out.append(col == numCols - 1 ? "\n" : "\t");
        }
        RowSorter<?> sorter = table.getRowSorter();
        int numViewRows = sorter.getViewRowCount();
        // Print table data
        for (int viewRow = 0; viewRow < numViewRows; viewRow++) {
            int modelRow = sorter.convertRowIndexToModel(viewRow);
            if (leadingEdgeOnly && !tableModel.getRankValue(modelRow).isSignificant())
                continue;
            out.append(tableModel.getValueAt(modelRow, HeatMapTableModel.GENE_COL).toString());
            out.append("\t");
            for (int col = HeatMapTableModel.DESC_COL_COUNT; col < numCols; col++) {
                out.append(tableModel.getValueAt(modelRow, col).toString());
                out.append(col == numCols - 1 ? "\n" : "\t");
            }
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(jframeProvider.get(), e.getMessage(), "Error writing file", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}
Also used : HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 4 with HeatMapTableModel

use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method updateSetting_RankOption.

public void updateSetting_RankOption(RankingOption rankOption) {
    selectedRankOption = rankOption;
    List<String> genes = getGenes(getOperator());
    HeatMapTableModel tableModel = (HeatMapTableModel) table.getModel();
    EnrichmentMap map = tableModel.getEnrichmentMap();
    List<Integer> geneIds = genes.stream().map(map::getHashFromGene).collect(Collectors.toList());
    CompletableFuture<Optional<Map<Integer, RankValue>>> rankingFuture = rankOption.computeRanking(geneIds);
    if (rankingFuture != null) {
        rankingFuture.whenComplete((ranking, ex) -> {
            if (ranking.isPresent()) {
                tableModel.setRanking(rankOption.getName(), ranking.get());
                table.getColumnModel().getColumn(HeatMapTableModel.RANK_COL).setHeaderValue(rankOption);
            } else {
                tableModel.setRanking(rankOption.getName(), null);
                table.getColumnModel().getColumn(HeatMapTableModel.RANK_COL).setHeaderValue(new RankOptionErrorHeader(rankOption));
            }
            table.getTableHeader().repaint();
        });
    }
    settingChanged();
}
Also used : Optional(java.util.Optional) HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) RankOptionErrorHeader(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankOptionErrorHeader)

Example 5 with HeatMapTableModel

use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel in project EnrichmentMapApp by BaderLab.

the class HeatMapMainPanel method reset.

public void reset(EnrichmentMap map, HeatMapParams params, List<RankingOption> moreRankOptions, Set<String> union, Set<String> intersection) {
    isResetting = true;
    this.clusterRankOption = parent.getMediator().getClusterRankOption(map);
    this.moreRankOptions = moreRankOptions.isEmpty() ? Arrays.asList(RankingOption.none()) : moreRankOptions;
    unionGenes = new ArrayList<>(union);
    unionGenes.sort(Comparator.naturalOrder());
    interGenes = new ArrayList<>(intersection);
    interGenes.sort(Comparator.naturalOrder());
    operatorCombo.removeActionListener(operatorActionListener);
    normCombo.removeActionListener(normActionListener);
    showValuesCheck.removeActionListener(showValueActionListener);
    // Update Combo Boxes
    operatorCombo.removeAllItems();
    operatorCombo.addItem(new ComboItem<>(Operator.UNION, "All (" + union.size() + ")"));
    operatorCombo.addItem(new ComboItem<>(Operator.INTERSECTION, "Common (" + intersection.size() + ")"));
    operatorCombo.setSelectedItem(ComboItem.of(params.getOperator()));
    normCombo.setSelectedItem(ComboItem.of(params.getTransform()));
    selectedRankOption = getRankOptionFromParams(params);
    // Update the setings panel
    settingsPanel.update(params);
    showValuesCheck.setSelected(params.isShowValues());
    // Update the Table
    clearTableHeader();
    List<String> genesToUse = params.getOperator() == Operator.UNION ? unionGenes : interGenes;
    List<? extends SortKey> sortKeys = table.getRowSorter().getSortKeys();
    HeatMapTableModel tableModel = new HeatMapTableModel(map, null, genesToUse, params.getTransform());
    table.setModel(tableModel);
    updateSetting_ShowValues(params.isShowValues());
    try {
        table.getRowSorter().setSortKeys(sortKeys);
    } catch (IllegalArgumentException e) {
    }
    // Re-compute the ranking
    updateSetting_RankOption(selectedRankOption);
    operatorCombo.addActionListener(operatorActionListener);
    normCombo.addActionListener(normActionListener);
    showValuesCheck.addActionListener(showValueActionListener);
    isResetting = false;
}
Also used : HeatMapTableModel(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel)

Aggregations

HeatMapTableModel (org.baderlab.csplugins.enrichmentmap.view.heatmap.table.HeatMapTableModel)7 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)4 Optional (java.util.Optional)2 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 Assisted (com.google.inject.assistedinject.Assisted)1 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1