Search in sources :

Example 76 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-api by cytoscape.

the class SetCurrentNetworkEventTest method testNullGetNetwork.

@Test
public void testNullGetNetwork() {
    CyApplicationManager source = mock(CyApplicationManager.class);
    SetCurrentNetworkEvent e = new SetCurrentNetworkEvent(source, null);
    assertNull(e.getNetwork());
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) SetCurrentNetworkEvent(org.cytoscape.application.events.SetCurrentNetworkEvent) Test(org.junit.Test)

Example 77 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-api by cytoscape.

the class SetCurrentNetworkEventTest method testGoodGetNetwork.

@Test
public void testGoodGetNetwork() {
    CyApplicationManager source = mock(CyApplicationManager.class);
    CyNetwork n = mock(CyNetwork.class);
    SetCurrentNetworkEvent e = new SetCurrentNetworkEvent(source, n);
    assertNotNull(e.getNetwork());
    assertEquals(n, e.getNetwork());
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetwork(org.cytoscape.model.CyNetwork) SetCurrentNetworkEvent(org.cytoscape.application.events.SetCurrentNetworkEvent) Test(org.junit.Test)

Example 78 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-api by cytoscape.

the class SetCurrentNetworkViewEventTest method testNullGetNetworkView.

@Test
public void testNullGetNetworkView() {
    CyApplicationManager source = mock(CyApplicationManager.class);
    SetCurrentNetworkViewEvent e = new SetCurrentNetworkViewEvent(source, null);
    assertNull(e.getNetworkView());
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) SetCurrentNetworkViewEvent(org.cytoscape.application.events.SetCurrentNetworkViewEvent) Test(org.junit.Test)

Example 79 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project PhenomeScape by soulj.

the class PhenomeExpress method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setTitle("Running PhenomeExpress");
    taskMonitor.setStatusMessage("Preparing Networks");
    long time = System.currentTimeMillis();
    inputCheck();
    setUpNetworks();
    double[] relativeWeighting = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
    double[] alphas = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
    double[] piValues = proteinNetwork.getPivalues();
    Map<String, Integer> phenotypeMap = phenomeNetwork.getName2IndexMap();
    double[] phenoArray = new double[phenomeNetwork.getName2IndexMap().size()];
    selectedPhenotypes = new ArrayList<Phenotype>();
    boolean first = true;
    for (Phenotype phenotype : phenotypes) {
        if (phenotype.getSelected()) {
            if (first) {
                phenotypeSelected = phenotype.getID();
                phenotypeNamesSelected = phenotype.getName();
                selectedPhenotypes.add(phenotype);
                phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
                first = false;
            } else {
                phenotypeSelected = phenotypeSelected + " ," + phenotype.getID();
                phenotypeNamesSelected = phenotypeNamesSelected + " ," + phenotype.getName();
                phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
                selectedPhenotypes.add(phenotype);
            }
        }
    }
    Map<CyNode, Integer> map = proteinNetwork.getNode2IndexMap();
    int size = proteinNetwork.getNetwork().getNodeCount();
    int[] occuranceArray = new int[size];
    HashMap<CyNode, Protein> node2Protein = new HashMap<CyNode, Protein>();
    if (cancelled) {
        return;
    }
    taskMonitor.setStatusMessage("Calculating Activity Scores");
    taskMonitor.setProgress(0.0);
    double progress = 0.0;
    SparseRowMatrix adjMatrix = SparseRowMatrix.create(size, size);
    double[] transitionProbs = { 0.5, 0.6, 0.7, 0.8 };
    for (double transitionProb : transitionProbs) {
        TransitionMatrix transitionMatrix = new TransitionMatrix(phenomeNetwork.normalise(transitionProb, phenoGeneNetwork), proteinNetwork.normalise(transitionProb, phenoGeneNetwork), phenoGeneNetwork.normaliseT(transitionProb), phenoGeneNetwork.normalise(transitionProb));
        for (double weighting : relativeWeighting) {
            if (cancelled) {
                return;
            }
            transitionMatrix.prepareVector(piValues, phenoArray, weighting);
            for (double alpha : alphas) {
                progress += 0.0051;
                taskMonitor.setProgress(progress);
                double[] pageRankResults = transitionMatrix.pageRank(alpha);
                HashMap<Integer, Protein> index2ProteinMap = proteinNetwork.getIndex2ProteinMap();
                for (int i = 0; i < index2ProteinMap.size(); i++) {
                    Protein protein = index2ProteinMap.get(i);
                    protein.setValue(pageRankResults[i]);
                }
                List<Protein> proteinList = new ArrayList<Protein>(index2ProteinMap.values());
                Collections.sort(proteinList, new DescendingScoreComparator());
                int rank = 0;
                for (Protein protein : proteinList) {
                    rank++;
                    protein.setRank(rank);
                    node2Protein.put(protein.getNode(), protein);
                }
                Collections.sort(proteinList, new DescendingScoreComparator());
                GIGA giga = new GIGA(proteinList, node2Protein, proteinNetwork, maxNetworkSize);
                giga.compute();
                for (GIGACluster cluster : giga.getClusters()) {
                    for (CyNode node : cluster.getCluster()) {
                        Integer index = map.get(node);
                        AVector row = adjMatrix.getRow(index);
                        if (!row.isMutable()) {
                            row = row.mutable();
                        }
                        for (CyNode node2 : cluster.getCluster()) {
                            Integer index2 = map.get(node2);
                            row.set(index2, row.get(index2) + 1.0);
                            occuranceArray[index2]++;
                        }
                        adjMatrix.replaceRow(index, row);
                    }
                }
            }
        }
    }
    if (cancelled) {
        return;
    }
    taskMonitor.setProgress(1.0);
    taskMonitor.setStatusMessage("Creating Consensus Subnetworks");
    AMatrix cooccuranceMat = adjMatrix.transposeInnerProduct(adjMatrix);
    for (int i = 0; i < size; i++) {
        AVector row = cooccuranceMat.getRow(i);
        if (row.elementSum() > 0) {
            row.divide(occuranceArray[i]);
            Index nonSparse = row.nonSparseIndex();
            for (int j = 0; j < nonSparse.length(); j++) {
                if (row.get(nonSparse.get(j)) < 1.0) {
                    row.set(nonSparse.get(j), 0.0);
                }
            }
            cooccuranceMat.replaceRow(i, row.sparse());
        }
    }
    ConnectedComponentAnalyser CCA = new ConnectedComponentAnalyser(node2Protein);
    ArrayList<PhenomeExpressSubnetwork> subnetworks = CCA.ccFromAdjMatrix(adjMatrix, proteinNetwork);
    Iterator<PhenomeExpressSubnetwork> it = subnetworks.iterator();
    while (it.hasNext()) {
        PhenomeExpressSubnetwork subnetwork = it.next();
        if (subnetwork.getNodeList().size() < this.minNetSize) {
            it.remove();
        }
    }
    if (cancelled) {
        return;
    }
    taskMonitor.setStatusMessage("Calculating Subnetwork Significance");
    subnetworksSignificance(subnetworks);
    taskMonitor.setStatusMessage("Visualising Subnetworks");
    List<Double> foldChangeValues = proteinNetwork.getNodeTable().getColumn(foldChange).getValues(Double.class);
    double fcMax = Collections.max(foldChangeValues);
    double fcMin = Collections.min(foldChangeValues);
    // Apply the visual style to a NetworkView
    VizStyle vizStyle = new VizStyle();
    VisualStyle vs = vizStyle.createVizStyle(cyServiceRegistrar, geneName, foldChange, fcMax, fcMin);
    this.property = getNodeLabelPositionProperty();
    vs.setDefaultValue(property, property.parseSerializableString("N,S,c,0.0,0.0"));
    VisualMappingManager visualMappingManager = cyServiceRegistrar.getService(VisualMappingManager.class);
    visualMappingManager.setCurrentVisualStyle(vs);
    ArrayList<CyNetworkView> networkViewList = new ArrayList<CyNetworkView>();
    Iterator<PhenomeExpressSubnetwork> it2 = subnetworks.iterator();
    CyNetworkManager networkManager = cyServiceRegistrar.getService(CyNetworkManager.class);
    CyNetworkViewFactory networkViewFactory = cyServiceRegistrar.getService(CyNetworkViewFactory.class);
    CyLayoutAlgorithmManager layoutManager = cyServiceRegistrar.getService(CyLayoutAlgorithmManager.class);
    CyApplicationManager cyApplicationManager = cyServiceRegistrar.getService(CyApplicationManager.class);
    CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");
    Map<String, Object> settings = new HashMap<String, Object>();
    settings.put("defaultSpringLength", 5.0);
    settings.put("defaultSpringNodeMass", 2.0);
    TunableSetter setter = cyServiceRegistrar.getService(TunableSetter.class);
    Object context = layout.createLayoutContext();
    setter.applyTunables(context, settings);
    GOTermAnalyser2 goTermAnalyser = new GOTermAnalyser2(proteinNetwork, species);
    while (it2.hasNext()) {
        PhenomeExpressSubnetwork subnet = it2.next();
        if (subnet.getPvalue() > this.threshold) {
            it2.remove();
        } else {
            goTermAnalyser.calculateGOTermPValues(subnet, proteinNetwork);
            String subnetworkName = NetworkUtils.getUniqueNetworkName(cyServiceRegistrar, networkName + "_" + subnet.getBestGOTerm());
            subnet.setName(subnetworkName);
            CySubNetwork subnetwork = NetworkUtils.createSubNetwork(((CySubNetwork) proteinNetwork.getNetwork()).getRootNetwork(), subnet.getNodeList());
            subnetwork.getRow(subnetwork).set(CyNetwork.NAME, subnetworkName);
            addSeedPhenotypes(subnetwork);
            networkManager.addNetwork(subnetwork);
            CyNetworkViewManager viewManager = cyServiceRegistrar.getService(CyNetworkViewManager.class);
            CyNetworkView nv = networkViewFactory.createNetworkView(subnetwork);
            viewManager.addNetworkView(nv);
            cyApplicationManager.setCurrentNetworkView(nv);
            for (CyNode phenoNode : phenotypesAdded) {
                View<CyNode> nodeView = nv.getNodeView(phenoNode);
                nodeView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
                nodeView.setLockedValue(BasicVisualLexicon.NODE_FILL_COLOR, Color.BLUE);
            }
            for (CyEdge phenoEdge : phenoEdges) {
                View<CyEdge> edgeView = nv.getEdgeView(phenoEdge);
                edgeView.setLockedValue(BasicVisualLexicon.EDGE_LINE_TYPE, LineTypeVisualProperty.DOT);
                edgeView.setLockedValue(BasicVisualLexicon.EDGE_PAINT, Color.BLUE);
            }
            networkViewList.add(nv);
            Set<View<CyNode>> nodeSet = Collections.emptySet();
            cyServiceRegistrar.getService(TaskManager.class).execute(layout.createTaskIterator(nv, context, nodeSet, null));
        }
    }
    CyEventHelper cyEventHelper = cyServiceRegistrar.getService(CyEventHelper.class);
    for (CyNetworkView nv : networkViewList) {
        visualMappingManager.setVisualStyle(vs, nv);
        vs.apply(nv);
        cyEventHelper.flushPayloadEvents();
        cyApplicationManager.setCurrentNetworkView(nv);
        nv.updateView();
    }
    phenomeNetwork = null;
    proteinNetwork = null;
    ResultsPanel resultsPanel = (ResultsPanel) CytoPanelUtils.getCytoPanel(cyServiceRegistrar, ResultsPanel.class, CytoPanelName.EAST);
    resultsPanel.newTableData(getResultsSummary(subnetworks), getParameterList());
    CytoPanelUtils.showCytoPanel(cyServiceRegistrar, CytoPanelName.EAST);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) HashMap(java.util.HashMap) AMatrix(mikera.matrixx.AMatrix) ArrayList(java.util.ArrayList) Index(mikera.indexz.Index) TunableSetter(org.cytoscape.work.TunableSetter) AVector(mikera.vectorz.AVector) CyNode(org.cytoscape.model.CyNode) GOTermAnalyser2(org.cytoscape.phenomescape.internal.util.GOTermAnalyser2) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyApplicationManager(org.cytoscape.application.CyApplicationManager) Phenotype(org.cytoscape.phenomescape.internal.util.Phenotype) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) ConnectedComponentAnalyser(org.cytoscape.phenomescape.internal.util.ConnectedComponentAnalyser) DescendingScoreComparator(org.cytoscape.phenomescape.internal.Protein.DescendingScoreComparator) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VizStyle(org.cytoscape.phenomescape.internal.util.VizStyle) CyEdge(org.cytoscape.model.CyEdge) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) SparseRowMatrix(mikera.matrixx.impl.SparseRowMatrix) TaskManager(org.cytoscape.work.TaskManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 80 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project PhenomeScape by soulj.

the class CyActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    CyServiceRegistrar cyServiceRegistrar = getService(context, CyServiceRegistrar.class);
    CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class);
    LoadHumanNetworkMenuAction loadHumanNetworkMenuAction = new LoadHumanNetworkMenuAction(cyApplicationManager, cyServiceRegistrar);
    LoadMouseNetworkMenuAction loadMouseNetworkMenuAction = new LoadMouseNetworkMenuAction(cyApplicationManager, cyServiceRegistrar);
    TableManager myTableManager = new TableManager(cyServiceRegistrar);
    Properties properties = new Properties();
    registerAllServices(context, loadHumanNetworkMenuAction, properties);
    registerAllServices(context, loadMouseNetworkMenuAction, properties);
    CyTableManager cyTableManager = getService(context, CyTableManager.class);
    ControlPanel myControlPanel = new ControlPanel(cyServiceRegistrar, cyTableManager);
    registerService(context, myControlPanel, CytoPanelComponent.class, properties);
    ResultsPanel myResultsPanel = new ResultsPanel(cyServiceRegistrar);
    registerService(context, myResultsPanel, CytoPanelComponent.class, properties);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTableManager(org.cytoscape.model.CyTableManager) LoadMouseNetworkMenuAction(org.cytoscape.phenomescape.internal.listeners.LoadMouseNetworkMenuAction) TableManager(org.cytoscape.phenomescape.internal.util.TableManager) CyTableManager(org.cytoscape.model.CyTableManager) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) LoadHumanNetworkMenuAction(org.cytoscape.phenomescape.internal.listeners.LoadHumanNetworkMenuAction)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7