use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class ClusteringManager method runClustering.
/**
* Runs the clustering with the given configurations in the config class: {@link TaskConfig}.
* Clusters each {@link ConnectedComponent} separately and waits until all are done.
* Differes between the modes clustering and general training. Creates a Config file if
* the training mode is used.
* @throws InvalidInputFileException If the file/directory given produces an error.
* @throws InvalidTypeException An incorrect method implementation was given, or some
* other error occured with this.
*/
public void runClustering() throws InvalidInputFileException, InvalidTypeException {
/* initialise ClusterFile if in clustering mode */
ClusterFile clusterFile = null;
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
log.fine("Running clustering in clustering mode!");
clusterFile = new ClusterFile();
clusterFile.instantiateFile(TaskConfig.clustersPath);
clusterFile.printPreProcessingClusters(TaskConfig.transitiveConnectedComponents);
/* check whether connectedComponents has been initialised */
if (this.connectedComponents == null) {
if (TaskConfig.transitiveConnectedComponents == null) {
log.warning("Incorrect use of the ClusteringManager, the connected components list" + "hadn't been initialised. Called method to initialise this and the parameters from " + "the config. Or only a TCC file was given and no connected components.");
this.initParametersAndCCs();
} else {
log.info("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
InfoFile.appendToProjectDetails("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
}
}
}
if (this.connectedComponents != null) {
/* go through cc list and start training for each and control thread use */
ArrayList<Semaphore> allSemaphores = new ArrayList<Semaphore>();
Semaphore maxThreadSemaphore = new Semaphore(TaskConfig.maxNoThreads, true);
for (int i = 0; i < this.connectedComponents.size(); i++) {
Semaphore semaphore = new Semaphore(1);
allSemaphores.add(semaphore);
long time = System.currentTimeMillis();
CostMatrixReader cmReader = new CostMatrixReader(this.connectedComponents.get(i));
ConnectedComponent cc = cmReader.getConnectedComponent();
runClusteringForOneConnectedComponent(cc, clusterFile, semaphore, maxThreadSemaphore, time);
}
/* wait for all clustering tasks to finish */
for (Semaphore s : allSemaphores) {
try {
s.acquire();
} catch (InterruptedException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
}
}
if (clusterFile != null)
clusterFile.closeFile();
/* END OF CLUSTERING */
log.info("Clustering scores sum: " + totalScoreSum);
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
InfoFile.appendLnProjectResults("Total sum of clustering scores for given input: " + TaskUtility.round(totalScoreSum, 2));
}
/* set score to IParameters objects for general training mode */
if (TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
log.fine("Setting parameters score for training mode!");
for (IParameters parameter : this.layouterParameters) {
parameter.setScore(totalScoreSum);
}
}
totalScoreSum = 0;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class ResultPanelPCA method initComponents.
private void initComponents() {
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setAutoCreateRowSorter(true);
table.setDefaultRenderer(StringBuffer.class, new ResultsPanel.JTextAreaRenderer(defaultRowHeight));
// gives a little vertical room between clusters
table.setIntercellSpacing(new Dimension(0, 4));
// removes an outline that appears when the user clicks on the images
table.setFocusable(false);
// Ask to be notified of selection changes.
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(this);
JScrollPane tableScrollPane = new JScrollPane(table);
// System.out.println("CBP: after creating JScrollPane");
tableScrollPane.getViewport().setBackground(Color.WHITE);
add(tableScrollPane, BorderLayout.CENTER);
// System.out.println("CBP: after adding JScrollPane");
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class ResultsPanelTask method getClusters.
public List<NodeCluster> getClusters() {
List<NodeCluster> clusters = new ArrayList<NodeCluster>();
// List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
/*
System.out.println(network.NAME);
System.out.println(CyNetwork.LOCAL_ATTRS);
System.out.println(ClusterManager.CLUSTER_ATTRIBUTE);
*/
clusterAttribute = network.getRow(network, CyNetwork.LOCAL_ATTRS).get(ClusterManager.CLUSTER_ATTRIBUTE, String.class);
// Create a temporary cluster map
Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<Integer, ArrayList<CyNode>>();
for (CyNode node : (List<CyNode>) network.getNodeList()) {
// For each node -- see if it's in a cluster. If so, add it to our map
if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
if (!clusterMap.containsKey(cluster))
clusterMap.put(cluster, new ArrayList<CyNode>());
clusterMap.get(cluster).add(node);
}
}
// See if this algorithm provided it's own scores
List<Double> scores = null;
if (network.getDefaultNetworkTable().getColumn(clusterAttribute + "_Scores") != null) {
scores = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(clusterAttribute + "_Scores", Double.class);
}
for (int clustNum : clusterMap.keySet()) {
NodeCluster cluster = new NodeCluster(clusterMap.get(clustNum));
cluster.setClusterNumber(clustNum);
if (scores != null)
cluster.setClusterScore(scores.get(clustNum - 1));
clusters.add(cluster);
}
// calculating the scores for each cluster
clusterResults = new AbstractClusterResults(network, clusters);
List<Double> modularityList;
if (scores == null) {
modularityList = clusterResults.getModularityList();
} else {
modularityList = scores;
}
for (int i = 0; i < clusters.size(); i++) {
clusters.get(i).setClusterScore(modularityList.get(i));
}
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class ClusterUtils method fetchClusters.
public static List<NodeCluster> fetchClusters(CyNetwork network) {
List<NodeCluster> clusters = new ArrayList<>();
String clusterAttribute = getClusterAttribute(network);
Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<>();
for (CyNode node : network.getNodeList()) {
if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
if (!clusterMap.containsKey(cluster)) {
clusterMap.put(cluster, new ArrayList<>());
}
clusterMap.get(cluster).add(node);
}
}
for (int clusterNum : clusterMap.keySet()) {
NodeCluster cluster = new NodeCluster(clusterMap.get(clusterNum));
cluster.setClusterNumber(clusterNum);
clusters.add(cluster);
}
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class ClusterUtils method setNodeScoresInCluster.
public static List<NodeCluster> setNodeScoresInCluster(CyNetwork network, List<NodeCluster> clusters, List<String> nodeAttributes, String clusterColumnName, boolean multiplicative) {
List<CyNode> nodes = network.getNodeList();
CyTable table = network.getDefaultNodeTable();
for (String nodeAttr : nodeAttributes) {
for (CyNode node : nodes) {
CyRow row = table.getRow(node.getSUID());
int nodeClusterNumber = row.get(clusterColumnName, Integer.class, -1);
for (NodeCluster cluster : clusters) {
if (cluster.getClusterNumber() == nodeClusterNumber) {
if (multiplicative) {
setRankScoreMultiplicative(nodeAttr, row, cluster);
} else {
setRankScore(nodeAttr, row, cluster);
}
}
}
}
}
return clusters;
}
Aggregations