use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class RankingPanel method createClusterImage.
/**
* Convert a network to an image. This is used by the MCODEResultsPanel.
*
* @param cluster Input network to convert to an image
* @param height Height that the resulting image should be
* @param width Width that the resulting image should be
* @param layouter Reference to the layout algorithm
* @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
* @return The resulting image
*/
public Image createClusterImage(final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
// System.out.println("CCI: inside method");
final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
// need to create a method get the subnetwork for a cluster
final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
// System.out.println("CCI: after getting root and network ");
// Progress reporters.
// There are three basic tasks, the progress of each is calculated and then combined
// using the respective weighting to get an overall progress global progress
// setting up the nodes and edges is deemed as 25% of the whole task
int weightSetupNodes = 20;
int weightSetupEdges = 5;
// layout it is 70%
double weightLayout = 75.0;
double goalTotal = weightSetupNodes + weightSetupEdges;
if (layoutNecessary) {
goalTotal += weightLayout;
}
// keeps track of progress as a percent of the totalGoal
double progress = 0;
final VisualStyle vs = getClusterStyle();
// System.out.println("CCI: after getClusterStyle");
final CyNetworkView clusterView = createNetworkView(net, vs);
// System.out.println("CCI: after createNetworkView");
clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
for (View<CyNode> nv : clusterView.getNodeViews()) {
if (interrupted) {
// problems the next time around
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
// Node position
final double x;
final double y;
// first prevents the program from throwing a null pointer exception in the second condition)
if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
// If it does, then we take the layout position that was already generated for it
x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
} else {
// Otherwise, randomize node positions before layout so that they don't all layout in a line
// (so they don't fall into a local minimum for the SpringEmbedder)
// If the SpringEmbedder implementation changes, this code may need to be removed
// size is small for many default drawn graphs, thus +100
x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
if (!layoutNecessary) {
goalTotal += weightLayout;
progress /= (goalTotal / (goalTotal - weightLayout));
layoutNecessary = true;
}
}
nv.setVisualProperty(NODE_X_LOCATION, x);
nv.setVisualProperty(NODE_Y_LOCATION, y);
// Might be specific to MCODE
/*
// Node shape
if (cluster.getSeedNode() == nv.getModel().getSUID()) {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
} else {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.ELLIPSE);
}
*/
/*
// Update loader
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getNodeViews().size()) *
((double) weightSetupNodes / (double) goalTotal);
loader.setProgress((int) progress, "Setup: nodes");
}
*/
}
if (clusterView.getEdgeViews() != null) {
for (int i = 0; i < clusterView.getEdgeViews().size(); i++) {
if (interrupted) {
// logger.error("Interrupted: Edge Setup");
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
/*
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getEdgeViews().size()) *
((double) weightSetupEdges / (double) goalTotal);
loader.setProgress((int) progress, "Setup: edges");
}
*/
}
}
if (layoutNecessary) {
if (layouter == null) {
layouter = new SpringEmbeddedLayouter();
}
layouter.setGraphView(clusterView);
// The doLayout method should return true if the process completes without interruption
if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
// Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
resetLoading();
return null;
}
}
final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = (Graphics2D) image.getGraphics();
SwingUtilities.invokeLater(new Runnable() {
// @Override
public void run() {
try {
final Dimension size = new Dimension(width, height);
JPanel panel = new JPanel();
panel.setPreferredSize(size);
panel.setSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setBackground((Color) vs.getDefaultValue(NETWORK_BACKGROUND_PAINT));
JWindow window = new JWindow();
window.getContentPane().add(panel, BorderLayout.CENTER);
RenderingEngine<CyNetwork> re = renderingEngineFactory.createRenderingEngine(panel, clusterView);
vs.apply(clusterView);
clusterView.fitContent();
clusterView.updateView();
window.pack();
window.repaint();
re.createImage(width, height);
re.printCanvas(g);
g.dispose();
if (clusterView.getNodeViews().size() > 0) {
cluster.setView(clusterView);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
layouter.resetDoLayout();
resetLoading();
return image;
}
use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class RankingPanelTask method setNodeColors.
private void setNodeColors() {
String rankingAlgorithmName = getRankingAlgorithmName();
VisualStyle vs = ViewUtils.copyStyle(manager, ViewUtils.getCurrentVisualStyle(manager), "_removeThis");
vs.setTitle("Ranking results colors");
VisualMappingFunctionFactory vmff = manager.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
ContinuousMapping mapping = (ContinuousMapping) vmff.createVisualMappingFunction(rankingAlgorithmName, Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
Color color1 = new Color(170, 221, 221);
Color color2 = new Color(212, 229, 212);
Color color3 = new Color(255, 238, 204);
Color color4 = new Color(255, 195, 178);
Color color5 = new Color(255, 153, 153);
double belowAverage = NodeCluster.getAverageRankScore(clusters) / 2.0;
double overAverage = NodeCluster.getMaxRankScore(clusters) / 2.0;
BoundaryRangeValues<Paint> range1 = new BoundaryRangeValues<>(color1, color1, color2);
BoundaryRangeValues<Paint> range2 = new BoundaryRangeValues<>(color3, color4, color5);
mapping.addPoint(belowAverage, range1);
mapping.addPoint(overAverage, range2);
vs.addVisualMappingFunction(mapping);
ViewUtils.setVisualStyle(manager, manager.getNetworkView(), vs);
}
use of org.cytoscape.view.vizmap.VisualStyle in project clusterMaker2 by RBVI.
the class ResultsPanel method createClusterImage.
/**
* Convert a network to an image. This is used by the MCODEResultsPanel.
*
* @param cluster Input network to convert to an image
* @param height Height that the resulting image should be
* @param width Width that the resulting image should be
* @param layouter Reference to the layout algorithm
* @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
* @return The resulting image
*/
public Image createClusterImage(final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
// System.out.println("CCI: inside method");
final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
// need to create a method get the subnetwork for a cluster
final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
// System.out.println("CCI: after getting root and network ");
// Progress reporters.
// There are three basic tasks, the progress of each is calculated and then combined
// using the respective weighting to get an overall progress global progress
// setting up the nodes and edges is deemed as 25% of the whole task
int weightSetupNodes = 20;
int weightSetupEdges = 5;
// layout it is 70%
double weightLayout = 75.0;
double goalTotal = weightSetupNodes + weightSetupEdges;
if (layoutNecessary) {
goalTotal += weightLayout;
}
// keeps track of progress as a percent of the totalGoal
double progress = 0;
final VisualStyle vs = getClusterStyle();
// System.out.println("CCI: after getClusterStyle");
final CyNetworkView clusterView = createNetworkView(net, vs);
// System.out.println("CCI: after createNetworkView");
clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
for (View<CyNode> nv : clusterView.getNodeViews()) {
if (interrupted) {
// problems the next time around
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
// Node position
final double x;
final double y;
// first prevents the program from throwing a null pointer exception in the second condition)
if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
// If it does, then we take the layout position that was already generated for it
x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
} else {
// Otherwise, randomize node positions before layout so that they don't all layout in a line
// (so they don't fall into a local minimum for the SpringEmbedder)
// If the SpringEmbedder implementation changes, this code may need to be removed
// size is small for many default drawn graphs, thus +100
x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
if (!layoutNecessary) {
goalTotal += weightLayout;
progress /= (goalTotal / (goalTotal - weightLayout));
layoutNecessary = true;
}
}
nv.setVisualProperty(NODE_X_LOCATION, x);
nv.setVisualProperty(NODE_Y_LOCATION, y);
// Might be specific to MCODE
/*
// Node shape
if (cluster.getSeedNode() == nv.getModel().getSUID()) {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
} else {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.ELLIPSE);
}
*/
/*
// Update loader
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getNodeViews().size()) *
((double) weightSetupNodes / (double) goalTotal);
loader.setProgress((int) progress, "Setup: nodes");
}
*/
}
if (clusterView.getEdgeViews() != null) {
for (int i = 0; i < clusterView.getEdgeViews().size(); i++) {
if (interrupted) {
// logger.error("Interrupted: Edge Setup");
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
/*
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getEdgeViews().size()) *
((double) weightSetupEdges / (double) goalTotal);
loader.setProgress((int) progress, "Setup: edges");
}
*/
}
}
if (layoutNecessary) {
if (layouter == null) {
layouter = new SpringEmbeddedLayouter();
}
layouter.setGraphView(clusterView);
// The doLayout method should return true if the process completes without interruption
if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
// Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
resetLoading();
return null;
}
}
final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = (Graphics2D) image.getGraphics();
SwingUtilities.invokeLater(new Runnable() {
// @Override
public void run() {
try {
final Dimension size = new Dimension(width, height);
JPanel panel = new JPanel();
panel.setPreferredSize(size);
panel.setSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setBackground((Color) vs.getDefaultValue(NETWORK_BACKGROUND_PAINT));
JWindow window = new JWindow();
window.getContentPane().add(panel, BorderLayout.CENTER);
RenderingEngine<CyNetwork> re = renderingEngineFactory.createRenderingEngine(panel, clusterView);
vs.apply(clusterView);
clusterView.fitContent();
clusterView.updateView();
window.pack();
window.repaint();
re.createImage(width, height);
re.printCanvas(g);
g.dispose();
if (clusterView.getNodeViews().size() > 0) {
cluster.setView(clusterView);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
layouter.resetDoLayout();
resetLoading();
return image;
}
use of org.cytoscape.view.vizmap.VisualStyle in project PhenomeScape by soulj.
the class PhenomeExpress method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
taskMonitor.setTitle("Running PhenomeExpress");
taskMonitor.setStatusMessage("Preparing Networks");
long time = System.currentTimeMillis();
inputCheck();
setUpNetworks();
double[] relativeWeighting = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
double[] alphas = { 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };
double[] piValues = proteinNetwork.getPivalues();
Map<String, Integer> phenotypeMap = phenomeNetwork.getName2IndexMap();
double[] phenoArray = new double[phenomeNetwork.getName2IndexMap().size()];
selectedPhenotypes = new ArrayList<Phenotype>();
boolean first = true;
for (Phenotype phenotype : phenotypes) {
if (phenotype.getSelected()) {
if (first) {
phenotypeSelected = phenotype.getID();
phenotypeNamesSelected = phenotype.getName();
selectedPhenotypes.add(phenotype);
phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
first = false;
} else {
phenotypeSelected = phenotypeSelected + " ," + phenotype.getID();
phenotypeNamesSelected = phenotypeNamesSelected + " ," + phenotype.getName();
phenoArray[phenotypeMap.get(phenotype.getID())] = 1.0;
selectedPhenotypes.add(phenotype);
}
}
}
Map<CyNode, Integer> map = proteinNetwork.getNode2IndexMap();
int size = proteinNetwork.getNetwork().getNodeCount();
int[] occuranceArray = new int[size];
HashMap<CyNode, Protein> node2Protein = new HashMap<CyNode, Protein>();
if (cancelled) {
return;
}
taskMonitor.setStatusMessage("Calculating Activity Scores");
taskMonitor.setProgress(0.0);
double progress = 0.0;
SparseRowMatrix adjMatrix = SparseRowMatrix.create(size, size);
double[] transitionProbs = { 0.5, 0.6, 0.7, 0.8 };
for (double transitionProb : transitionProbs) {
TransitionMatrix transitionMatrix = new TransitionMatrix(phenomeNetwork.normalise(transitionProb, phenoGeneNetwork), proteinNetwork.normalise(transitionProb, phenoGeneNetwork), phenoGeneNetwork.normaliseT(transitionProb), phenoGeneNetwork.normalise(transitionProb));
for (double weighting : relativeWeighting) {
if (cancelled) {
return;
}
transitionMatrix.prepareVector(piValues, phenoArray, weighting);
for (double alpha : alphas) {
progress += 0.0051;
taskMonitor.setProgress(progress);
double[] pageRankResults = transitionMatrix.pageRank(alpha);
HashMap<Integer, Protein> index2ProteinMap = proteinNetwork.getIndex2ProteinMap();
for (int i = 0; i < index2ProteinMap.size(); i++) {
Protein protein = index2ProteinMap.get(i);
protein.setValue(pageRankResults[i]);
}
List<Protein> proteinList = new ArrayList<Protein>(index2ProteinMap.values());
Collections.sort(proteinList, new DescendingScoreComparator());
int rank = 0;
for (Protein protein : proteinList) {
rank++;
protein.setRank(rank);
node2Protein.put(protein.getNode(), protein);
}
Collections.sort(proteinList, new DescendingScoreComparator());
GIGA giga = new GIGA(proteinList, node2Protein, proteinNetwork, maxNetworkSize);
giga.compute();
for (GIGACluster cluster : giga.getClusters()) {
for (CyNode node : cluster.getCluster()) {
Integer index = map.get(node);
AVector row = adjMatrix.getRow(index);
if (!row.isMutable()) {
row = row.mutable();
}
for (CyNode node2 : cluster.getCluster()) {
Integer index2 = map.get(node2);
row.set(index2, row.get(index2) + 1.0);
occuranceArray[index2]++;
}
adjMatrix.replaceRow(index, row);
}
}
}
}
}
if (cancelled) {
return;
}
taskMonitor.setProgress(1.0);
taskMonitor.setStatusMessage("Creating Consensus Subnetworks");
AMatrix cooccuranceMat = adjMatrix.transposeInnerProduct(adjMatrix);
for (int i = 0; i < size; i++) {
AVector row = cooccuranceMat.getRow(i);
if (row.elementSum() > 0) {
row.divide(occuranceArray[i]);
Index nonSparse = row.nonSparseIndex();
for (int j = 0; j < nonSparse.length(); j++) {
if (row.get(nonSparse.get(j)) < 1.0) {
row.set(nonSparse.get(j), 0.0);
}
}
cooccuranceMat.replaceRow(i, row.sparse());
}
}
ConnectedComponentAnalyser CCA = new ConnectedComponentAnalyser(node2Protein);
ArrayList<PhenomeExpressSubnetwork> subnetworks = CCA.ccFromAdjMatrix(adjMatrix, proteinNetwork);
Iterator<PhenomeExpressSubnetwork> it = subnetworks.iterator();
while (it.hasNext()) {
PhenomeExpressSubnetwork subnetwork = it.next();
if (subnetwork.getNodeList().size() < this.minNetSize) {
it.remove();
}
}
if (cancelled) {
return;
}
taskMonitor.setStatusMessage("Calculating Subnetwork Significance");
subnetworksSignificance(subnetworks);
taskMonitor.setStatusMessage("Visualising Subnetworks");
List<Double> foldChangeValues = proteinNetwork.getNodeTable().getColumn(foldChange).getValues(Double.class);
double fcMax = Collections.max(foldChangeValues);
double fcMin = Collections.min(foldChangeValues);
// Apply the visual style to a NetworkView
VizStyle vizStyle = new VizStyle();
VisualStyle vs = vizStyle.createVizStyle(cyServiceRegistrar, geneName, foldChange, fcMax, fcMin);
this.property = getNodeLabelPositionProperty();
vs.setDefaultValue(property, property.parseSerializableString("N,S,c,0.0,0.0"));
VisualMappingManager visualMappingManager = cyServiceRegistrar.getService(VisualMappingManager.class);
visualMappingManager.setCurrentVisualStyle(vs);
ArrayList<CyNetworkView> networkViewList = new ArrayList<CyNetworkView>();
Iterator<PhenomeExpressSubnetwork> it2 = subnetworks.iterator();
CyNetworkManager networkManager = cyServiceRegistrar.getService(CyNetworkManager.class);
CyNetworkViewFactory networkViewFactory = cyServiceRegistrar.getService(CyNetworkViewFactory.class);
CyLayoutAlgorithmManager layoutManager = cyServiceRegistrar.getService(CyLayoutAlgorithmManager.class);
CyApplicationManager cyApplicationManager = cyServiceRegistrar.getService(CyApplicationManager.class);
CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");
Map<String, Object> settings = new HashMap<String, Object>();
settings.put("defaultSpringLength", 5.0);
settings.put("defaultSpringNodeMass", 2.0);
TunableSetter setter = cyServiceRegistrar.getService(TunableSetter.class);
Object context = layout.createLayoutContext();
setter.applyTunables(context, settings);
GOTermAnalyser2 goTermAnalyser = new GOTermAnalyser2(proteinNetwork, species);
while (it2.hasNext()) {
PhenomeExpressSubnetwork subnet = it2.next();
if (subnet.getPvalue() > this.threshold) {
it2.remove();
} else {
goTermAnalyser.calculateGOTermPValues(subnet, proteinNetwork);
String subnetworkName = NetworkUtils.getUniqueNetworkName(cyServiceRegistrar, networkName + "_" + subnet.getBestGOTerm());
subnet.setName(subnetworkName);
CySubNetwork subnetwork = NetworkUtils.createSubNetwork(((CySubNetwork) proteinNetwork.getNetwork()).getRootNetwork(), subnet.getNodeList());
subnetwork.getRow(subnetwork).set(CyNetwork.NAME, subnetworkName);
addSeedPhenotypes(subnetwork);
networkManager.addNetwork(subnetwork);
CyNetworkViewManager viewManager = cyServiceRegistrar.getService(CyNetworkViewManager.class);
CyNetworkView nv = networkViewFactory.createNetworkView(subnetwork);
viewManager.addNetworkView(nv);
cyApplicationManager.setCurrentNetworkView(nv);
for (CyNode phenoNode : phenotypesAdded) {
View<CyNode> nodeView = nv.getNodeView(phenoNode);
nodeView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
nodeView.setLockedValue(BasicVisualLexicon.NODE_FILL_COLOR, Color.BLUE);
}
for (CyEdge phenoEdge : phenoEdges) {
View<CyEdge> edgeView = nv.getEdgeView(phenoEdge);
edgeView.setLockedValue(BasicVisualLexicon.EDGE_LINE_TYPE, LineTypeVisualProperty.DOT);
edgeView.setLockedValue(BasicVisualLexicon.EDGE_PAINT, Color.BLUE);
}
networkViewList.add(nv);
Set<View<CyNode>> nodeSet = Collections.emptySet();
cyServiceRegistrar.getService(TaskManager.class).execute(layout.createTaskIterator(nv, context, nodeSet, null));
}
}
CyEventHelper cyEventHelper = cyServiceRegistrar.getService(CyEventHelper.class);
for (CyNetworkView nv : networkViewList) {
visualMappingManager.setVisualStyle(vs, nv);
vs.apply(nv);
cyEventHelper.flushPayloadEvents();
cyApplicationManager.setCurrentNetworkView(nv);
nv.updateView();
}
phenomeNetwork = null;
proteinNetwork = null;
ResultsPanel resultsPanel = (ResultsPanel) CytoPanelUtils.getCytoPanel(cyServiceRegistrar, ResultsPanel.class, CytoPanelName.EAST);
resultsPanel.newTableData(getResultsSummary(subnetworks), getParameterList());
CytoPanelUtils.showCytoPanel(cyServiceRegistrar, CytoPanelName.EAST);
}
use of org.cytoscape.view.vizmap.VisualStyle in project PhenomeScape by soulj.
the class VizStyle method createVizStyle.
public VisualStyle createVizStyle(CyServiceRegistrar cyServiceRegistrar, String geneName, String foldchangeName, double maxFC, double minFC) {
// To get references to services in CyActivator class
VisualMappingManager vmmServiceRef = cyServiceRegistrar.getService(VisualMappingManager.class);
VisualStyleFactory visualStyleFactoryServiceRef = cyServiceRegistrar.getService(VisualStyleFactory.class);
VisualMappingFunctionFactory vmfFactoryC = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
VisualMappingFunctionFactory vmfFactoryD = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=discrete)");
VisualMappingFunctionFactory vmfFactoryP = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
// To create a new VisualStyle object and set the mapping function
VisualStyle vs = visualStyleFactoryServiceRef.createVisualStyle("PhenomeScape");
// Use pass-through mapping to create the node label
PassthroughMapping nameMapping = (PassthroughMapping) vmfFactoryP.createVisualMappingFunction(geneName, String.class, BasicVisualLexicon.NODE_LABEL);
vs.addVisualMappingFunction(nameMapping);
vs.setDefaultValue(BasicVisualLexicon.NODE_SIZE, 15.0);
// RenderingEngineManager renderingEngineManager = cyServiceRegistrar.getService(RenderingEngineManager.class);
// CyNetworkViewManager viewManager = cyServiceRegistrar.getService(CyNetworkViewManager.class);
// CyNetworkViewFactory networkViewFactory = cyServiceRegistrar.getService(CyNetworkViewFactory.class);
// Set<CyNetworkView> views = viewManager.getNetworkViewSet();
// CyNetworkView networkView = views.iterator().next();
// Collection<RenderingEngine<?>> engines = renderingEngineManager.getAllRenderingEngines();
// VisualLexicon lex = engines.iterator().next().getVisualLexicon();
// VisualProperty prop = lex.lookup(CyNode.class, "NODE_LABEL_POSITION");
// Object value = prop.parseSerializableString("S,N,c,0.0,5.0"); // Put the north of the label on the southeast corner of the node
// vs.setDefaultValue(prop, value);
// Set the node size to smaller than the default
// Set node color map to attribute "FoldChange"
ContinuousMapping mapping = (ContinuousMapping) vmfFactoryC.createVisualMappingFunction(foldchangeName, Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
// Define the points
BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.GREEN, Color.WHITE);
BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.WHITE, Color.RED);
BoundaryRangeValues<Paint> brv3 = new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED);
// Set the points
// TODO add the point size and text postition
mapping.addPoint(minFC, brv1);
mapping.addPoint(0.0, brv2);
mapping.addPoint(maxFC, brv3);
// add the mapping to visual style
vs.addVisualMappingFunction(mapping);
// Add the new style to the VisualMappingManager
vmmServiceRef.addVisualStyle(vs);
return (vs);
}
Aggregations