Search in sources :

Example 31 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class PostAnalysisCutoffTest method _setup.

@Test
public void _setup(PropertyManager pm, CyApplicationManager applicationManager, CyNetworkManager networkManager) {
    EMCreationParameters params = new EMCreationParameters("EM1_", pm.getDefaultPvalue(), pm.getDefaultQvalue(), NESFilter.ALL, Optional.empty(), SimilarityMetric.JACCARD, pm.getDefaultJaccardCutOff(), pm.getDefaultCombinedConstant());
    DataSetFiles dataset1files = new DataSetFiles();
    dataset1files.setGMTFileName(PATH + "gene_sets.gmt");
    dataset1files.setExpressionFileName(PATH + "FakeExpression.txt");
    dataset1files.setEnrichmentFileName1(PATH + "fakeEnrichments.txt");
    dataset1files.setRankedFile(PATH + "FakeRank.rnk");
    buildEnrichmentMap(params, dataset1files, Method.Generic, LegacySupport.DATASET1);
    // Assert the network is as expected
    Set<CyNetwork> networks = networkManager.getNetworkSet();
    assertEquals(1, networks.size());
    emNetwork = networks.iterator().next();
}
Also used : EMCreationParameters(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters) CyNetwork(org.cytoscape.model.CyNetwork) DataSetFiles(org.baderlab.csplugins.enrichmentmap.model.DataSetFiles) Test(org.junit.Test)

Example 32 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 33 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class LegacySupport method getNextAttributePrefix.

/**
	 * The attribute prefix is based on the number of nextworks in cytoscape.
	 * make attribute prefix independent of cytoscape
	 */
public String getNextAttributePrefix() {
    Set<CyNetwork> networks = networkTableManager.getNetworkSet();
    if (networks == null || networks.isEmpty()) {
        return "EM1_";
    } else {
        // how many enrichment maps are there?
        int max_prefix = 0;
        // if they are then calculate the max EM_# and use the max number + 1 for the current attributes
        for (CyNetwork current_network : networks) {
            Long networkId = current_network.getSUID();
            if (emManager.isEnrichmentMap(networkId)) {
                // fails
                EnrichmentMap tmpMap = emManager.getEnrichmentMap(networkId);
                String tmpPrefix = tmpMap.getParams().getAttributePrefix();
                tmpPrefix = tmpPrefix.replace("EM", "");
                tmpPrefix = tmpPrefix.replace("_", "");
                int tmpNum = Integer.parseInt(tmpPrefix);
                if (tmpNum > max_prefix) {
                    max_prefix = tmpNum;
                }
            }
        }
        return "EM" + (max_prefix + 1) + "_";
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 34 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class EnrichmentMap method getName.

public String getName() {
    final String undefined = "-- UNDEFINED --";
    if (serviceRegistrar == null)
        return undefined;
    CyNetworkManager networkManager = serviceRegistrar.getService(CyNetworkManager.class);
    if (networkManager == null)
        return undefined;
    CyNetwork net = networkManager.getNetwork(networkID);
    if (net == null)
        return undefined;
    return NetworkUtil.getName(net);
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 35 with CyNetwork

use of org.cytoscape.model.CyNetwork 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)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)48 Test (org.junit.Test)20 CyNode (org.cytoscape.model.CyNode)16 CyNetworkView (org.cytoscape.view.model.CyNetworkView)13 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)11 CyEdge (org.cytoscape.model.CyEdge)9 ArrayList (java.util.ArrayList)8 List (java.util.List)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyRow (org.cytoscape.model.CyRow)6 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)5 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)5 CyTable (org.cytoscape.model.CyTable)5 Map (java.util.Map)4 Set (java.util.Set)4 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)4 View (org.cytoscape.view.model.View)4 Inject (com.google.inject.Inject)3 Color (java.awt.Color)3