Search in sources :

Example 1 with GeneExpression

use of org.baderlab.csplugins.enrichmentmap.model.GeneExpression 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));
}
Also used : Method(org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression) DetermineEnrichmentResultFileReader(org.baderlab.csplugins.enrichmentmap.parsers.DetermineEnrichmentResultFileReader) Collection(java.util.Collection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) GSEAResult(org.baderlab.csplugins.enrichmentmap.model.GSEAResult) ArrayList(java.util.ArrayList) List(java.util.List) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) SwingUtil(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil) Map(java.util.Map) Rank(org.baderlab.csplugins.enrichmentmap.model.Rank) Optional(java.util.Optional) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) EnrichmentResult(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Rank(org.baderlab.csplugins.enrichmentmap.model.Rank) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression)

Example 2 with GeneExpression

use of org.baderlab.csplugins.enrichmentmap.model.GeneExpression in project EnrichmentMapApp by BaderLab.

the class LegacySessionLoadTest method test_1_LoadedLegacyData.

@Test
@SessionFile("em_session_2.2.cys")
public void test_1_LoadedLegacyData() throws Exception {
    EnrichmentMap map = getEnrichmentMap();
    assertEquals("EM1_Enrichment Map", map.getName());
    CyNetwork network = networkManager.getNetwork(map.getNetworkID());
    assertNotNull(network);
    assertEquals(1, map.getDataSetCount());
    assertEquals(14067, map.getNumberOfGenes());
    assertEquals(14067, map.getAllGenes().size());
    // Number of edges: 3339 - that's how many geneset similarity objects there should be!!!
    CyTable edgeTable = network.getDefaultEdgeTable();
    assertEquals(3339, edgeTable.getRowCount());
    EMCreationParameters params = map.getParams();
    String prefix = params.getAttributePrefix();
    assertEquals("EM1_", prefix);
    assertEquals(0.5, params.getCombinedConstant(), 0.0);
    assertFalse(params.isEMgmt());
    assertEquals("Geneset_Overlap", params.getEnrichmentEdgeType());
    assertTrue(params.isFDR());
    assertEquals(GreatFilter.HYPER, params.getGreatFilter());
    assertEquals(0.005, params.getPvalue(), 0.0);
    assertEquals(1.0, params.getPvalueMin(), 0.0);
    assertEquals(0.1, params.getQvalue(), 0.0);
    assertEquals(1.0, params.getQvalueMin(), 0.0);
    assertEquals(0.5, params.getSimilarityCutoff(), 0.0);
    assertEquals(SimilarityMetric.OVERLAP, params.getSimilarityMetric());
    //		assertFalse(params.isDistinctExpressionSets());
    String geneset1 = "RESOLUTION OF SISTER CHROMATID COHESION%REACTOME%REACT_150425.2";
    String geneset2 = "CHROMOSOME, CENTROMERIC REGION%GO%GO:0000775";
    Collection<CyRow> rows = edgeTable.getMatchingRows(CyNetwork.NAME, geneset1 + " (Geneset_Overlap) " + geneset2);
    assertEquals(1, rows.size());
    CyRow row = rows.iterator().next();
    assertEquals("Geneset_Overlap", row.get(CyEdge.INTERACTION, String.class));
    assertEquals(0.6097560975609756, EMStyleBuilder.Columns.EDGE_SIMILARITY_COEFF.get(row, prefix), 0.0);
    EMDataSet dataset = map.getDataSet("Dataset 1");
    assertNotNull(dataset);
    assertSame(map, dataset.getMap());
    assertEquals(Method.GSEA, dataset.getMethod());
    assertEquals(12653, dataset.getDataSetGenes().size());
    assertEquals(389, dataset.getGeneSetsOfInterest().getGeneSets().size());
    //		assertEquals(17259, dataset.getSetofgenesets().getGenesets().size()); // MKTODO why? what is this used for
    assertEndsWith(dataset.getSetOfGeneSets().getFilename(), "Human_GO_AllPathways_no_GO_iea_April_15_2013_symbol.gmt");
    for (long suid : dataset.getNodeSuids()) {
        assertNotNull(network.getNode(suid));
    }
    GeneSet geneset = dataset.getGeneSetsOfInterest().getGeneSets().get("NCRNA PROCESSING%GO%GO:0034470");
    assertEquals(88, geneset.getGenes().size());
    assertEquals("NCRNA PROCESSING%GO%GO:0034470", geneset.getName());
    assertEquals("ncRNA processing", geneset.getDescription());
    assertEquals(Optional.of("GO"), geneset.getSource());
    SetOfEnrichmentResults enrichments = dataset.getEnrichments();
    assertEquals(4756, enrichments.getEnrichments().size());
    assertEndsWith(enrichments.getFilename1(), "gsea_report_for_ES12_1473194913081.xls");
    assertEndsWith(enrichments.getFilename2(), "gsea_report_for_NT12_1473194913081.xls");
    assertEquals("ES12", enrichments.getPhenotype1());
    assertEquals("NT12", enrichments.getPhenotype2());
    EnrichmentResult result = enrichments.getEnrichments().get("RIBONUCLEOSIDE TRIPHOSPHATE BIOSYNTHETIC PROCESS%GO%GO:0009201");
    assertTrue(result instanceof GSEAResult);
    GSEAResult gseaResult = (GSEAResult) result;
    assertEquals("RIBONUCLEOSIDE TRIPHOSPHATE BIOSYNTHETIC PROCESS%GO%GO:0009201", gseaResult.getName());
    assertEquals(0.42844063, gseaResult.getES(), 0.0);
    assertEquals(0.45225498, gseaResult.getFdrqvalue(), 0.0);
    assertEquals(1.0, gseaResult.getFwerqvalue(), 0.0);
    assertEquals(23, gseaResult.getGsSize());
    assertEquals(1.1938541, gseaResult.getNES(), 0.0);
    assertEquals(0.2457786, gseaResult.getPvalue(), 0.0);
    assertEquals(4689, gseaResult.getRankAtMax());
    assertEquals(Optional.of("GO"), gseaResult.getSource());
    GeneExpressionMatrix expressions = dataset.getExpressionSets();
    assertEquals(20326, expressions.getExpressionUniverse());
    assertEquals(3.686190609, expressions.getClosesttoZero(), 0.0);
    //		assertEndsWith(expressions.getFilename(), "MCF7_ExprMx_v2_names.gct");
    assertEquals(15380.42388, expressions.getMaxExpression(), 0.0);
    assertEquals(3.686190609, expressions.getMinExpression(), 0.0);
    assertEquals(20, expressions.getNumConditions());
    assertEquals(12653, expressions.getExpressionMatrix().size());
    assertEquals(12653, expressions.getExpressionMatrix_rowNormalized().size());
    GeneExpression expression = expressions.getExpressionMatrix().get(0);
    assertEquals("MOCOS", expression.getName());
    assertEquals("MOCOS (molybdenum cofactor sulfurase)", expression.getDescription());
    assertEquals(18, expression.getExpression().length);
    Ranking ranking = expressions.getRanks().get("GSEARanking");
    assertEquals(12653, ranking.getAllRanks().size());
    assertEquals(12653, ranking.getRanking().size());
    Rank rank = ranking.getRanking().get(0);
    assertEquals("MOCOS", rank.getName());
    assertEquals(1238, rank.getRank().intValue());
    assertEquals(0.54488367, rank.getScore(), 0.0);
    DataSetFiles files = dataset.getDataSetFiles();
    assertEndsWith(files.getClassFile(), "ES_NT.cls");
    assertEndsWith(files.getEnrichmentFileName1(), "gsea_report_for_ES12_1473194913081.xls");
    assertEndsWith(files.getEnrichmentFileName2(), "gsea_report_for_NT12_1473194913081.xls");
    //		assertEndsWith(files.getExpressionFileName(), "MCF7_ExprMx_v2_names.gct");
    assertEndsWith(files.getGMTFileName(), "Human_GO_AllPathways_no_GO_iea_April_15_2013_symbol.gmt");
    assertEndsWith(files.getGseaHtmlReportFile(), "estrogen_treatment_12hr_gsea_enrichment_results.Gsea.1473194913081/index.html");
    assertEndsWith(files.getRankedFile(), "ranked_gene_list_ES12_versus_NT12_1473194913081.xls");
    assertEquals("ES12", files.getPhenotype1());
    assertEquals("NT12", files.getPhenotype2());
}
Also used : EnrichmentResult(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult) EMCreationParameters(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters) GSEAResult(org.baderlab.csplugins.enrichmentmap.model.GSEAResult) CyNetwork(org.cytoscape.model.CyNetwork) Rank(org.baderlab.csplugins.enrichmentmap.model.Rank) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow) GeneExpressionMatrix(org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix) CyTable(org.cytoscape.model.CyTable) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression) DataSetFiles(org.baderlab.csplugins.enrichmentmap.model.DataSetFiles) SetOfEnrichmentResults(org.baderlab.csplugins.enrichmentmap.model.SetOfEnrichmentResults) BaseIntegrationTest(org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest) Test(org.junit.Test) SessionFile(org.baderlab.csplugins.enrichmentmap.integration.SessionFile)

