@Override public void run(TaskMonitor taskMonitor) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(CYTABLES_PACKAGE, getClass().getClassLoader()); taskMonitor.setProgress(0.33); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); taskMonitor.setProgress(0.67); cyTables = (CyTables) unmarshaller.unmarshal(inputStream); taskMonitor.setProgress(1); }
@Override public void run(TaskMonitor taskMonitor) throws Exception { if (network == null) network = appMgr.getCurrentNetwork(); views = new ArrayList<CyNetworkView>(viewMgr.getNetworkViews(network)); taskMonitor.showMessage( TaskMonitor.Level.INFO, "Views for network " + DataUtils.getNetworkTitle(network)); for (CyNetworkView view : views) { taskMonitor.showMessage(TaskMonitor.Level.INFO, " " + view); return; } }
@Override public void run(TaskMonitor monitor) throws Exception { monitor.setStatusMessage("Executing ForceAtlas2 layout"); List<ExtensionCall> calls = exec.buildExtensionCalls(); double progress = 0.0; for (ExtensionCall call : calls) { Object callRetValue = plugin.getInteractor().executeExtensionCall(call, false); exec.processCallResponse(call, callRetValue); ++progress; monitor.setProgress(progress / ((double) calls.size())); } }
@Override public void run(TaskMonitor taskMonitor) throws Exception { taskMonitor.setTitle("Loading Gene Association File"); taskMonitor.setStatusMessage("Importing annotation file. Please wait..."); taskMonitor.setProgress(-1.0); this.ontologyDAG = OntologyDAGManager.getOntologyDAG(ontologyDagName); if (ontologyDAG == null) logger.warn("Could not find associated Ontology DAG."); else { termIDList = ontologyDAG.getDefaultNodeTable().getColumn(CyNetwork.NAME).getValues(String.class); } BufferedReader bufRd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8").newDecoder())); String line = null; String[] parts; while ((line = bufRd.readLine()) != null) { // Validate. if (line.contains(COMPATIBLE_VERSION)) break; } // Create result table table = serviceRegistrar .getService(CyTableFactory.class) .createTable(tableName, CyNetwork.NAME, String.class, true, true); createColumns(); while ((line = bufRd.readLine()) != null) { if (line.startsWith("!")) continue; parts = line.split(GA_DELIMITER); // GA is a fixed format file. Read only valid lines. if (parts.length >= EXPECTED_COL_COUNT) { parseGA(parts); } } bufRd.close(); is.close(); is = null; tables = new CyTable[1]; tables[0] = table; serviceRegistrar.getService(CyTableManager.class).addTable(table); }
private void loadNetwork(TaskMonitor tm) throws IOException { final CyNetwork network = this.rootNetwork.addSubNetwork(); tm.setProgress(0.10); this.reader.setNetwork(network); if (this.cancelled) return; this.reader.read(); tm.setProgress(0.80); if (this.cancelled) return; networks = new CyNetwork[] {network}; tm.setProgress(1.0); }
/** * Inform User of Network Stats. * * @param taskMonitor */ private void informUserOfGraphStats(CyNetwork newNetwork, TaskMonitor taskMonitor) { NumberFormat formatter = new DecimalFormat("#,###,###"); StringBuffer sb = new StringBuffer(); // Give the user some confirmation sb.append("Successfully loaded network from: "); sb.append(url); sb.append("\n\nNetwork contains " + formatter.format(newNetwork.getNodeCount())); sb.append(" nodes and " + formatter.format(newNetwork.getEdgeCount())); sb.append(" edges.\n\n"); // TODO: Port this // if (newNetwork.getNodeCount() < Integer.parseInt(CytoscapeInit.getProperties() // // .getProperty("viewThreshold"))) { // sb.append("Network is under " // + CytoscapeInit.getProperties().getProperty("viewThreshold") // + " nodes. A view will be automatically created."); // } else { // sb.append("Network is over " // + CytoscapeInit.getProperties().getProperty("viewThreshold") // + " nodes. A view has not been created." // + " If you wish to view this network, use " // + "\"Create View\" from the \"Edit\" menu."); // } taskMonitor.setStatusMessage(sb.toString()); }
@Override public void run(TaskMonitor tm) throws Exception { tm.setTitle("Loading network from table"); tm.setProgress(0.0); tm.setStatusMessage("Loading network..."); Workbook workbook = null; // Load Spreadsheet data for preview. if (fileType != null && (fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) && workbook == null) { try { workbook = WorkbookFactory.create(is); } catch (InvalidFormatException e) { throw new IllegalArgumentException( "Could not read Excel file. Maybe the file is broken?", e); } finally { if (is != null) is.close(); } } try { if (this.fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || this.fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) { String networkName = ntmp.getName(); if (networkName == null) networkName = workbook.getSheetName(0); final Sheet sheet = workbook.getSheet(networkName); reader = new ExcelNetworkSheetReader( networkName, sheet, ntmp, nMap, rootNetwork, serviceRegistrar); } else { reader = new NetworkTableReader(inputName, is, ntmp, nMap, rootNetwork, serviceRegistrar); } } catch (Exception ioe) { tm.showMessage(TaskMonitor.Level.ERROR, "Unable to read table: " + ioe.getMessage()); return; } loadNetwork(tm); tm.setProgress(1.0); }
@Override public void run(TaskMonitor taskMonitor) throws Exception { taskMonitor.setTitle("Updating Organism Interactome Data Files"); taskMonitor.setProgress(-1); taskMonitor.setStatusMessage("Downloading data from BioGRID..."); BiogridDataLoader task = new BiogridDataLoader(props, dataSource, settingFileLocation); task.extract(true); final String version = task.getVersion(); taskMonitor.setProgress(1.0d); taskMonitor.setStatusMessage( "Organism network data files has been updated to BioGRID version " + version + ". Please restart Cytoscape to use new data."); }
/** Executes Task. */ public void run(TaskMonitor taskMonitor) throws Exception { taskMonitor.setTitle("Loading Network"); taskMonitor.setProgress(0); taskMonitor.setStatusMessage("Reading in Network Data..."); try { CyNetworkReaderManager readerManager = factory.getCyNetworkViewReaderManager(); CyNetworkReader reader = readerManager.getReader(url.toURI(), url.getFile()); if (reader == null) { JOptionPane.showMessageDialog( factory.getCySwingApplication().getJFrame(), "Unable to connect to URL " + url, "URL Connect Error", JOptionPane.ERROR_MESSAGE); return; } taskMonitor.setStatusMessage("Creating Cytoscape Network..."); reader.run(taskMonitor); CyNetwork[] networks = reader.getNetworks(); CyNetwork cyNetwork = networks[0]; // TODO: Does CPath2 listen for this? // Object[] ret_val = new Object[2]; // ret_val[0] = cyNetwork; // ret_val[1] = url.toString(); // // Cytoscape.firePropertyChange(Cytoscape.NETWORK_LOADED, null, ret_val); if (cyNetwork != null) { informUserOfGraphStats(cyNetwork, taskMonitor); } else { StringBuffer sb = new StringBuffer(); sb.append("Could not read network from: "); sb.append(url); sb.append("\nThis file may not be a valid file format."); throw new IOException(sb.toString()); } taskMonitor.setProgress(1.0); } catch (Exception e) { throw new Exception("Unable to load network.", e); } }
@Override public void run(TaskMonitor monitor) throws Exception { // TODO Auto-generated method stub monitor.setTitle("Building the User Interface"); DynNetworkView<T> view = dynNetViewManager.getDynNetworkView(cyNetworkView); DynNetwork<T> dynamicnetwork = view.getNetwork(); GraphMetricsPanel<T, C> graphMetricsPanel = new GraphMetricsPanel<T, C>(this.cyActivator, dynamicnetwork); this.cyActivator .getCyServiceRegistrar() .registerService(graphMetricsPanel, CytoPanelComponent.class, new Properties()); }
@Override public CyNetworkView buildCyNetworkView(final CyNetwork network) { final CyNetworkView view = networkViewFactory.createNetworkView(network); final CyLayoutAlgorithm layout = layouts.getDefaultLayout(); TaskIterator itr = layout.createTaskIterator( view, layout.getDefaultLayoutContext(), CyLayoutAlgorithm.ALL_NODE_VIEWS, ""); Task nextTask = itr.next(); try { nextTask.run(parentTaskMonitor); } catch (Exception e) { throw new RuntimeException("Could not finish layout", e); } parentTaskMonitor.setProgress(1.0d); return view; }
@Override public void run(final TaskMonitor taskMonitor) { taskMonitor.setTitle("Adding variations..."); taskMonitor.setProgress(0.0d); if (!mergeStrategy.isRetain()) { final Lock nodesReadLock = model.nodes().getReadWriteLock().readLock(); final Lock featuresReadLock = model.features().getReadWriteLock().readLock(); final Lock variationsWriteLock = model.variations().getReadWriteLock().writeLock(); nodesReadLock.lock(); featuresReadLock.lock(); variationsWriteLock.lock(); try { for (int i = 0, size = model.features().size(); i < size; i++) { Feature feature = model.features().get(i); taskMonitor.setStatusMessage( "Retrieving variations associated with feature " + feature + "..."); final List<Variation> variations = model.getVariationService().variations(feature); taskMonitor.setStatusMessage( resultStatusMessage(variations.size(), "variation", "feature", feature)); // todo: merge strategy for (Variation variation : variations) { if (!model.variations().contains(variation)) { model.variations().add(variation); } } // todo: count doesn't consider existing variations for (CyNode node : model.nodesFor(feature)) { addCount(node, model.getNetwork(), "variation_count", variations.size()); } taskMonitor.setProgress(i / (double) size); } } finally { nodesReadLock.unlock(); featuresReadLock.unlock(); variationsWriteLock.unlock(); } } taskMonitor.setProgress(1.0d); }
@Override public void run(TaskMonitor taskMonitor) throws Exception { parentTaskMonitor = taskMonitor; long start = System.currentTimeMillis(); taskMonitor.setProgress(0.01d); taskMonitor.setTitle("Loading PSI-MI 2.5.x XML File "); taskMonitor.setStatusMessage("Loading data file in PSI-MI 2.5 XML format."); // support to add network into existing collection this.initNodeMap(); PsimiXmlReader reader = new PsimiXmlReader(); EntrySet result = reader.read(inputStream); taskMonitor.setProgress(0.4d); taskMonitor.setStatusMessage("Data Loaded. Mapping Data to Network..."); if (cancelFlag) { inputStream.close(); reader = null; result = null; return; } // network = cyNetworkFactory.createNetwork(); String networkCollectionName = this.rootNetworkList.getSelectedValue().toString(); if (networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) { // This is a new network collection, create a root network and a subnetwork, which is a base // subnetwork network = cyNetworkFactory.createNetwork(); } else { // Add a new subNetwork to the given collection network = this.name2RootMap.get(networkCollectionName).addSubNetwork(); } mapper = new PSIMI25EntryMapper(network, result); mapper.map(); taskMonitor.setProgress(1.0d); logger.info( "PSI-MI XML Data Import finihsed in " + (System.currentTimeMillis() - start) + " msec."); }
@Override protected void complete(TaskMonitor tm) throws Exception { tm.setProgress(0.4); tm.setTitle("Set network tables"); tm.setStatusMessage("Setting network tables..."); mergeNetworkTables(); tm.setProgress(0.5); tm.setTitle("Restore virtual columns"); tm.setStatusMessage("Restoring virtual columns..."); restoreVirtualColumns(); tm.setProgress(0.6); tm.setTitle("Extract network views"); tm.setStatusMessage("Extracting network views..."); // Read the session file again, this time to extract the network views networksExtracted = true; readSessionFile(tm); tm.setProgress(0.8); tm.setTitle("Update SUID columns"); tm.setStatusMessage("Updating SUID columns..."); updateSUIDColumns(); super.complete(tm); }
/** * Calculates the node distances. * * @return the <code>int[][]</code> array of calculated distances or null if the task was canceled * or there was an error */ public int[][] calculate() { int currentProgress = 0; this.maxValue = distances.length; CyNode[] nodes = new CyNode[nodesList.size()]; // TODO: REMOVE // System.err.println( "Calculating all node distances.. for: " // +nodesList.size()+" and "+nodes.length ); // We don't have to make new Integers all the time, so we store the index // Objects in this array for reuse. Integer[] integers = new Integer[nodes.length]; // Fill the nodes array with the nodes in their proper index locations. // int index; CyNode from_node; for (int i = 0; i < nodes.length; i++) { from_node = (CyNode) nodesList.get(i); if (from_node == null) { continue; } int index = ((Integer) nodeIndexToMatrixIndexMap.get(from_node.getSUID())).intValue(); // index = ((Integer) nodeIndexToMatrixIndexMap.get(new // Integer(from_node.getRootGraphIndex()))).intValue(); if ((index < 0) || (index >= nodes.length)) { System.err.println( "WARNING: GraphNode \"" + from_node + "\" has an index value that is out of range: " + index + ". Graph indices should be maintained such " + "that no index is unused."); return null; } if (nodes[index] != null) { System.err.println( "WARNING: GraphNode \"" + from_node + "\" has an index value ( " + index + " ) that is the same as " + "that of another GraphNode ( \"" + nodes[index] + "\" ). Graph indices should be maintained such " + "that indices are unique."); return null; } nodes[index] = from_node; Integer in = new Integer(index); integers[index] = in; } LinkedList queue = new LinkedList(); boolean[] completed_nodes = new boolean[nodes.length]; Iterator neighbors; CyNode to_node; CyNode neighbor; int neighbor_index; int to_node_distance; int neighbor_distance; for (int from_node_index = 0; from_node_index < nodes.length; from_node_index++) { if (this.interrupted) { // The task was canceled this.distances = null; return this.distances; } from_node = nodes[from_node_index]; if (from_node == null) { // Make the distances in this row all Integer.MAX_VALUE. if (distances[from_node_index] == null) { distances[from_node_index] = new int[nodes.length]; } Arrays.fill(distances[from_node_index], Integer.MAX_VALUE); continue; } // TODO: REMOVE // System.err.print( "Calculating node distances from graph node " + // from_node ); // System.err.flush(); // Make the distances row and initialize it. if (distances[from_node_index] == null) { distances[from_node_index] = new int[nodes.length]; } Arrays.fill(distances[from_node_index], Integer.MAX_VALUE); distances[from_node_index][from_node_index] = 0; // Reset the completed nodes array. Arrays.fill(completed_nodes, false); // Add the start node to the queue. queue.add(integers[from_node_index]); while (!(queue.isEmpty())) { if (this.interrupted) { // The task was canceled this.distances = null; return this.distances; } int index = ((Integer) queue.removeFirst()).intValue(); if (completed_nodes[index]) { continue; } completed_nodes[index] = true; to_node = nodes[index]; to_node_distance = distances[from_node_index][index]; if (index < from_node_index) { // Oh boy. We've already got every distance from/to this node. int distance_through_to_node; for (int i = 0; i < nodes.length; i++) { if (distances[index][i] == Integer.MAX_VALUE) { continue; } distance_through_to_node = to_node_distance + distances[index][i]; if (distance_through_to_node <= distances[from_node_index][i]) { // Any immediate neighbor of a node that's already been // calculated for that does not already have a shorter path // calculated from from_node never will, and is thus complete. if (distances[index][i] == 1) { completed_nodes[i] = true; } distances[from_node_index][i] = distance_through_to_node; } } // End for every node, update the distance using the distance from // to_node. // So now we don't need to put any neighbors on the queue or // anything, since they've already been taken care of by the previous // calculation. continue; } // End if to_node has already had all of its distances calculated. neighbors = getNeighbors(to_node).iterator(); // neighbors = perspective.neighborsList(to_node).iterator(); while (neighbors.hasNext()) { if (this.interrupted) { this.distances = null; return this.distances; } neighbor = (CyNode) neighbors.next(); neighbor_index = ((Integer) nodeIndexToMatrixIndexMap.get(neighbor.getSUID())).intValue(); // neighbor_index = ((Integer) nodeIndexToMatrixIndexMap.get(new // Integer(neighbor.getRootGraphIndex()))).intValue(); // If this neighbor was not in the incoming List, we cannot include // it in any paths. if (nodes[neighbor_index] == null) { distances[from_node_index][neighbor_index] = Integer.MAX_VALUE; continue; } if (completed_nodes[neighbor_index]) { // We've already done everything we can here. continue; } neighbor_distance = distances[from_node_index][neighbor_index]; if ((to_node_distance != Integer.MAX_VALUE) && (neighbor_distance > (to_node_distance + 1))) { distances[from_node_index][neighbor_index] = (to_node_distance + 1); queue.addLast(integers[neighbor_index]); } // TODO: REMOVE // System.out.print( "." ); // System.out.flush(); } // For each of the next nodes' neighbors // TODO: REMOVE // System.out.print( "|" ); // System.out.flush(); } // For each to_node, in order of their (present) distances // TODO: REMOVE /* System.err.println( "done." ); */ // Calculate Percentage. This must be a value between 0..100. int percentComplete = (int) (((double) currentProgress / maxValue) * 100); // Estimate Time Remaining long timeRemaining = maxValue - currentProgress; // Update the Task Monitor. // This automatically updates the UI Component w/ progress bar. if (taskMonitor != null) { taskMonitor.setProgress(percentComplete); taskMonitor.setStatusMessage( "Calculating Node Distances: " + currentProgress + "of " + maxValue); // taskMonitor.setEstimatedTimeRemaining(timeRemaining); } currentProgress++; } // For each from_node // TODO: REMOVE // System.err.println( "..Done calculating all node distances." ); return distances; } // calculate
public void run(TaskMonitor monitor) { monitor.setTitle("Performing MCL cluster"); this.monitor = monitor; if (network == null) network = clusterManager.getNetwork(); context.setNetwork(network); NodeCluster.init(); DistanceMatrix matrix = context.edgeAttributeHandler.getMatrix(); if (matrix == null) { monitor.showMessage( TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?"); return; } // Update our tunable results clusterAttributeName = context.getClusterAttribute(); createGroups = context.advancedAttributes.createGroups; if (canceled) return; // Cluster the nodes runMCL = new RunMCL( matrix, context.inflation_parameter, context.iterations, context.clusteringThresh, context.maxResidual, context.maxThreads, monitor); runMCL.setDebug(debug); if (canceled) return; monitor.showMessage(TaskMonitor.Level.INFO, "Clustering..."); // results = runMCL.run(monitor); List<NodeCluster> clusters = runMCL.run(network, monitor); if (clusters == null) return; // Canceled? monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups"); // Remove any leftover groups from previous runs removeGroups(network, GROUP_ATTRIBUTE); monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups"); params = new ArrayList<String>(); context.edgeAttributeHandler.setParams(params); List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE); results = new AbstractClusterResults(network, nodeClusters); monitor.showMessage(TaskMonitor.Level.INFO, "MCL results:\n" + results); if (context.vizProperties.showUI) { monitor.showMessage(TaskMonitor.Level.INFO, "Creating network"); insertTasksAfterCurrentTask( new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges)); } }
@Override public void run(TaskMonitor taskMonitor) { taskMonitor.setProgress(0.0); taskMonitor.setTitle("PRWP with Priors ranking of clusters"); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters..."); taskMonitor.setProgress(0.1); List<NodeCluster> clusters = ClusterUtils.fetchClusters(network); taskMonitor.setProgress(0.5); initVariables(); clusters.forEach(NodeCluster::initNodeScores); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting node scores in clusters"); addNodes(); taskMonitor.setProgress(0.6); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting edge scores in clusters"); addEdges(); taskMonitor.setProgress(0.7); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Calculating PageRank scores"); PageRank<PRNode, PREdge> pageRank = performPageRank(); taskMonitor.setProgress(0.8); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Inserting scores into clusters"); insertScores(clusters, pageRank); taskMonitor.setProgress(0.9); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Insert cluster information in tables"); ClusterUtils.insertResultsInColumns(network, clusters, SHORTNAME); taskMonitor.setProgress(1.0); taskMonitor.showMessage(TaskMonitor.Level.INFO, "Done..."); }
@Override public void run(TaskMonitor taskMonitor) throws Exception { CaseList caseList = (CaseList) caseSetComboBox.getSelectedItem(); Object[] profiles = profileList.getSelectedValues(); String geneSymbolField = (String) geneSymbolComboBox.getSelectedItem(); // update the configuration to store this field MondrianApp app = MondrianApp.getInstance(); CyNetwork currentNetwork = app.getAppManager().getCurrentNetwork(); // call the next two lines in the right order! app.getMondrianConfiguration() .setNetworkGeneSymbolAttr(currentNetwork.getSUID(), geneSymbolField); Map<String, Long> geneSymbolMap = app.getMondrianConfiguration().getGeneNodeMap(currentNetwork.getSUID()); List<String> genes = new ArrayList<String>(geneSymbolMap.keySet()); // Extract data from web service int p = 1; List<GeneticProfile> profileList = new ArrayList<GeneticProfile>(); List<MondrianCyTable> importedTables = new ArrayList<MondrianCyTable>(); CyNetwork network = app.getAppManager().getCurrentNetwork(); CancerStudy study = (CancerStudy) cancerStudyComboBox.getSelectedItem(); for (Object obj : profiles) { GeneticProfile profile = (GeneticProfile) obj; profileList.add(profile); taskMonitor.setStatusMessage("Loading genetic profile: " + profile.getName()); taskMonitor.setProgress(p++ / (double) profiles.length); CyTable table = MondrianApp.getInstance() .getTableFactory() .createTable(profile.getName(), CyIdentifiable.SUID, Long.class, true, true); DataTypeMatrix matrix = portalClient.getProfileData(caseList, profile, genes); List<String> dataColNames = matrix.getDataColNames(); for (String colName : dataColNames) { if (profile.getType() == GENETIC_PROFILE_TYPE.MUTATION_EXTENDED) { table.createColumn(colName, String.class, false); } else { table.createColumn(colName, Double.class, false); } } // Add rows for (String rowName : matrix.getRowNames()) { long suid = geneSymbolMap.get(rowName); CyRow row = table.getRow(suid); // row.set("selected", currentNetwork.getDefaultNodeTable().getRow(suid).get("selected", // Boolean.class)); // row.set(geneSymbolField, rowName); int i = 0; for (String colName : dataColNames) { row.set(colName, matrix.getDataRow(rowName).get(i++)); } } log.debug( "Loading genetic profile: " + profile.getName() + "; Insert Table: " + matrix.getNumRows() + ", " + matrix.getDataColNames().size()); MondrianCyTable mondrianCyTable = new MondrianCyTable(study, profile, caseList, table); importedTables.add(mondrianCyTable); // } app.getMondrianConfiguration().registerMondrianTables(network, importedTables); // app.getMondrianConfiguration().cbioDataImport(currentNetwork.getSUID(), profileList, // caseList); }
public void run(TaskMonitor taskMonitor) throws Exception { taskMonitor.setTitle("Exiting Chimera"); structureManager.exitChimera(); }
@Override public void run(TaskMonitor taskMonitor) throws Exception { desktopApp.getJFrame().getGlassPane().setVisible(true); taskMonitor.setTitle("Gene Set / Mutation Analysis"); taskMonitor.setStatusMessage("Loading file..."); taskMonitor.setProgress(.25d); try { Map<String, Integer> geneToSampleNumber = null; Map<String, String> geneToSampleString = null; Map<String, Set<String>> sampleToGenes = null; Set<String> selectedGenes = null; if (format.equals("MAF")) { sampleToGenes = new MATFileLoader().loadSampleToGenes(file.getAbsolutePath(), chooseHomoGenes); selectedGenes = CancerAnalysisUtilitites.selectGenesInSamples(sampleCutoffValue, sampleToGenes); } else if (format.equals("GeneSample")) { geneToSampleNumber = new HashMap<String, Integer>(); geneToSampleString = new HashMap<String, String>(); loadGeneSampleFile(file, geneToSampleNumber, geneToSampleString); selectedGenes = selectGenesBasedOnSampleCutoff(geneToSampleNumber, sampleCutoffValue); } else if (format.equals("GeneSet")) { selectedGenes = loadGeneSetFile(file); } // Check if it is possible to construct the network // given the sample size. if (useLinkers) { taskMonitor.setStatusMessage("Checking FI Network size..."); FINetworkService fiService = PlugInScopeObjectManager.getManager().getNetworkService(); Integer cutoff = fiService.getNetworkBuildSizeCutoff(); if (cutoff != null && selectedGenes.size() >= cutoff) { JOptionPane.showMessageDialog( desktopApp.getJFrame(), "The size of the gene set is too big. Linker genes should not be used!\n" + "Please try again without using linker genes.", "Error in Building Network", JOptionPane.ERROR_MESSAGE); desktopApp.getJFrame().getGlassPane().setVisible(false); return; } } CytoPanel controlPane = desktopApp.getCytoPanel(CytoPanelName.WEST); int selectedIndex = controlPane.getSelectedIndex(); taskMonitor.setStatusMessage("Constructing FI Network..."); taskMonitor.setProgress(.50d); CyNetwork network = constructFINetwork(selectedGenes, file.getName()); network.getDefaultNetworkTable().getRow(network.getSUID()).set("name", file.getName()); if (network == null) { JOptionPane.showMessageDialog( desktopApp.getJFrame(), "Cannot find any functional interaction among provided genes.\n" + "No network can be constructed.\n" + "Note: only human gene names are supported.", "Empty Network", JOptionPane.INFORMATION_MESSAGE); desktopApp.getJFrame().getGlassPane().setVisible(false); return; } netManager.addNetwork(network); // Fix for missing default value persistence in CyTables // Should be remedied in the 3.1 api CyTable nodeTable = network.getDefaultNodeTable(); for (Object name : network.getNodeList()) { CyNode node = (CyNode) name; Long nodeSUID = node.getSUID(); nodeTable.getRow(nodeSUID).set("isLinker", false); } controlPane.setSelectedIndex(selectedIndex); if (sampleToGenes != null) { geneToSampleNumber = new HashMap<String, Integer>(); geneToSampleString = new HashMap<String, String>(); Map<String, Set<String>> geneToSamples = InteractionUtilities.switchKeyValues(sampleToGenes); geneToSamples.keySet().retainAll(selectedGenes); for (String gene : geneToSamples.keySet()) { Set<String> samples = geneToSamples.get(gene); geneToSampleNumber.put(gene, samples.size()); geneToSampleString.put(gene, InteractionUtilities.joinStringElements(";", samples)); } } taskMonitor.setStatusMessage("Formatting network attributes..."); taskMonitor.setProgress(.65d); CyTableManager tableManager = new CyTableManager(); CyNetworkView view = viewFactory.createNetworkView(network); tableManager.storeFINetworkVersion(view); tableManager.storeDataSetType(network, CyTableFormatter.getSampleMutationData()); viewManager.addNetworkView(view); if (geneToSampleNumber != null && !geneToSampleNumber.isEmpty()) { tableManager.loadNodeAttributesByName(view, "sampleNumber", geneToSampleNumber); } if (geneToSampleString != null && !geneToSampleString.isEmpty()) { tableManager.loadNodeAttributesByName(view, "samples", geneToSampleString); } // Check if linker genes are to be used. if (useLinkers) { taskMonitor.setStatusMessage("Fetching linker genes..."); Map<String, Boolean> geneToIsLinker = new HashMap<String, Boolean>(); for (Object name : network.getNodeList()) { CyNode node = (CyNode) name; Long suid = node.getSUID(); String nodeName = network.getDefaultNodeTable().getRow(suid).get("name", String.class); geneToIsLinker.put(nodeName, !selectedGenes.contains(nodeName)); } tableManager.loadNodeAttributesByName(view, "isLinker", geneToIsLinker); } if (fetchFIAnnotations) { taskMonitor.setStatusMessage("Fetching FI annotations..."); new FIAnnotationHelper().annotateFIs(view, new RESTFulFIService(), tableManager); } if (view.getModel().getEdgeCount() != 0) { for (CyEdge edge : view.getModel().getEdgeList()) { tableManager.storeEdgeName(edge, view); } } BundleContext context = PlugInScopeObjectManager.getManager().getBundleContext(); ServiceReference visHelperRef = context.getServiceReference(FIVisualStyle.class.getName()); if (visHelperRef != null) { FIVisualStyleImpl styleHelper = (FIVisualStyleImpl) context.getService(visHelperRef); styleHelper.setVisualStyle(view); styleHelper.setLayout(); } // BundleContext context = // PlugInScopeObjectManager.getManager().getBundleContext(); // ServiceReference styleHelperRef = // context.getServiceReference(FIVisualStyleImpl.class.getName()); // FIVisualStyleImpl styleHelper = (FIVisualStyleImpl) // context.getService(styleHelperRef); taskMonitor.setProgress(1.0d); } catch (Exception e) { JOptionPane.showMessageDialog( desktopApp.getJFrame(), "Error in Loading File: " + e.getMessage(), "Error in Loading", JOptionPane.ERROR_MESSAGE); desktopApp.getJFrame().getGlassPane().setVisible(false); } desktopApp.getJFrame().getGlassPane().setVisible(false); }
private void readInput(TaskMonitor tm) throws IOException { this.parentTaskMonitor = tm; tm.setProgress(0.0); String line; final BufferedReader br = new BufferedReader( new InputStreamReader(inputStream, Charset.forName("UTF-8").newDecoder()), 128 * 1024); String networkCollectionName = this.rootNetworkList.getSelectedValue().toString(); CySubNetwork subNetwork; if (networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) { // This is a new network collection, create a root network and a subnetwork, which is a base // subnetwork CyNetwork rootNetwork = cyNetworkFactory.createNetwork(); subNetwork = this.cyRootNetworkManager.getRootNetwork(rootNetwork).addSubNetwork(); } else { // Add a new subNetwork to the given collection subNetwork = this.name2RootMap.get(networkCollectionName).addSubNetwork(); } // Build a Map based on the key attribute for the entire collection, // For SIF network, the 'shared name' attribute is the primary key this.initNodeMap(subNetwork.getRootNetwork(), "shared " + CyNetwork.NAME); tm.setProgress(0.1); // Generate bundled event to avoid too many events problem. final String firstLine = br.readLine(); if (firstLine.contains(TAB)) delimiter = TAB; createEdge(new Interaction(firstLine.trim(), delimiter), subNetwork); tm.setProgress(0.15); tm.setStatusMessage("Processing the interactions..."); int numInteractionsRead = 0; while ((line = br.readLine()) != null) { if (cancelled) { // Cancel called. Clean up the garbage. nMap.clear(); nMap = null; subNetwork = null; br.close(); return; } if (line.trim().length() <= 0) continue; try { final Interaction itr = new Interaction(line, delimiter); createEdge(itr, subNetwork); } catch (Exception e) { // Simply ignore invalid lines. continue; } if ((++numInteractionsRead % 1000) == 0) tm.setStatusMessage("Processed " + numInteractionsRead + " interactions so far."); } br.close(); tm.setStatusMessage("Processed " + numInteractionsRead + " interactions in total."); nMap.clear(); nMap = null; this.cyNetworks = new CyNetwork[] {subNetwork}; tm.setProgress(1.0); logger.debug("SIF file loaded: ID = " + subNetwork.getSUID()); }
@SuppressWarnings("unchecked") @Override protected void doLayout(TaskMonitor taskMonitor) { if (!context.m_cancel && networkView != null && dynView != null) { taskMonitor.setTitle("Compute Dynamic Kamada Kawai Force Layout"); taskMonitor.setStatusMessage("Running energy minimization..."); taskMonitor.setProgress(0); // int size = (int) (4*50*Math.sqrt(nodesToLayOut.size())); int size = (int) (dynView.getCurrentVisualStyle().getDefaultValue(BasicVisualLexicon.NODE_SIZE) * Math.sqrt(nodesToLayOut.size())); // int size =(int) // dynView.getCurrentVisualStyle().getDefaultValue(BasicVisualLexicon.NETWORK_HEIGHT).floatValue(); snap = new DynNetworkSnapshotImpl<T>(dynView, context.m_attribute_name); kklayout = new KKLayout<T>(snap, new Dimension(4 * size, 4 * size)); List<Double> events = context.m_event_list; // Full KK evaluation to initialize the network at time t=0 kklayout.setAdjustForGravity(true); kklayout.setExchangeVertices(context.m_exchange_nodes); kklayout.setAutoscaling(context.m_autoscale); kklayout.setMaxIterations(1000); // Compute incremental KK. The number of iterations is proportional to the time to the next // event. double t0, t1; for (int t = 0; t < events.size() - 1; t++) { t0 = events.get(Math.max(0, t - context.m_past_events)); t1 = events.get(Math.min(events.size() - 1, t + 1 + context.m_future_events)); snap.setInterval((DynInterval<T>) new DynIntervalDouble(t0, t1), t, 1000, 1000); if (!context.m_attribute_name.equals("none")) kklayout.setDistance(new DijkstraShortestPath<T>(snap, snap.getWeightMap(), 100)); else kklayout.setDistance(new UnweightedShortestPath<T>(snap)); kklayout.initialize(); kklayout.run(); updateGraph((DynInterval<T>) new DynIntervalDouble(events.get(t), events.get(t + 1))); kklayout.setMaxIterations( (int) (context.m_iteration_rate * (events.get(t + 1) - events.get(t)))); if (t % 10 == 0) taskMonitor.setProgress(((double) t) / (double) events.size()); taskMonitor.setStatusMessage("Running energy minimization... " + t + "/" + events.size()); } // Finalize layout layout.finalize(); taskMonitor.setProgress(1); // Set the current network view initializePositions(size); layout.initNodePositions(timeInterval); view.fitContent(); view.updateView(); } }