use of ca.utoronto.tdccbr.mcode.internal.model.MCODEParameters in project MCODE by BaderLab.
the class AnalysisAction method execute.
private void execute(CyNetwork network, TaskObserver taskObserver) {
int resultId = resultsMgr.getNextResultId();
var currentParams = mcodeUtil.getParameterManager().getLiveParams().copy();
var nodes = network.getNodeList();
var selectedNodes = new ArrayList<Long>();
for (CyNode n : nodes) {
if (network.getRow(n).get(CyNetwork.SELECTED, Boolean.class))
selectedNodes.add(n.getSUID());
}
var selectedNodesRGI = selectedNodes.toArray(new Long[selectedNodes.size()]);
currentParams.setSelectedNodes(selectedNodesRGI);
final MCODEAlgorithm alg;
MCODEParameters savedParams = null;
// otherwise we construct a new alg class
if (mcodeUtil.containsNetworkAlgorithm(network.getSUID())) {
alg = mcodeUtil.getNetworkAlgorithm(network.getSUID());
// Get a copy of the last saved parameters for comparison with the current ones
savedParams = mcodeUtil.getParameterManager().getNetworkParams(network.getSUID());
} else {
alg = new MCODEAlgorithm(null, mcodeUtil);
mcodeUtil.addNetworkAlgorithm(network.getSUID(), alg);
mode = FIRST_TIME;
}
var interruptedMessage = "";
// the clustering parameters are relevant if the optimization is used
if (mode == FIRST_TIME || isDirty(network) || (savedParams != null && (currentParams.getIncludeLoops() != savedParams.getIncludeLoops() || currentParams.getDegreeCutoff() != savedParams.getDegreeCutoff()))) {
mode = RESCORE;
logger.debug("Analysis: score network, find clusters");
mcodeUtil.getParameterManager().setParams(currentParams, resultId, network);
} else {
var res = resultsMgr.getFreshResult(network.getSUID(), currentParams);
if (res != null) {
mode = INTERRUPTION;
interruptedMessage = "The parameters you specified have not changed\n" + "(you used the same parameters in analysis #" + res.getId() + ").";
} else {
mode = REFIND;
logger.debug("Analysis: find clusters");
mcodeUtil.getParameterManager().setParams(currentParams, resultId, network);
}
}
// In case the user selected selection scope we must make sure that they selected at least 1 node
if (currentParams.getScope() == MCODEAnalysisScope.SELECTION && currentParams.getSelectedNodes().length < 1) {
mode = INTERRUPTION;
interruptedMessage = "You must first SELECT one or more NODES for this scope.";
}
if (mode == INTERRUPTION) {
JOptionPane.showMessageDialog(swingApplication.getJFrame(), interruptedMessage, "Analysis Interrupted", JOptionPane.WARNING_MESSAGE);
} else {
// Run MCODE
var tf = new MCODEAnalyzeTaskFactory(network, mode, resultId, alg, resultsMgr, mcodeUtil);
registrar.getService(DialogTaskManager.class).execute(tf.createTaskIterator(), taskObserver);
}
}
use of ca.utoronto.tdccbr.mcode.internal.model.MCODEParameters in project MCODE by BaderLab.
the class MCODEAlgorithmTest method testCompleteGraphIncludingLoops.
@Test
public void testCompleteGraphIncludingLoops() {
CyNetwork net = createCompleteGraph(16);
int resultId = resultsMgr.getNextResultId();
MCODEParameters params = new MCODEParameters();
params.setIncludeLoops(true);
List<MCODECluster> clusters = findClusters(net, params);
assertEquals(1, clusters.size());
MCODECluster c = clusters.get(0);
CySubNetwork cn = c.getNetwork();
assertNotNull(cn);
assertEquals(resultId, c.getResultId());
assertEquals(14.118, c.getScore(), 0.0009);
assertEquals(16, cn.getNodeCount());
assertEquals(120, cn.getEdgeCount());
assertNotNull(c.getSeedNode());
// TODO: fix
// check scores of all nodes
// for (CyNode n : cn.getNodeList()) {
// assertEquals(13.345, alg.getNodeScore(n.getSUID(), resultId), 0.001);
// }
}
use of ca.utoronto.tdccbr.mcode.internal.model.MCODEParameters in project MCODE by BaderLab.
the class MCODEUtilTest method testDisposeUnnusedNetworks.
@Test
public void testDisposeUnnusedNetworks() {
final CyNetwork net = createCompleteGraph(16);
final CyRootNetwork rn = netViewTestSupport.getRootNetworkFactory().getRootNetwork(net);
int originalNetCount = rn.getSubNetworkList().size();
final List<MCODECluster> clusters = findClusters(net);
assertEquals(1, clusters.size());
MCODEResult res = resultsMgr.createResult(net, new MCODEParameters(), clusters);
mcodeUtil.disposeUnusedNetworks(Collections.singleton(res));
assertEquals(originalNetCount + clusters.size(), rn.getSubNetworkList().size());
}
Aggregations