Search in sources :

Example 51 with EnrichmentMap

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

the class PAKnownSignatureCommandTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    if (gmtFile == null || !gmtFile.canRead())
        throw new IllegalArgumentException("Signature GMT file name not valid");
    CyNetwork selectedNetwork;
    CyNetworkView selectedView;
    if (network == null) {
        selectedNetwork = applicationManager.getCurrentNetwork();
        selectedView = applicationManager.getCurrentNetworkView();
        if (selectedNetwork == null || selectedView == null) {
            throw new IllegalArgumentException("Current network not available.");
        }
    } else {
        selectedNetwork = network;
        Collection<CyNetworkView> networkViews = networkViewManager.getNetworkViews(network);
        if (networkViews == null || networkViews.isEmpty()) {
            throw new IllegalArgumentException("No network view for: " + network);
        }
        selectedView = networkViews.iterator().next();
    }
    EnrichmentMap map = emManager.getEnrichmentMap(selectedNetwork.getSUID());
    if (map == null)
        throw new IllegalArgumentException("Network is not an Enrichment Map.");
    loadGeneSets(map);
    PostAnalysisFilterType filter = PostAnalysisFilterType.valueOf(filterType.getSelectedValue());
    UniverseType universe = UniverseType.valueOf(hypergeomUniverseType.getSelectedValue());
    PostAnalysisParameters.Builder builder = new PostAnalysisParameters.Builder();
    builder.setAttributePrefix(map.getParams().getAttributePrefix());
    builder.setSignatureGMTFileName(gmtFile.getAbsolutePath());
    builder.setLoadedGMTGeneSets(signatureGenesets);
    builder.addSelectedGeneSetNames(selectedGenesetNames);
    builder.setUniverseType(universe);
    builder.setUserDefinedUniverseSize(userDefinedUniverseSize);
    builder.setRankTestParameters(new PostAnalysisFilterParameters(filter, cutoff));
    builder.setName(name);
    if (isBatch()) {
        // run in batch mode
        builder.setDataSetName(null);
    } else {
        if (map.getDataSet(dataSetName) == null) {
            throw new IllegalArgumentException("Data set name not valid: '" + dataSetName + "'");
        }
        builder.setDataSetName(dataSetName);
    }
    // Mann-Whitney requires ranks
    if (filter.isMannWhitney()) {
        processMannWhitneyArgs(map, builder);
    }
    TaskFactory taskFactory = taskFactoryFactory.create(selectedView, builder.build());
    TaskIterator taskIterator = new TaskIterator();
    taskIterator.append(taskFactory.createTaskIterator());
    Task updatePanelTask = new AbstractTask() {

        @Override
        public void run(TaskMonitor taskMonitor) {
            controlPanelMediatorProvider.get().updateDataSetList(selectedView);
            selectedView.updateView();
        }
    };
    taskIterator.append(updatePanelTask);
    insertTasksAfterCurrentTask(taskIterator);
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) UniverseType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters.UniverseType) AbstractTask(org.cytoscape.work.AbstractTask) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) PostAnalysisParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CreateDiseaseSignatureTaskFactory(org.baderlab.csplugins.enrichmentmap.task.postanalysis.CreateDiseaseSignatureTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 52 with EnrichmentMap

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

the class ModelSerializer method deserialize.

public static EnrichmentMap deserialize(String json) {
    Type immutableIntSetType = new TypeToken<ImmutableSet<Integer>>() {
    }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(BiMap.class, new BiMapAdapter()).registerTypeHierarchyAdapter(Path.class, new PathAdapter()).registerTypeAdapter(EnrichmentResult.class, new EnrichmentResultAdapter()).registerTypeAdapter(immutableIntSetType, new ImmutableIntSetAdapter()).create();
    try {
        EnrichmentMap map = gson.fromJson(json, EnrichmentMap.class);
        for (EMDataSet dataset : map.getDataSetList()) {
            dataset.setParent(map);
        }
        return map;
    } catch (JsonParseException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
Also used : Path(java.nio.file.Path) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) JsonParseException(com.google.gson.JsonParseException) Type(java.lang.reflect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet)

Example 53 with EnrichmentMap

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

the class SessionModelIO method saveModel.

public void saveModel() {
    if (debug)
        System.out.println("SessionModelListener.saveModel()");
    CyTable table = getOrCreatePrivateModelTable();
    clearTable(table);
    int[] id = { 0 };
    Map<Long, EnrichmentMap> maps = emManager.getAllEnrichmentMaps();
    maps.forEach((suid, em) -> {
        CyNetwork network = networkManager.getNetwork(suid);
        if (network != null) {
            // MKTODO big error if its null
            String json = ModelSerializer.serialize(em);
            CyRow row = table.getRow(id[0]);
            COL_NETWORK_ID.set(row, suid);
            COL_EM_JSON.set(row, json);
            id[0]++;
        }
    });
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow)

Example 54 with EnrichmentMap

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

the class SessionModelIO method restoreModelFromTables.

private boolean restoreModelFromTables(CySession session) {
    boolean sessionHasEM = false;
    CyTable table = getPrivateTable();
    if (table != null) {
        for (CyRow row : table.getAllRows()) {
            Long suid = COL_NETWORK_ID.get(row);
            String json = COL_EM_JSON.get(row);
            if (suid != null && json != null) {
                CyNetwork network = networkManager.getNetwork(suid);
                if (network != null) {
                    EnrichmentMap em = ModelSerializer.deserialize(json);
                    if (em != null) {
                        em.setServiceRegistrar(serviceRegistrar);
                        em.setNetworkID(network.getSUID());
                        updateSuids(em, session);
                        emManager.registerEnrichmentMap(em);
                        sessionHasEM = true;
                    }
                }
            }
        }
    }
    return sessionHasEM;
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow)

Example 55 with EnrichmentMap

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

the class LegacySessionLoadTest method test_2_LoadTwoDataSetWithPostAnalysisLegacySession.

@Test
@SessionFile("em_session_2.2_twodataset_pa.cys")
public void test_2_LoadTwoDataSetWithPostAnalysisLegacySession() {
    EnrichmentMap map = getEnrichmentMap();
    assertEquals(2, map.getDataSetCount());
    assertEquals(11445, map.getAllGenes().size());
    CyNetwork network = networkManager.getNetwork(map.getNetworkID());
    Map<String, CyEdge> edges = TestUtils.getEdges(network);
    assertEquals(15, edges.size());
    assertTrue(edges.containsKey("PA_TOP8_MIDDLE8_BOTTOM8 (sig_set1) BOTTOM8_PLUS100"));
    assertTrue(edges.containsKey("PA_TOP8_MIDDLE8_BOTTOM8 (sig_set1) TOP8_PLUS100"));
    assertTrue(edges.containsKey("PA_TOP8_MIDDLE8_BOTTOM8 (sig_set1) MIDDLE8_PLUS100"));
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyEdge(org.cytoscape.model.CyEdge) BaseIntegrationTest(org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest) Test(org.junit.Test) SessionFile(org.baderlab.csplugins.enrichmentmap.integration.SessionFile)

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