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