use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread in project clusterMaker2 by RBVI.
the class RunTransClust method run.
public List<NodeCluster> run(TaskMonitor monitor, CyNetwork network) {
DoubleMatrix2D matrix = this.distanceMatrix.getColtMatrix();
nodes = distanceMatrix.getRowNodes();
HashMap<String, CyNode> nodeHash = new HashMap<String, CyNode>();
for (CyNode node : nodes) {
nodeHash.put(ModelUtils.getNodeName(network, node), node);
}
HashMap<String, Integer> integers2proteins = new HashMap<String, Integer>();
HashMap<Integer, String> proteins2integers = new HashMap<Integer, String>();
int count = 0;
for (CyNode node : this.nodes) {
integers2proteins.put(ModelUtils.getNodeName(network, node), count);
proteins2integers.put(count, ModelUtils.getNodeName(network, node));
count++;
}
Edges es = new Edges(this.nodes.size() * this.nodes.size(), this.nodes.size());
count = 0;
for (int i = 0; i < this.nodes.size(); i++) {
CyNode cyNodeI = this.nodes.get(i);
es.startPositions[integers2proteins.get(cyNodeI.getSUID())] = count;
for (int j = 0; j < this.nodes.size(); j++) {
CyNode cyNodeJ = this.nodes.get(j);
es.sources[count] = i;
es.targets[count] = j;
Double val = distanceMatrix.getValue(i, j);
if (val != null) {
es.values[count] = val.floatValue();
count++;
}
}
es.endPositions[integers2proteins.get(cyNodeI.getSUID())] = count - 1;
}
Semaphore s = new Semaphore(1);
TaskConfig.mode = TaskConfig.COMPARISON_MODE;
TaskConfig.monitor = monitor;
IteratorThread it = new IteratorThread(es, integers2proteins, proteins2integers, s);
TaskConfig.minThreshold = threshold;
TaskConfig.maxThreshold = threshold;
try {
s.acquire();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
it.start();
monitor.showMessage(TaskMonitor.Level.INFO, "Executing TransClust Clustering...");
try {
s.acquire();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
monitor.showMessage(TaskMonitor.Level.INFO, "Assigning nodes to clusters");
String result = it.resultsStringBuffer.toString();
String[] clusters = result.split("\t")[2].split(";");
Map<Integer, NodeCluster> clusterMap = getClusterMap(clusters, nodeHash);
// Update node attributes in network to include clusters. Create cygroups from clustered nodes
monitor.showMessage(TaskMonitor.Level.INFO, "Created " + clusterMap.size() + " clusters");
if (clusterCount == 0) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Created 0 clusters!!!!");
return null;
}
int clusterNumber = 1;
Map<NodeCluster, NodeCluster> cMap = new HashMap();
for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
if (cMap.containsKey(cluster))
continue;
cMap.put(cluster, cluster);
cluster.setClusterNumber(clusterNumber);
clusterNumber++;
}
Set<NodeCluster> clusters2 = cMap.keySet();
return new ArrayList<NodeCluster>(clusters2);
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread in project clusterMaker2 by RBVI.
the class ClusteringManagerTask method run.
public void run() {
try {
TaskConfig.monitor.setStatusMessage("-----------------------------------");
TaskConfig.monitor.setStatusMessage("Running ... " + TaskConfig.NAME + " v" + TaskConfig.VERSION);
Date date = new Date(System.currentTimeMillis());
TaskConfig.monitor.setStatusMessage(date.toString());
TaskConfig.monitor.setStatusMessage("-----------------------------------");
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
long time = System.currentTimeMillis();
this.clusterManager = new ClusteringManager(TaskConfig.cmPath);
try {
this.clusterManager.initParametersAndCCs();
this.clusterManager.runClustering();
// System.out.println(this.clusterManager.getConnectedComponents().size());
time = System.currentTimeMillis() - time;
TaskConfig.monitor.setStatusMessage("Time taken for complete clustering process: " + TaskUtility.convertTime(time));
} catch (InvalidInputFileException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
System.exit(-1);
} catch (InvalidTypeException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
System.exit(-1);
}
} else /* start general training */
if (TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
try {
long time = System.currentTimeMillis();
ClusteringManager clustermanage = new ClusteringManager(TaskConfig.cmPath);
GeneralParameterTraining generalParameterTraining = new GeneralParameterTraining(clustermanage);
IParameters[] layoutParams = generalParameterTraining.runGeneralTraining();
/* save newly found parameters to config file */
TaskConfig.saveConfigurationsToConfigFile(TaskConfig.outConfigPath);
/* print out information about training */
TaskConfig.monitor.setStatusMessage(TaskConfig.NL + "###### Best Parameter Configurations Found ######");
for (int i = 0; i < layoutParams.length; i++) {
TaskConfig.monitor.setStatusMessage(layoutParams[i].toString());
InfoFile.appendLnProjectResults(layoutParams[i].toString());
}
time = System.currentTimeMillis() - time;
TaskConfig.monitor.setStatusMessage("Time taken for complete general training: " + TaskUtility.convertTime(time));
} catch (InvalidInputFileException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
} catch (InvalidTypeException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
}
} else if (TaskConfig.mode == TaskConfig.COMPARISON_MODE || TaskConfig.mode == TaskConfig.HIERARICHAL_MODE) {
Thread t = new IteratorThread();
t.start();
} else /* no such mode */
{
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: This mode does not exist: " + TaskConfig.mode);
}
/* create info file */
if (TaskConfig.info) {
InfoFile info = new InfoFile();
info.instantiateFile(TaskConfig.infoPath);
info.createAndCloseInfoFile();
/* clear information from StringBuffers in InfoFile */
InfoFile.clearData();
}
// /* ====== CLEAN UP AT END ====== */
} catch (Exception e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR occured in run with the following message: " + e.getMessage());
// e.printStackTrace();
}
/* release permit in semaphore if necessary */
if (semaphore != null) {
semaphore.release();
}
/* reset the run button back to "RUN" and reset action command */
}
Aggregations