Example 3 with GeneExpression

use of org.baderlab.csplugins.enrichmentmap.model.GeneExpression in project EnrichmentMapApp by BaderLab.

the class CreateDummyExpressionTask method createDummyExpression.

//Create a dummy expression file so that when no expression files are loaded you can still
//use the intersect and union viewers.
private void createDummyExpression() {
    //in order to see the gene in the expression viewer we also need a dummy expression file
    //get all the genes
    //HashMap<String, Integer> genes= dataset.getMap().getGenes();
    Set<Integer> datasetGenes;
    Map<String, Integer> genes = dataset.getMap().getGeneSetsGenes(dataset.getSetOfGeneSets().getGeneSets().values());
    datasetGenes = dataset.getDataSetGenes();
    String[] titletokens = { "Name", "Description", "Dummy" };
    GeneExpressionMatrix expressionMatrix = dataset.getExpressionSets();
    expressionMatrix.setColumnNames(titletokens);
    Map<Integer, GeneExpression> expression = expressionMatrix.getExpressionMatrix();
    expressionMatrix.setExpressionMatrix(expression);
    String[] tokens = { "tmp", "tmp", "0.25" };
    for (String currentGene : genes.keySet()) {
        int genekey = genes.get(currentGene);
        if (datasetGenes != null)
            datasetGenes.add(genekey);
        GeneExpression expres = new GeneExpression(currentGene, currentGene);
        expres.setExpression(tokens);
        double newMax = expres.newMax(expressionMatrix.getMaxExpression());
        if (newMax != -100)
            expressionMatrix.setMaxExpression(newMax);
        double newMin = expres.newMin(expressionMatrix.getMinExpression());
        if (newMin != -100)
            expressionMatrix.setMinExpression(newMin);
        double newClosest = expres.newclosesttoZero(expressionMatrix.getClosesttoZero());
        if (newClosest != -100)
            expressionMatrix.setClosesttoZero(newClosest);
        expression.put(genekey, expres);
    }
    //set the number of genes
    //expressionMatrix.setNumGenes(expressionMatrix.getExpressionMatrix().size());
    expressionMatrix.setNumConditions(3);
    expressionMatrix.setFilename("Dummy Expression_" + dataset.getName().toString());
    dataset.setDummyExpressionData(true);
}
Also used : GeneExpressionMatrix(org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression)

