Search in sources :

Example 6 with EnrichmentMap

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

the class ParseGenericEnrichmentResults method parseLines.

@Override
public void parseLines(List<String> lines, EMDataSet dataset, TaskMonitor taskMonitor) {
    if (taskMonitor == null)
        taskMonitor = new NullTaskMonitor();
    taskMonitor.setTitle("Parsing Generic Result file");
    //Get the current genesets so we can check that all the results are in the geneset list
    //and put the size of the genesets into the visual style
    Map<String, GeneSet> genesets = dataset.getSetOfGeneSets().getGeneSets();
    int currentProgress = 0;
    int maxValue = lines.size();
    taskMonitor.setStatusMessage("Parsing Generic Results file - " + maxValue + " rows");
    boolean FDR = false;
    //skip the first line which just has the field names (start i=1)
    //check to see how many columns the data has
    String line = lines.get(0);
    String[] tokens = line.split("\t");
    int length = tokens.length;
    EnrichmentMap map = dataset.getMap();
    SetOfEnrichmentResults enrichments = dataset.getEnrichments();
    Map<String, EnrichmentResult> results = enrichments.getEnrichments();
    String upPhenotype = enrichments.getPhenotype1();
    String downPhenotype = enrichments.getPhenotype2();
    //check to see if there are genesets.
    //if there are no genesets then populate the genesets from the generic file
    //can only do this if the 6th column has a list of genes for that geneset.
    boolean populate_gs = false;
    if (genesets == null || genesets.isEmpty())
        populate_gs = true;
    else
        //as this is the default for gprofiler use the Description in the visual style instead of the formatted name
        //but only if there is a gmt supplied.  If using just the generic output file there is not field for description
        dataset.getMap().getParams().setEMgmt(true);
    for (int i = 1; i < lines.size(); i++) {
        line = lines.get(i);
        tokens = line.split("\t");
        //update the length each time because some line might have missing values
        length = tokens.length;
        double pvalue = 1.0;
        double FDRqvalue = 1.0;
        GenericResult result;
        int gs_size = 0;
        double NES = 1.0;
        //The first column of the file is the name of the geneset
        final String name = tokens[0].toUpperCase().trim();
        final String description = tokens[1].toUpperCase();
        if (genesets.containsKey(name)) {
            gs_size = genesets.get(name).getGenes().size();
        }
        //The third column is the nominal p-value
        if (tokens[2] == null || tokens[2].equalsIgnoreCase("")) {
        //do nothing
        } else {
            pvalue = Double.parseDouble(tokens[2]);
        }
        if (length > 3) {
            //the fourth column is the FDR q-value
            if (tokens[3] == null || tokens[3].equalsIgnoreCase("")) {
            //do nothing
            } else {
                FDRqvalue = Double.parseDouble(tokens[3]);
                FDR = true;
            }
            // and if it is a number the only important part is the sign
            if (length > 4) {
                if (tokens[4] == null || tokens[4].equalsIgnoreCase("")) {
                } else {
                    //check to see if the string matches the specified phenotypes
                    if (tokens[4].equalsIgnoreCase(upPhenotype))
                        NES = 1.0;
                    else if (tokens[4].equalsIgnoreCase(downPhenotype))
                        NES = -1.0;
                    else //try and see if the user has specified the phenotype as a number
                    {
                        try {
                            NES = Double.parseDouble(tokens[4]);
                        } catch (NumberFormatException nfe) {
                            throw new IllegalThreadStateException(tokens[4] + " is not a valid phenotype.  Phenotype specified in generic enrichment results file must have the same phenotype as specified in advanced options or must be a positive or negative number.");
                        }
                    }
                }
                //its enrichment
                if (length > 5 && populate_gs) {
                    //get all the genes in the field
                    String[] gene_tokens = tokens[5].split(",");
                    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
                    //All subsequent fields in the list are the geneset associated with this geneset.
                    for (String token : gene_tokens) {
                        String gene = token.trim().toUpperCase();
                        //if it is already in the hash then get its associated key and put it into the set of genes
                        if (map.containsGene(gene)) {
                            builder.add(map.getHashFromGene(gene));
                        } else if (!gene.isEmpty()) {
                            Integer hash = map.addGene(gene).get();
                            builder.add(hash);
                        }
                    }
                    GeneSet gs = new GeneSet(name, description, builder.build());
                    gs_size = gs.getGenes().size();
                    //put the new or filtered geneset back into the set.
                    genesets.put(name, gs);
                }
                //end of tokens>5
                result = new GenericResult(name, description, pvalue, gs_size, FDRqvalue, NES);
            } else
                //end of tokens>4
                result = new GenericResult(name, description, pvalue, gs_size, FDRqvalue);
        } else {
            result = new GenericResult(name, description, pvalue, gs_size);
        }
        // Calculate Percentage.  This must be a value between 0..100.
        int percentComplete = (int) (((double) currentProgress / maxValue) * 100);
        taskMonitor.setProgress(percentComplete);
        currentProgress++;
        //check to see if the gene set has already been entered in the results
        //it is possible that one geneset will be in both phenotypes.
        //if it is already exists then we want to make sure the one retained is the result with the
        //lower p-value.
        //ticket #149
        GenericResult temp = (GenericResult) results.get(name);
        if (temp == null)
            results.put(name, result);
        else {
            if (result.getPvalue() < temp.getPvalue())
                results.put(name, result);
        }
    }
    if (FDR)
        dataset.getMap().getParams().setFDR(FDR);
}
Also used : EnrichmentResult(org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) GenericResult(org.baderlab.csplugins.enrichmentmap.model.GenericResult) ImmutableSet(com.google.common.collect.ImmutableSet) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) NullTaskMonitor(org.baderlab.csplugins.enrichmentmap.util.NullTaskMonitor) SetOfEnrichmentResults(org.baderlab.csplugins.enrichmentmap.model.SetOfEnrichmentResults)

