Search in sources :

Example 1 with RankingOption

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

the class HeatMapRanksTest method testLeadingEdge.

@Test
public void testLeadingEdge(EnrichmentMapManager emManager) throws Exception {
    final String geneSetName = "ENVELOPE%GO%GO:0031975";
    final int leadingEdgeSize = 170;
    // Sanity test
    EnrichmentMap map = emManager.getAllEnrichmentMaps().values().iterator().next();
    EMDataSet dataset = map.getDataSet(LegacySupport.DATASET1);
    GeneSet gs = dataset.getGeneSetsOfInterest().getGeneSets().get(geneSetName);
    assertNotNull(gs);
    // Run the ranking
    RankingOption rankingOption = new GSEALeadingEdgeRankingOption(dataset, geneSetName, Ranking.GSEARanking);
    Map<Integer, RankValue> ranks = rankingOption.computeRanking(gs.getGenes()).get().get();
    assertEquals(454, ranks.size());
    // Convert to useful collections
    Map<RankValue, Integer> rankToGeneId = HashBiMap.create(ranks).inverse();
    List<RankValue> sortedRanks = ranks.values().stream().sorted().collect(Collectors.toList());
    // Test leading edge
    for (int i = 0; i < sortedRanks.size(); i++) {
        RankValue v = sortedRanks.get(i);
        assertTrue(v.isSignificant() == i < leadingEdgeSize);
    }
    // Test genes are the same
    List<Integer> expectedGeneOrder = getGeneOrderFromFile(map, PATH + "gene_order_leading_edge.txt");
    List<Integer> actualGeneOrder = sortedRanks.stream().map(rankToGeneId::get).collect(Collectors.toList());
    assertEquals(expectedGeneOrder, actualGeneOrder);
}
Also used : RankingOption(org.baderlab.csplugins.enrichmentmap.view.heatmap.RankingOption) GSEALeadingEdgeRankingOption(org.baderlab.csplugins.enrichmentmap.view.heatmap.GSEALeadingEdgeRankingOption) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) GSEALeadingEdgeRankingOption(org.baderlab.csplugins.enrichmentmap.view.heatmap.GSEALeadingEdgeRankingOption) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) BaseNetworkTest(org.baderlab.csplugins.enrichmentmap.task.BaseNetworkTest) Test(org.junit.Test)

Example 2 with RankingOption

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

the class ColumnHeaderRankOptionRenderer method menuButtonClicked.

private void menuButtonClicked(JTable table, JButton button) {
    JTableHeader header = table.getTableHeader();
    List<RankingOption> rankOptions = mainPanel.getAllRankingOptions();
    JPopupMenu menu = new JPopupMenu();
    for (RankingOption rankOption : rankOptions) {
        JMenuItem item = new JCheckBoxMenuItem(rankOption.getName());
        item.setSelected(rankOption == mainPanel.getSelectedRankOption());
        SwingUtil.makeSmall(item);
        menu.add(item);
        item.addActionListener(e -> mainPanel.updateSetting_RankOption(rankOption));
    }
    int y = button.getHeight();
    int x = 0;
    for (int i = 0; i < colIndex; i++) {
        TableColumn tableColumn = table.getColumnModel().getColumn(i);
        x += tableColumn.getWidth();
    }
    menu.show(header, x, y);
}
Also used : JTableHeader(javax.swing.table.JTableHeader) RankingOption(org.baderlab.csplugins.enrichmentmap.view.heatmap.RankingOption) JMenuItem(javax.swing.JMenuItem) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 3 with RankingOption

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

the class ColumnHeaderRankOptionRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, final Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    // Convert RankingOption to display String
    String text = null;
    if (value instanceof RankingOption) {
        RankingOption rankingOption = (RankingOption) value;
        text = rankingOption.getTableHeaderText();
    } else if (value instanceof RankOptionErrorHeader) {
        RankOptionErrorHeader headerValue = (RankOptionErrorHeader) value;
        text = headerValue.getRankingOption().getTableHeaderText();
    }
    // Use the default renderer to paint the header nicely (with sort arrows)
    JTableHeader header = table.getTableHeader();
    TableCellRenderer delegate = table.getTableHeader().getDefaultRenderer();
    Component component = delegate.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, col);
    // Create the panel
    JButton button = new JButton("Sort");
    SwingUtil.makeSmall(button);
    if (isAquaLAF())
        button.putClientProperty("JButton.buttonType", "gradient");
    button.addActionListener(e -> menuButtonClicked(table, button));
    JPanel buttonPanel = new JPanel(new BorderLayout());
    buttonPanel.add(button, BorderLayout.CENTER);
    buttonPanel.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    buttonPanel.setForeground(header.getForeground());
    buttonPanel.setBackground(header.getBackground());
    JPanel panel = new JPanel(new BorderLayout());
    panel.setForeground(header.getForeground());
    panel.setBackground(header.getBackground());
    panel.add(component, BorderLayout.CENTER);
    panel.add(buttonPanel, BorderLayout.NORTH);
    if (value instanceof RankOptionErrorHeader) {
        JLabel icon = new JLabel(IconManager.ICON_TIMES_CIRCLE);
        icon.setForeground(Color.RED.darker());
        icon.setFont(iconManager.getIconFont(13.0f));
        icon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        icon.setOpaque(false);
        panel.add(icon, BorderLayout.WEST);
    }
    // Add mouse listener
    if (mouseListener != null) {
        header.removeMouseListener(mouseListener);
    }
    header.addMouseListener(mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int col = header.columnAtPoint(e.getPoint());
            if (col == colIndex)
                if (e.getY() <= button.getHeight())
                    button.doClick();
                else
                    sortColumn(table);
            else
                sortOrder = null;
        }
    });
    return panel;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) RankingOption(org.baderlab.csplugins.enrichmentmap.view.heatmap.RankingOption) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) Component(java.awt.Component)

Aggregations

RankingOption (org.baderlab.csplugins.enrichmentmap.view.heatmap.RankingOption)3 JTableHeader (javax.swing.table.JTableHeader)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 JButton (javax.swing.JButton)1 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1 JLabel (javax.swing.JLabel)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)1 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)1 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)1 BaseNetworkTest (org.baderlab.csplugins.enrichmentmap.task.BaseNetworkTest)1 GSEALeadingEdgeRankingOption (org.baderlab.csplugins.enrichmentmap.view.heatmap.GSEALeadingEdgeRankingOption)1 RankValue (org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue)1