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