Package org.cytoscape.ClusterViz.internal

Examples of org.cytoscape.ClusterViz.internal.Cluster


        List clusters = panel.getClusters();
        registrar.unregisterService(panel, CytoPanelComponent.class);
        mcodeUtil.removeNetworkResult(resultId);
        if (clusters != null)
        {
          Cluster c;
          for (Iterator iterator = clusters.iterator(); iterator.hasNext(); c.dispose())
            c = (Cluster)iterator.next();

        }
      }
    }
View Full Code Here


         
          int degree = inputNetwork.getAdjacentEdgeList(n, CyEdge.Type.ANY).size();

          //int degree=super.getNodeDegree(inputNetwork,n.getSUID());
        //int degree=inputNetwork.getDegree(n);
        Cluster newCluster = new Cluster(i);
        ArrayList alNodes=new ArrayList();
        alNodes.add(n.getSUID());
       
        newCluster.setAlCluster(alNodes);
//        newCluster.setALNodes(alNodes);
        newCluster.setTotalDegree(degree);
        Long nodeIndex= n.getSUID();
        ((NodeInfo)curNodeInfos.get(nodeIndex)).setComplex(i);
        i++;
        alOriginalClusters.add(newCluster);
        }
        /**********************************************************************************************
      Then, Operation UNION:  according to different situation, in which the two nodes consisting
        this arc may belong to different Complexes or an identical Complex and that the
        attributes of the Complexes varies, we take on different action
         ***********************************************************************************************/
        ArrayList alEdgeWithSameWeight; 
        CyEdge curEdge;                                                                                                                         
        for (Iterator iterator = values.iterator(); iterator.hasNext();) {
            //each weight may be associated with multiple edges, iterate over these lists
          alEdgeWithSameWeight = (ArrayList) iterator.next();
            for (int j = 0; j < alEdgeWithSameWeight.size(); j++) {//for each edge
                Long edgeIndex = ((Long) alEdgeWithSameWeight.get(j)).longValue();
                curEdge=inputNetwork.getEdge(edgeIndex);               
            Long inFrom = curEdge.getSource().getSUID();
            Long inTo   = curEdge.getTarget().getSUID();
            NodeInfo fromNI=(NodeInfo)curNodeInfos.get(inFrom)//source node info
            NodeInfo toNI=(NodeInfo)curNodeInfos.get(inTo)//target node info
           
            int icFrom=fromNI.iComplex;  //complex that the source node belongs to
            int icTo=toNI.iComplex;    //complex that the target node belongs to
            if(icFrom != icTo)    //we have take some actions only if the two complexes are not the same
            {
              Cluster cFrom=(Cluster)alOriginalClusters.get(icFrom);
              Cluster cTo=(Cluster)alOriginalClusters.get(icTo);
              if(cFrom.isMergeable() && cTo.isMergeable())  //the two complexes are both mergeable
                if(!cFrom.isModule() || !cTo.isModule())  //either of the two complexes are not modules yet
                  //if(cFrom.getALNodes().size() >= cTo.getALNodes().size()){//merge the smaller complexe to the larger one
                  if(cFrom.getALCluster().size() >= cTo.getALCluster().size()){//merge the smaller complexe to the larger one
                    if(params.isWeak()) mergeComplexes1(cFrom, cTo);
                    else  mergeComplexes2(cFrom, cTo);  
                  }
                  else//merge the smaller complex to the larger one
                    if(params.isWeak())  mergeComplexes1(cTo, cFrom);
                    else  mergeComplexes2(cFrom, cTo);
                  }
                else  //both of the two complexes are modules
                {
                  cFrom.setMergeable(false);
                  cTo.setMergeable(false);
                }
              else  //either of the two complexes is not mergeable
              {
                cFrom.setMergeable(false);
              cTo.setMergeable(false);
              }
            }
                if (taskMonitor != null) {
                    findingProgress++;
                    //We want to be sure that only progress changes are reported and not
                    //miniscule decimal increments so that the taskMonitor isn't overwhelmed
                    int newProgress = (findingProgress * 100) / findingTotal;
                    int oldProgress = ((findingProgress-1) * 100) / findingTotal;
                    if (newProgress != oldProgress) {
                        taskMonitor.setProgress(newProgress);
                    }
                }
                if (cancelled) {
                    break;
                }
            }
        }
        ArrayList alClusters = new ArrayList();
        Iterator it=alOriginalClusters.iterator();
        while(it.hasNext()){
          Cluster cluster=(Cluster)it.next();
//          if(cluster.getALNodes().size()>=params.getComplexSizeThreshold()){

          if(cluster.getALCluster().size()>=params.getComplexSizeThreshold()){
            //
            //ArrayList<Long> alNodes=cluster.getALNodes();
            List<Long> alNodes=cluster.getALCluster();
            ClusterGraph gpCluster = this.createClusterGraph(alNodes, inputNetwork);
            //cluster.setComplexID(counter++);
            cluster.setGraph(gpCluster);
            cluster.setScore(0.0);
            cluster.setSeedNode(alNodes.get(0));
           
//            cluster.setResultTitle(resultTitle);
            cluster.setResultTitle(resultTitle);
            int ind=cluster.getInDegree();
            int outd=cluster.getTotalDegree()-2*ind;
            if(ind!=0 && outd!=0)
              cluster.setModularity((double)ind/(double)outd);
            else
                cluster.calModularity(inputNetwork,this);
            alClusters.add(cluster);
          }
        }
        //Once the clusters have been found we either return them or in the case of selection scope,
        //we select only the ones that contain the selected node(s) and return those
        ArrayList selectedALClusters = new ArrayList();
        if (!params.getScope().equals(ParameterSet.NETWORK)) {
            for (Iterator ic = alClusters.iterator(); ic.hasNext();){
                Cluster cluster = (Cluster) ic.next();
                List<Long> alNodes = cluster.getALCluster();
                ArrayList alSelectedNodes = new ArrayList();
                for (int c = 0; c < params.getSelectedNodes().length; c++) {
                    alSelectedNodes.add(params.getSelectedNodes()[c]);
                }
                //method for returning all clusters that contain any of the selected nodes
View Full Code Here

                fluffClusterBoundary(alCluster, nodeSeenHashMap, nodeInfoHashMap);

              clusterGraph = createClusterGraph(alCluster, inputNetwork);
              final double score = scoreCluster(clusterGraph);
             
              Cluster currentCluster = new Cluster(resultId, currentNode, clusterGraph, score,
                  alCluster, nodeSeenHashMapSnapShot);
             
              alClusters.add(currentCluster);
            }
          }