Example 7 with EnrichmentMap

use of org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap 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 8 with EnrichmentMap

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

the class HeatMapMediator method getDataSetRankOptions.

private List<RankingOption> getDataSetRankOptions(EnrichmentMap map, CyNetwork network, List<CyNode> nodes, List<CyEdge> edges) {
    List<RankingOption> options = new ArrayList<>();
    for (EMDataSet dataset : map.getDataSetList()) {
        if (nodes.size() == 1 && edges.isEmpty() && dataset.getMethod() == Method.GSEA && contains(dataset, network, nodes.get(0))) {
            String geneSetName = network.getRow(nodes.get(0)).get(CyNetwork.NAME, String.class);
            Map<String, Ranking> ranks = dataset.getExpressionSets().getRanks();
            ranks.forEach((name, ranking) -> {
                options.add(new GSEALeadingEdgeRankingOption(dataset, geneSetName, name));
            });
        } else if (contains(network, dataset, nodes, edges)) {
            Map<String, Ranking> ranks = dataset.getExpressionSets().getRanks();
            ranks.forEach((name, ranking) -> {
                options.add(new BasicRankingOption(ranking, dataset, name));
            });
        }
    }
    return options;
}
Also used : CyNode(org.cytoscape.model.CyNode) Inject(com.google.inject.Inject) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) Operator(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Operator) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CyRow(org.cytoscape.model.CyRow) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) SetCurrentNetworkViewEvent(org.cytoscape.application.events.SetCurrentNetworkViewEvent) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyTableUtil(org.cytoscape.model.CyTableUtil) Method(org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method) EMStyleBuilder(org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder) Properties(java.util.Properties) Transform(org.baderlab.csplugins.enrichmentmap.view.heatmap.HeatMapParams.Transform) Collection(java.util.Collection) SetCurrentNetworkViewListener(org.cytoscape.application.events.SetCurrentNetworkViewListener) Set(java.util.Set) CyNetworkManager(org.cytoscape.model.CyNetworkManager) EnrichmentMapManager(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapManager) CytoPanel(org.cytoscape.application.swing.CytoPanel) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) RowsSetListener(org.cytoscape.model.events.RowsSetListener) List(java.util.List) CytoPanelComponent(org.cytoscape.application.swing.CytoPanelComponent) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) ArrayList(java.util.ArrayList) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) Map(java.util.Map)

Example 9 with EnrichmentMap

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

the class HeatMapMediator method updateHeatMap.

private void updateHeatMap(CyNetworkView networkView) {
    if (heatMapPanel == null)
        return;
    CyNetwork network = networkView.getModel();
    EnrichmentMap map = emManager.getEnrichmentMap(network.getSUID());
    if (map == null)
        return;
    List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
    List<CyEdge> selectedEdges = CyTableUtil.getEdgesInState(network, CyNetwork.SELECTED, true);
    String prefix = map.getParams().getAttributePrefix();
    this.onlyEdges = selectedNodes.isEmpty() && !selectedEdges.isEmpty();
    Set<String> union = unionGenesets(network, selectedNodes, selectedEdges, prefix);
    Set<String> inter = intersectionGenesets(network, selectedNodes, selectedEdges, prefix);
    List<RankingOption> rankOptions = getDataSetRankOptions(map, network, selectedNodes, selectedEdges);
    HeatMapParams params = getHeatMapParams(map, network.getSUID(), onlyEdges);
    heatMapPanel.selectGenes(map, params, rankOptions, union, inter);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyEdge(org.cytoscape.model.CyEdge)

Example 10 with EnrichmentMap

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

the class HeatMapMediator method heatMapParamsChanged.

/**
	 * Callback that HeatMapMainPanel calls.
	 */
public void heatMapParamsChanged(HeatMapParams params) {
    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
    if (networkView != null) {
        Long suid = networkView.getModel().getSUID();
        EnrichmentMap map = emManager.getEnrichmentMap(suid);
        // Overwrite all the params of the other one except 'operator'.
        // The 'operator' field is the only param that is kept separate.
        HeatMapParams otherParams = getHeatMapParams(map, suid, !onlyEdges);
        HeatMapParams newOtherParams = new HeatMapParams.Builder(params).setOperator(otherParams.getOperator()).build();
        emManager.registerHeatMapParams(suid, !onlyEdges, newOtherParams);
        emManager.registerHeatMapParams(suid, onlyEdges, params);
    }
}
Also used : EMStyleBuilder(org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)57 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)27 Test (org.junit.Test)22 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)21 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)13 Method (org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method)13 CyNetwork (org.cytoscape.model.CyNetwork)12 EnrichmentMapParameters (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapParameters)11 EnrichmentResult (org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult)10 CyNetworkView (org.cytoscape.view.model.CyNetworkView)10 Map (java.util.Map)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 NullTaskMonitor (org.baderlab.csplugins.enrichmentmap.util.NullTaskMonitor)6 TaskIterator (org.cytoscape.work.TaskIterator)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 HashSet (java.util.HashSet)5 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)5 Inject (com.google.inject.Inject)4 ActionEvent (java.awt.event.ActionEvent)4