use of org.baderlab.csplugins.enrichmentmap.util.Baton in project EnrichmentMapApp by BaderLab.
the class GeneSetSimilarityTest method testCombindCalculations.
@Test
public void testCombindCalculations() throws Exception {
double combined_constant = 0.5;
//set the parameters in the params to use jaccard coeffecient calculation
map.getParams().setSimilarityMetric(EMCreationParameters.SimilarityMetric.COMBINED);
//set the cutoff to the max
map.getParams().setSimilarityCutoff(0);
map.getParams().setCombinedConstant(combined_constant);
Baton<Map<SimilarityKey, GenesetSimilarity>> baton = new Baton<>();
ComputeSimilarityTaskParallel sim_task = new ComputeSimilarityTaskParallel(map, baton.consumer());
sim_task.run(taskMonitor);
Map<SimilarityKey, GenesetSimilarity> similarities = baton.supplier().get();
assertEquals(15, similarities.size());
//SetOfGeneSets gs_set = map.getDataset(EnrichmentMap.DATASET1).getSetofgenesets();
//check the gene set similarity between APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4
//and APOPTOSIS%REACTOME%REACT_578.5
GenesetSimilarity similarity;
// Set A has 13 elements, Set B has 142 elements, They have 13 elements in common
Double combined = (combined_constant * (13.0 / 13.0)) + ((1 - combined_constant) * (13.0 / 142.0));
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOSIS%REACTOME%REACT_578.5", "Geneset_Overlap", null));
assertEquals(combined, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(13, similarity.getSizeOfOverlap());
if ("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4".equals(similarity.getGeneset1Name())) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOSIS%REACTOME%REACT_578.5", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOSIS%REACTOME%REACT_578.5", similarity.getGeneset1Name());
}
// Set A has 13 elements, Set B has 9 elements, They have 1 elements in common
combined = (combined_constant * (1.0 / 9.0)) + ((1 - combined_constant) * (1.0 / 21.0));
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", "Geneset_Overlap", null));
assertEquals(combined, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(1, similarity.getSizeOfOverlap());
assertTrue(similarity.getOverlappingGenes().contains(map.getHashFromGene("CASP3")));
if ("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4".equals(similarity.getGeneset1Name())) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", similarity.getGeneset1Name());
}
// Set A has 13 elements, Set B has 7 elements, They have 1 elements in common
combined = (combined_constant * (1.0 / 7.0)) + ((1 - combined_constant) * (1.0 / 19.0));
;
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", "Geneset_Overlap", null));
assertEquals(combined, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(1, similarity.getSizeOfOverlap());
assertTrue(similarity.getOverlappingGenes().contains(map.getHashFromGene("CASP3")));
if ("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4".equals(similarity.getGeneset1Name())) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", similarity.getGeneset1Name());
}
}
use of org.baderlab.csplugins.enrichmentmap.util.Baton in project EnrichmentMapApp by BaderLab.
the class GeneSetSimilarityTest method testJaccardCalculations.
@Test
public void testJaccardCalculations() throws Exception {
//set the parameters in the params to use jaccard coeffecient calculation
map.getParams().setSimilarityMetric(EMCreationParameters.SimilarityMetric.JACCARD);
//set the cutoff to the max
map.getParams().setSimilarityCutoff(0);
Baton<Map<SimilarityKey, GenesetSimilarity>> baton = new Baton<>();
ComputeSimilarityTaskParallel sim_task = new ComputeSimilarityTaskParallel(map, baton.consumer());
sim_task.run(taskMonitor);
Map<SimilarityKey, GenesetSimilarity> similarities = baton.supplier().get();
assertEquals(15, similarities.size());
//check the gene set similarity between APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4
//and APOPTOSIS%REACTOME%REACT_578.5
GenesetSimilarity similarity;
// Set A has 13 elements, Set B has 142 elements, They have 13 elements in common
Double jaccard = 13.0 / 142.0;
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOSIS%REACTOME%REACT_578.5", "Geneset_Overlap", null));
assertEquals(jaccard, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(13, similarity.getSizeOfOverlap());
if (similarity.getGeneset1Name().equals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4")) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOSIS%REACTOME%REACT_578.5", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOSIS%REACTOME%REACT_578.5", similarity.getGeneset1Name());
}
// Set A has 13 elements, Set B has 9 elements, They have 1 elements in common
jaccard = 1.0 / 21.0;
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", "Geneset_Overlap", null));
assertEquals(jaccard, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(1, similarity.getSizeOfOverlap());
assertTrue(similarity.getOverlappingGenes().contains(map.getHashFromGene("CASP3")));
if ("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4".equals(similarity.getGeneset1Name())) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOTIC CLEAVAGE OF CELL ADHESION PROTEINS%REACTOME%REACT_13579.1", similarity.getGeneset1Name());
}
// Set A has 13 elements, Set B has 7 elements, They have 1 elements in common
jaccard = 1.0 / 19.0;
similarity = similarities.get(new SimilarityKey("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", "APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", "Geneset_Overlap", null));
assertEquals(jaccard, similarity.getSimilarityCoeffecient(), 0.0);
assertEquals(1, similarity.getSizeOfOverlap());
assertTrue(similarity.getOverlappingGenes().contains(map.getHashFromGene("CASP3")));
if ("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4".equals(similarity.getGeneset1Name())) {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset1Name());
assertEquals("APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", similarity.getGeneset2Name());
} else {
assertEquals("APOPTOSIS INDUCED DNA FRAGMENTATION%REACTOME%REACT_1213.4", similarity.getGeneset2Name());
assertEquals("APOPTOTIC FACTOR-MEDIATED RESPONSE%REACTOME%REACT_963.2", similarity.getGeneset1Name());
}
}
use of org.baderlab.csplugins.enrichmentmap.util.Baton in project EnrichmentMapApp by BaderLab.
the class CreateEnrichmentMapTaskFactory method createTaskIterator.
@Override
public TaskIterator createTaskIterator() {
TaskIterator tasks = new TaskIterator();
if (dataSets.isEmpty())
return tasks;
tasks.append(new TitleTask("Building EnrichmentMap"));
EnrichmentMap map = new EnrichmentMap(params, serviceRegistrar);
for (DataSetParameters dataSetParameters : dataSets) {
String datasetName = dataSetParameters.getName();
Method method = dataSetParameters.getMethod();
DataSetFiles files = dataSetParameters.getFiles();
EMDataSet dataset = map.createDataSet(datasetName, method, files);
// Load GMT File
if (!Strings.isNullOrEmpty(dataset.getSetOfGeneSets().getFilename())) {
tasks.append(new GMTFileReaderTask(dataset));
}
// Load the enrichments
tasks.append(new DetermineEnrichmentResultFileReader(dataset).getParsers());
// If there is no expression file then create a dummy file to associate with this dataset so we can still use the expression viewer (heat map)
if (Strings.isNullOrEmpty(dataset.getDataSetFiles().getExpressionFileName())) {
tasks.append(new CreateDummyExpressionTask(dataset));
} else {
tasks.append(new ExpressionFileReaderTask(dataset));
}
// Load ranks if present
String ranksName = dataset.getMethod() == Method.GSEA ? Ranking.GSEARanking : datasetName;
if (dataset.getExpressionSets().getRanksByName(ranksName) != null) {
String filename = dataset.getExpressionSets().getRanksByName(ranksName).getFilename();
tasks.append(new RanksFileReaderTask(filename, dataset, ranksName, false));
}
if (!Strings.isNullOrEmpty(dataset.getDataSetFiles().getClassFile())) {
tasks.append(new ClassFileReaderTask(dataset));
}
}
// NOTE: First filter out genesets that don't pass the thresholds,
// Then filter the remaining genesets of interest to only contain genes from the expression file.
// Filter out genesets that don't pass the p-value and q-value thresholds
InitializeGenesetsOfInterestTask genesetsTask = new InitializeGenesetsOfInterestTask(map);
// genesetsTask.setThrowIfMissing(false); // TEMPORARY
tasks.append(genesetsTask);
// Trim the genesets to only contain the genes that are in the data file.
tasks.append(new FilterGenesetsByDatasetGenes(map));
// Link the ComputeSimilarityTask to the MasterMapNetworkTask by a "pipe"
Baton<Map<SimilarityKey, GenesetSimilarity>> pipe = new Baton<>();
// Compute the geneset similarities
tasks.append(new ComputeSimilarityTaskParallel(map, pipe.consumer()));
// Create the network
tasks.append(createEMNetworkTaskFactory.create(map, pipe.supplier()));
// Create style and layout
if (!headless) {
tasks.append(createEMViewTaskFactory.create(map));
}
return tasks;
}
use of org.baderlab.csplugins.enrichmentmap.util.Baton in project EnrichmentMapApp by BaderLab.
the class LoadGMTFileOnlyTest method testGMTOnly.
@Test
public void testGMTOnly() throws Exception {
//for a dataset we require genesets, an expression file (optional), enrichment results
String testGmtFileName = "src/test/resources/org/baderlab/csplugins/enrichmentmap/task/genesets_subset.gmt";
DataSetFiles files = new DataSetFiles();
files.setGMTFileName(testGmtFileName);
//create an new enrichment Map
double similarityCutoff = 0.5;
double pvalue = 1.0;
double qvalue = 1.0;
EMCreationParameters params = new EMCreationParameters("EM1_", pvalue, qvalue, NESFilter.ALL, Optional.empty(), SimilarityMetric.JACCARD, similarityCutoff, 0.5);
EnrichmentMap em = new EnrichmentMap(params, serviceRegistrar);
//Load data set
//create a dataset
EMDataSet dataset = em.createDataSet(LegacySupport.DATASET1, Method.GSEA, files);
//create a DatasetTask
//set up task
GMTFileReaderTask task = new GMTFileReaderTask(dataset);
task.run(taskMonitor);
dataset.setGeneSetsOfInterest(dataset.getSetOfGeneSets());
//create dummy expression
CreateDummyExpressionTask dummyExpressionTask = new CreateDummyExpressionTask(dataset);
dummyExpressionTask.run(taskMonitor);
em.filterGenesets();
InitializeGenesetsOfInterestTask genesets_init = new InitializeGenesetsOfInterestTask(em);
genesets_init.run(taskMonitor);
Baton<Map<SimilarityKey, GenesetSimilarity>> baton = new Baton<>();
ComputeSimilarityTaskParallel similarities = new ComputeSimilarityTaskParallel(em, baton.consumer());
similarities.run(taskMonitor);
//check to see if the dataset loaded - there should be 36 genesets
assertEquals(36, dataset.getSetOfGeneSets().getGeneSets().size());
//there should be (36 * 35)/2 edges (geneset similarities)
assertEquals(18, baton.supplier().get().size());
//there should be 523 genes
assertEquals(523, em.getNumberOfGenes());
assertEquals(523, dataset.getExpressionSets().getNumGenes());
assertEquals(523, dataset.getDataSetGenes().size());
assertEquals(3, dataset.getExpressionSets().getNumConditions());
}
use of org.baderlab.csplugins.enrichmentmap.util.Baton in project EnrichmentMapApp by BaderLab.
the class LoadBingoResultsTest method testLoadBingoResult_withoutexpression.
@Test
public void testLoadBingoResult_withoutexpression() throws Exception {
//for a dataset we require genesets, an expression file (optional), enrichment results
String testBingoResultsFileName = "src/test/resources/org/baderlab/csplugins/enrichmentmap/task/bingo_output/12Hr_topgenes.bgo";
DataSetFiles files = new DataSetFiles();
files.setEnrichmentFileName1(testBingoResultsFileName);
//set the method to Bingo
double pvalue = 0.00005;
// 5.0 X 10-8
double qvaule = 0.00000005;
double similarityCutoff = 0.25;
EMCreationParameters params = new EMCreationParameters("EM1_", pvalue, qvaule, NESFilter.ALL, Optional.empty(), SimilarityMetric.JACCARD, similarityCutoff, 0.5);
//create an new enrichment Map
EnrichmentMap em = new EnrichmentMap(params, serviceRegistrar);
EMDataSet dataset = em.createDataSet(LegacySupport.DATASET1, Method.Specialized, files);
ParseBingoEnrichmentResults enrichmentResultsFilesTask = new ParseBingoEnrichmentResults(dataset);
enrichmentResultsFilesTask.run(taskMonitor);
CreateDummyExpressionTask dummyExpressionTask = new CreateDummyExpressionTask(dataset);
dummyExpressionTask.run(taskMonitor);
em.filterGenesets();
InitializeGenesetsOfInterestTask genesets_init = new InitializeGenesetsOfInterestTask(em);
genesets_init.run(taskMonitor);
Baton<Map<SimilarityKey, GenesetSimilarity>> baton = new Baton<>();
ComputeSimilarityTaskParallel similarities = new ComputeSimilarityTaskParallel(em, baton.consumer());
similarities.run(taskMonitor);
//check to see if the dataset loaded - there should be 74 genesets
assertEquals(74, dataset.getSetOfGeneSets().getGeneSets().size());
//there should also be 74 enrichments (the genesets are built from the bgo file)
assertEquals(74, dataset.getEnrichments().getEnrichments().size());
//there should be 11 genesets in the enrichments of interest
assertEquals(5, dataset.getGeneSetsOfInterest().getGeneSets().size());
//there should be 6 edges
assertEquals(6, baton.supplier().get().size());
//there should be a total of 366 genes
assertEquals(446, em.getNumberOfGenes());
//there should be 43 genes in the geneset "nucleolus"
assertEquals(43, em.getAllGeneSets().get("NUCLEOLUS").getGenes().size());
//make sure the dummy expression has values for all the genes
assertEquals(446, dataset.getExpressionSets().getNumGenes());
assertEquals(446, dataset.getDataSetGenes().size());
}
Aggregations