View Full Code Here

      fluffClusterBoundary(alCluster, nodeSeenHashMap, nodeInfoHashMap);

    clusterGraph = createClusterGraph(alCluster, inputNet);
    final double score = scoreCluster(clusterGraph);
   
    final Cluster newCluster = new Cluster(resultId, seedNode, clusterGraph, score, alCluster,
        nodeSeenHashMap);
    newCluster.setRank(cluster.getRank());
   
    return newCluster;
  }
View Full Code Here

     int d1,d2,c1,c2;
     Long[] neighs;
     int m=currentNetwork.getEdgeCount();
     Iterator i0=alClusters.iterator();
     while(i0.hasNext()){//for each Complex
       Cluster cur=(Cluster)i0.next();
       List<Long> alNodes=cur.getALCluster();
//       Long[] nodes=ClusterUtil.convertIntArrayList2array(alNodes);
       for(i=0;i<alNodes.size()-1;i++){//for each pairs of nodes
//       for(i=0;i<nodes.length-1;i++){//for each pairs of nodes
        //n1=nodes[i];
           n1=alNodes.get(i);
View Full Code Here

  
  protected int searchInComplexes(ArrayList alClusters, Long node){
      int counter=0;
      Iterator it=alClusters.iterator();
      while(it.hasNext()){
        Cluster cur=(Cluster) it.next();
        List alNodes=cur.getALCluster();
        if(alNodes.contains(node))
          counter++;
      }
      return counter;
    }
View Full Code Here

    }
  }
  private void switchPlace(String field){
    int max;
    Image image;
    Cluster cluster;
    for(int i=0;i<clusters.size()-1;i++){
      max=i;
      for(int j=i+1;j<clusters.size();j++){
        if(field.equals("size")){
          if(clusters.get(j).getALCluster().size()>clusters.get(max).getALCluster().size())
View Full Code Here

    public void actionPerformed(ActionEvent evt)
    {
      NumberFormat nf = NumberFormat.getInstance();
      nf.setMaximumFractionDigits(3);
      final Cluster cluster = (Cluster)ResultPanel.this.clusters.get(this.selectedRow);
      final CyNetwork clusterNetwork = cluster.getNetwork();
      final String title = this.trigger.getResultId() + ": " + cluster.getName() + " (Score: " +
        nf.format(cluster.getScore()) + ")";

      SwingWorker worker = new SwingWorker()
      {
        protected CyNetworkView doInBackground() throws Exception
        {
          CySubNetwork newNetwork = ResultPanel.this.mcodeUtil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList(),
            SavePolicy.SESSION_FILE);
          newNetwork.getRow(newNetwork).set("name", title);

          VisualStyle vs = ResultPanel.this.mcodeUtil.getNetworkViewStyle(ResultPanel.this.networkView);
          CyNetworkView newNetworkView = ResultPanel.this.mcodeUtil.createNetworkView(newNetwork, vs);

          newNetworkView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION, Double.valueOf(0.0D));
          newNetworkView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION, Double.valueOf(0.0D));

          ResultPanel.this.mcodeUtil.displayNetworkView(newNetworkView);

          boolean layoutNecessary = false;
          CyNetworkView clusterView = cluster.getView();

          for (View nv : newNetworkView.getNodeViews()) {
            CyNode node = (CyNode)nv.getModel();
            View cnv = clusterView != null ? clusterView.getNodeView(node) : null;
View Full Code Here

            ArrayList optimals=null;
            for(int i=0;i<curCliques.size();i++){
                Clique cur=(Clique)curCliques.get(new Integer(i));
                ArrayList nodes=cur.getCliqueNodes();
                if(nodes.size() >= params.getCliqueSizeThreshold1()){
                    Cluster newCluster=new Cluster();
                  ArrayList alNodes=new ArrayList();
                  Iterator it=nodes.iterator();
                  while(it.hasNext()){
                    Long n=(Long)it.next();
                    alNodes.add(n);
                  }
                  newCluster.setAlCluster(alNodes);
                  alClusters.add(newCluster);  
                }
                else  cur.setSubordinate(true);
            }
            for(int i=0;i<curCliques.size();i++){
              Clique cur=(Clique)curCliques.get(new Integer(i));
              if(cur.isSubordinate()){
                ArrayList nodes=cur.getCliqueNodes();
                Iterator it=nodes.iterator();
                while(it.hasNext()){
                    Long n=(Long) it.next();
                   
                   
                    if(searchInComplexes(alClusters,new Long(n))==0){  //a subordinate node
                      Cluster newCluster=new Cluster();
                      ArrayList alNodes=new ArrayList();
                      alNodes.add(n);
                      newCluster.setAlCluster(alNodes);
                      alClusters.add(newCluster);
                    }
                }
              }
            }/******End of initialization*******/
            int findingProgress = 0;
            int findingTotal = alClusters.size();
            double max=0,cur;int num=0;
            //merge two complexes with largest similarity each time until there is only on left
            do{
              mergeComplex(alClusters);
              cur=calModularity(alClusters);
            if(max==0 || cur>max){
              max=cur;
              ArrayList temp=new ArrayList();
                for(Iterator i=alClusters.iterator();i.hasNext();){
                  Cluster c=(Cluster)i.next();
                  Cluster newC=new Cluster();
                  List<Long> al=c.getALCluster();
                  ArrayList newAl=new ArrayList();
                    for(Iterator i1=al.iterator();i1.hasNext();)
                      newAl.add((Long)i1.next());
                    newC.setAlCluster(newAl);
                    temp.add(newC);
                }
              optimals=temp;
              //optimal=new ArrayList((ArrayList)alClusters.clone());
            }
                if (taskMonitor != null) {
                    findingProgress++;
                    int newProgress = (findingProgress * 100) / findingTotal;
                    int oldProgress = ((findingProgress-1) * 100) / findingTotal;
                    if (newProgress != oldProgress) {
                        taskMonitor.setProgress(newProgress);
                    }
                }
                if (cancelled) {
                    break;
                }
            }while(alClusters.size()>1);
            curOptimalDivision=optimals;
            optimalDivisionKeyMap.put(key, optimals);
        }
       
        ArrayList alClusters=new ArrayList();
        Iterator it=curOptimalDivision.iterator();
        while(it.hasNext()){
          Cluster cluster=(Cluster)it.next();
          if(cluster.getALCluster().size()>=params.getComplexSizeThreshold1()){
            List<Long> alNodes=cluster.getALCluster();
            ClusterGraph gpCluster =createClusterGraph(alNodes, inputNetwork);
            cluster.setGraph(gpCluster);
            cluster.setScore(0.0);
            cluster.setSeedNode((Long)alNodes.get(0));
            cluster.setResultTitle(resultTitle);
            cluster.calModularity(inputNetwork,this);
            alClusters.add(cluster);
          }
        }
       
        //Once the clusters have been found we either return them or in the case of selection scope,
        //we select only the ones that contain the selected node(s) and return those
        ArrayList selectedALClusters = new ArrayList();
        if (!params.getScope().equals(ParameterSet.NETWORK)) {
            for (Iterator ic = alClusters.iterator(); ic.hasNext();){
                Cluster cluster = (Cluster) ic.next();
                List<Long> alNodes = cluster.getALCluster();
                ArrayList alSelectedNodes = new ArrayList();
                for (int c = 0; c < params.getSelectedNodes().length; c++) {
                    alSelectedNodes.add(params.getSelectedNodes()[c]);
                }
                //method for returning all clusters that contain any of the selected nodes
View Full Code Here

        fout.write("Cluster  Score (Density*#Nodes)\tNodes\tEdges\tNode IDs" + lineSep);

        // Get sub-networks for all clusters, score and rank them
        // convert the ArrayList to an array of CyNetworks and sort it by cluster score
        for (int i = 0; i < clusters.size(); i++) {
          final Cluster c = clusters.get(i);
          final CyNetwork clusterNetwork = c.getNetwork();
          fout.write((i + 1) + "\t"); //rank
          NumberFormat nf = NumberFormat.getInstance();
          nf.setMaximumFractionDigits(3);
          fout.write(nf.format(c.getScore()) + "\t");
          // cluster size - format: (# prot, # intx)
          fout.write(clusterNetwork.getNodeCount() + "\t");
          fout.write(clusterNetwork.getEdgeCount() + "\t");
          // create a string of node names - this can be long
          fout.write(getNodeNameList(clusterNetwork) + lineSep);
View Full Code Here

TOP

Related Classes of org.cytoscape.ClusterViz.internal.Cluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.