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);
}
}
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);
}
}
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();
}
}
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();
}
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;
}
Aggregations