use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue in project EnrichmentMapApp by BaderLab.
the class GSEALeadingEdgeRankingOption method computeRanking.
@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
initializeLeadingEdge();
int topRank = getTopRank();
boolean isNegative = isNegativeGS();
Map<Integer, GeneExpression> expressions = dataset.getExpressionSets().getExpressionMatrix();
Ranking ranking = dataset.getExpressionSets().getRanksByName(rankingName);
Integer[] ranksSubset = new Integer[expressions.size()];
HashMap<Integer, ArrayList<Integer>> rank2keys = new HashMap<Integer, ArrayList<Integer>>();
int n = 0;
Map<Integer, Rank> currentRanks = ranking.getRanking();
for (Integer key : expressions.keySet()) {
if (currentRanks.containsKey(key)) {
ranksSubset[n] = currentRanks.get(key).getRank();
} else {
ranksSubset[n] = -1;
}
rank2keys.computeIfAbsent(ranksSubset[n], k -> new ArrayList<>()).add(key);
n++;
}
Map<Integer, RankValue> result = new HashMap<>();
int previous = -1;
boolean significant = false;
for (int m = 0; m < ranksSubset.length; m++) {
//if the current gene doesn't have a rank then don't show it
if (ranksSubset[m] == -1)
continue;
if (ranksSubset[m] == previous)
continue;
previous = ranksSubset[m];
significant = false;
if (ranksSubset[m] <= topRank && !isNegative && topRank != 0 && topRank != -1)
significant = true;
else if (ranksSubset[m] >= topRank && isNegative && topRank != 0 && topRank != -1)
significant = true;
List<Integer> keys = rank2keys.get(ranksSubset[m]);
for (Integer key : keys) {
Rank rank = currentRanks.get(key);
result.put(key, new RankValue(rank.getRank(), rank.getScore(), significant));
}
}
// Remove genes that we don't need
result.keySet().retainAll(genes);
BasicRankingOption.normalizeRanks(result);
return CompletableFuture.completedFuture(Optional.of(result));
}
use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue 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);
}
use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue 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.RankValue in project EnrichmentMapApp by BaderLab.
the class BasicRankingOption method computeRanking.
@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
Map<Integer, RankValue> result = new HashMap<>();
for (Map.Entry<Integer, Rank> entry : ranking.getRanking().entrySet()) {
Rank rank = entry.getValue();
result.put(entry.getKey(), new RankValue(rank.getRank(), rank.getScore(), false));
}
// Remove genes that we don't need
result.keySet().retainAll(genes);
normalizeRanks(result);
return CompletableFuture.completedFuture(Optional.of(result));
}
use of org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue in project EnrichmentMapApp by BaderLab.
the class ClusterRankingOption method computeRanking.
@Override
public CompletableFuture<Optional<Map<Integer, RankValue>>> computeRanking(Collection<Integer> genes) {
if (genes.size() < 2) {
// The HierarchicalClusterTask requires at least 2 genes
return CompletableFuture.completedFuture(Optional.of(Collections.emptyMap()));
}
HierarchicalClusterTask task = new HierarchicalClusterTask(map, genes, distance.getMetric());
CompletableFuture<Optional<Map<Integer, RankValue>>> future = new CompletableFuture<>();
taskManager.execute(new TaskIterator(task), new TaskObserver() {
@Override
public void taskFinished(ObservableTask task) {
if (task instanceof HierarchicalClusterTask) {
HierarchicalClusterTask clusterTask = (HierarchicalClusterTask) task;
Optional<Map<Integer, RankValue>> ranking = clusterTask.getActualResults();
future.complete(ranking);
}
}
@Override
public void allFinished(FinishStatus finishStatus) {
// Don't see why this would ever happen
if (!future.isDone()) {
future.completeExceptionally(new RuntimeException("Failed"));
}
}
});
return future;
}
Aggregations