Example 4 with GeneExpression

use of org.baderlab.csplugins.enrichmentmap.model.GeneExpression in project EnrichmentMapApp by BaderLab.

the class HeatMapTableModel method getGeneExpression.

private static GeneExpression getGeneExpression(EMDataSet dataset, int geneID) {
    GeneExpressionMatrix matrix = dataset.getExpressionSets();
    Map<Integer, GeneExpression> expressions = matrix.getExpressionMatrix();
    GeneExpression row = expressions.get(geneID);
    return row;
}
Also used : GeneExpressionMatrix(org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression)

Example 5 with GeneExpression

use of org.baderlab.csplugins.enrichmentmap.model.GeneExpression in project EnrichmentMapApp by BaderLab.

the class HierarchicalClusterTask method cluster.

public Map<Integer, RankValue> cluster(TaskMonitor tm) {
    if (tm == null)
        tm = new NullTaskMonitor();
    tm.setTitle("Hierarchical Cluster");
    tm.setStatusMessage("Loading expression data");
    List<double[]> clusteringExpressionSet = new ArrayList<>(genes.size());
    ArrayList<Integer> labels = new ArrayList<>(genes.size());
    List<String> names = new ArrayList<>(genes.size());
    List<EMDataSet> dataSets = map.getDataSetList();
    final int expressionCount = getTotalExpressionCount(dataSets);
    for (int geneId : genes) {
        // values all default to 0.0
        double[] vals = new double[expressionCount];
        int valsIndex = 0;
        boolean found = false;
        String name = null;
        for (EMDataSet dataSet : dataSets) {
            GeneExpressionMatrix expressionSets = dataSet.getExpressionSets();
            int numConditions = expressionSets.getNumConditions() - 2;
            GeneExpression geneExpression = expressionSets.getExpressionMatrix().get(geneId);
            if (geneExpression != null) {
                found = true;
                name = geneExpression.getName();
                double[] expression = geneExpression.getExpression();
                System.arraycopy(expression, 0, vals, valsIndex, expression.length);
            }
            valsIndex += numConditions;
        }
        if (found) {
            clusteringExpressionSet.add(vals);
            labels.add(geneId);
            names.add(name);
        }
    }
    tm.setStatusMessage("Calculating Distance");
    DistanceMatrix distanceMatrix = new DistanceMatrix(genes.size());
    distanceMatrix.calcDistances(clusteringExpressionSet, distanceMetric);
    distanceMatrix.setLabels(labels);
    tm.setStatusMessage("Clustering");
    AvgLinkHierarchicalClustering clusterResult = new AvgLinkHierarchicalClustering(distanceMatrix);
    //check to see if there more than 1000 genes, if there are use eisen ordering otherwise use bar-joseph
    clusterResult.setOptimalLeafOrdering(genes.size() <= 1000);
    clusterResult.run();
    tm.setStatusMessage("Ranking");
    Map<Integer, RankValue> ranks = new HashMap<>();
    int[] order = clusterResult.getLeafOrder();
    for (int i = 0; i < order.length; i++) {
        Integer geneId = labels.get(order[i]);
        ranks.put(geneId, new RankValue(i + 1, null, false));
    }
    tm.setStatusMessage("");
    return ranks;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AvgLinkHierarchicalClustering(org.baderlab.csplugins.brainlib.AvgLinkHierarchicalClustering) RankValue(org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue) GeneExpressionMatrix(org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) DistanceMatrix(org.baderlab.csplugins.brainlib.DistanceMatrix) GeneExpression(org.baderlab.csplugins.enrichmentmap.model.GeneExpression) NullTaskMonitor(org.baderlab.csplugins.enrichmentmap.util.NullTaskMonitor)

Aggregations

GeneExpression (org.baderlab.csplugins.enrichmentmap.model.GeneExpression)6 GeneExpressionMatrix (org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)2 EnrichmentResult (org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult)2 GSEAResult (org.baderlab.csplugins.enrichmentmap.model.GSEAResult)2 Rank (org.baderlab.csplugins.enrichmentmap.model.Rank)2 Ranking (org.baderlab.csplugins.enrichmentmap.model.Ranking)2 NullTaskMonitor (org.baderlab.csplugins.enrichmentmap.util.NullTaskMonitor)2 RankValue (org.baderlab.csplugins.enrichmentmap.view.heatmap.table.RankValue)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AvgLinkHierarchicalClustering (org.baderlab.csplugins.brainlib.AvgLinkHierarchicalClustering)1 DistanceMatrix (org.baderlab.csplugins.brainlib.DistanceMatrix)1 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)1