Author: apico
Date: 2009-04-02 20:28:04 -0700 (Thu, 02 Apr 2009)
New Revision: 16451
Added:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellTemplate.java
Modified:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/UnCrossAction.java
Log:
extra layout, scaling and uncross is now working!
Modified:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
===================================================================
---
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
2009-04-02 23:50:45 UTC (rev 16450)
+++
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
2009-04-03 03:28:04 UTC (rev 16451)
@@ -21,15 +21,13 @@
import cytoscape.layout.CyLayouts;
import cytoscape.layout.LayoutProperties;
import cytoscape.layout.Tunable;
-import ding.view.DGraphView;
-import ding.view.DingCanvas;
/**
* CellularLayoutAlgorithm will layout nodes according to a template of
cellular
* regions mapped by node attribute.
*/
public class CellAlgorithm extends AbstractLayout {
- double distanceBetweenNodes = 30.0d;
+ public double distanceBetweenNodes = 30.0d;
LayoutProperties layoutProperties = null;
/**
@@ -150,6 +148,13 @@
Cytoscape.getVisualMappingManager().setVisualStyle(
PartitionNetworkVisualStyleFactory.PartitionNetwork_VS);
+ taskMonitor.setStatus("Sizing up subcellular regions");
+ taskMonitor.setPercentCompleted(1);
+
+ // CREATE REGIONS:
+ CellTemplate.buildRegionsFromTepmlate(distanceBetweenNodes);
+
+ // LAYOUT REGIONS:
double nextX = 0.0d;
double nextY = 0.0d;
double startX = 0.0d;
@@ -157,329 +162,6 @@
int nodeCount = 0; // count nodes per region
List<NodeView> nodeViews;
- taskMonitor.setStatus("Sizing up subcellular regions");
- taskMonitor.setPercentCompleted(1);
-
- // CREATE REGIONS:
- RegionManager.clearAll();
-
- // Hard-coded templates
- String Color;
- String CenterX;
- String CenterY;
- String Width;
- String Height;
- String ZOrder;
- String Rotation;
- String cG;
- Double xG;
- Double yG;
- Double wG;
- Double hG;
- int zG;
- Double rG;
-
- Color = "999999";
- CenterX = "6254.75";
- CenterY = "1837.25";
- Width = "8670.5";
- Height = "1185.5";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region a = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "extracellular region");
-
- Color = "000000";
- CenterX = "2767.25";
- CenterY = "3877.25";
- Width = "1305.5";
- Height = "885.5";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region f = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "mitochondrion");
-
- Color = "000000";
- CenterX = "4987.25";
- CenterY = "6067.5";
- Width = "1395.5";
- Height = "735.0";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region g = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "endoplasmic reticulum");
-
- Color = "000000";
- CenterX = "6269.75";
- CenterY = "2635.25";
- Width = "8640.5";
- Height = "380.5";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region b = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "plasma membrane");
-
- Color = "000000";
- CenterX = "8479.75";
- CenterY = "5002.25";
- Width = "3620.5";
- Height = "2685.5";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region d = new Region("Oval", cG, xG, yG, wG, hG, zG, rG,
"nucleus");
-
- Color = "999999";
- CenterX = "6269.75";
- CenterY = "4747.25";
- Width = "8640.5";
- Height = "3765.5";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region c = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "cytoplasm");
-
- Color = "999999";
- CenterX = "12089.75";
- CenterY = "4020.0";
- Width = "1920.5";
- Height = "3990.0";
- ZOrder = "16384";
- Rotation = "0.0";
- cG = "#".concat(Color);
- xG = Double.parseDouble(CenterX);
- yG = Double.parseDouble(CenterY);
- wG = Double.parseDouble(Width);
- hG = Double.parseDouble(Height);
- zG = Integer.parseInt(ZOrder);
- rG = Double.parseDouble(Rotation);
- Region e = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
- "unassigned");
-
- // SIZE UP REGIONS:
- Collection<Region> allRegions = RegionManager.getAllRegions();
-
- // calculate free space in overlapped regions
- for (Region r : allRegions) {
-
- Double comX = 0.0d;
- Double comY = 0.0d;
-
- List<Region> orList = r.getOverlappingRegions();
- // does not include Line shapes
- int orListSize = orList.size();
- Double[][] xy = new Double[orListSize * 8][2];
- int i = 0;
- for (Region or : orList) {
- // define points to exclude: corners and
midpoints
- // System.out.println("Overlapping regions: " +
- // or.getAttValue());
- xy[i][0] = or.getRegionLeft();
- xy[i][1] = or.getRegionTop();
- i++;
- xy[i][0] = or.getRegionLeft();
- xy[i][1] = or.getRegionTop() +
or.getRegionHeight() / 2;
- i++;
- xy[i][0] = or.getRegionLeft();
- xy[i][1] = or.getRegionBottom();
- i++;
- xy[i][0] = or.getRegionLeft() +
or.getRegionWidth() / 2;
- xy[i][1] = or.getRegionBottom();
- i++;
- xy[i][0] = or.getRegionRight();
- xy[i][1] = or.getRegionBottom();
- i++;
- xy[i][0] = or.getRegionRight();
- xy[i][1] = or.getRegionBottom() -
or.getRegionHeight() / 2;
- i++;
- xy[i][0] = or.getRegionRight();
- xy[i][1] = or.getRegionTop();
- i++;
- xy[i][0] = or.getRegionRight() -
or.getRegionWidth() / 2;
- xy[i][1] = or.getRegionTop();
- i++;
-
- // define center of overlapped region
- // comX += or.getCenterX();
- // comY += or.getCenterY();
- }
- // if (orListSize > 1) {
- // comX = comX / orList.size();
- // comY = comY / orList.size();
- // } else {
- comX = r.getCenterX();
- comY = r.getCenterY();
- // }
- // check center against overlapping regions
- boolean skip = false;
- for (Region or : orList) {
- if (comX > or.getRegionLeft() && comX <
or.getRegionRight()
- && comY > or.getRegionTop()
- && comY < or.getRegionBottom())
{
- skip = true;
- System.out.println("Inner area
skipped!");
- }
- }
- if (skip)
- continue;
-
- // initialize with starting rectangle;
- Double freeL = r.getFreeLeft();
- Double freeR = r.getFreeRight();
- Double freeT = r.getFreeTop();
- Double freeB = r.getFreeBottom();
-
- // shrink to fit free area around center
- // adapted from ex2_1.m by E. Alpaydin, i2ml, Learning a
- // rectangle
- for (i = 0; i < orListSize * 8; i++) {
- Double x = xy[i][0];
- Double y = xy[i][1];
- if (x > freeL && x < freeR && y > freeT && y <
freeB) {
- if (x < comX)
- freeL = x;
- else if (x > comX)
- freeR = x;
- else if (y < comY)
- freeT = y;
- else if (y > comY)
- freeB = y;
- }
- }
- if (((freeR - freeL) < (distanceBetweenNodes * 2))
- || ((freeB - freeT) <
(distanceBetweenNodes * 2))) {
- continue; // skip using inner of too thin or
short
- }
- r.setFreeCenterX((freeL + freeR) / 2);
- r.setFreeCenterY((freeT + freeB) / 2);
- r.setFreeWidth(freeR - freeL);
- r.setFreeHeight(freeB - freeT);
- }
-
- // calculate the maximum scale factor among all regions
- double maxScaleFactor = Double.MIN_VALUE;
- double minPanX = Double.MAX_VALUE;
- double minPanY = Double.MAX_VALUE;
- for (Region r : allRegions) {
- // max scale
- if (r.getShape() == "Line") {
- int col = r.getNodeCount(); // columns == count
- // calculate available length
- double scaleX;
- scaleX = ((col + 1) * distanceBetweenNodes) /
r.getLineLength();
- if (scaleX > maxScaleFactor)
- maxScaleFactor = scaleX;
- } else { // Rectangle, Oval
- int col = r.getColumns();
- // System.out.println("col: " + r.getAttValue()
+ col);
- double scaleX = ((col + 1) *
distanceBetweenNodes)
- / r.getFreeWidth();
- double scaleY = ((col + 1) *
distanceBetweenNodes)
- / r.getFreeHeight();
- double scaleAreaSqrt = Math.sqrt(scaleX *
scaleY);
- // System.out.println("scaleX,Y,Area: " +
scaleX + "," + scaleY
- // + "," + scaleAreaSqrt);
- // use area to scale regions efficiently
- if (scaleAreaSqrt > maxScaleFactor)
- maxScaleFactor = scaleAreaSqrt;
- }
-
- // Allan hack!
- maxScaleFactor *= 1.1;
-
- // // min pan
- // if (r.getShape() == "Line") {
- // // don't bother
- // } else { // Rectangle, Oval
- // double x = r.getCenterX() - r.getRegionWidth() / 2;
- // double y = r.getCenterY() - r.getRegionHeight() / 2;
- // if (x < minPanX)
- // minPanX = x;
- // if (y < minPanY)
- // minPanY = y;
- // }
- }
-
- // apply max scale and min pan to all regions
- for (Region r : allRegions) {
- if (r.getShape() == "Line") {
- r.setLineLength(r.getLineLength() *
maxScaleFactor);
- r.setFreeLength(r.getFreeLength() *
maxScaleFactor);
- } else { // Rectangle, Oval
- r.setRegionWidth(r.getRegionWidth() *
maxScaleFactor);
- r.setRegionHeight(r.getRegionHeight() *
maxScaleFactor);
- r.setFreeWidth(r.getFreeWidth() *
maxScaleFactor);
- r.setFreeHeight(r.getFreeHeight() *
maxScaleFactor);
- }
-
- // r.setCenterX(r.getCenterX() - minPanX);
- // r.setCenterY(r.getCenterY() - minPanY);
-
- r.setCenterX(r.getCenterX() * maxScaleFactor);
- r.setCenterY(r.getCenterY() * maxScaleFactor);
-
- // r.setFreeCenterX(r.getFreeCenterX() - minPanX);
- // r.setFreeCenterY(r.getFreeCenterY() - minPanY);
-
- r.setFreeCenterX(r.getFreeCenterX() * maxScaleFactor);
- r.setFreeCenterY(r.getFreeCenterY() * maxScaleFactor);
- }
-
- // GRAPHICS
- DGraphView dview = (DGraphView)
Cytoscape.getCurrentNetworkView();
- DingCanvas bCanvas = dview
- .getCanvas(DGraphView.Canvas.BACKGROUND_CANVAS);
- bCanvas.add(a);
- bCanvas.add(b);
- bCanvas.add(c);
- bCanvas.add(d);
- bCanvas.add(e);
- bCanvas.add(f);
- bCanvas.add(g);
- Cytoscape.getCurrentNetworkView().fitContent();
-
- // LAYOUT REGIONS:
HashMap<NodeView, Integer> nvSeen = new HashMap<NodeView,
Integer>();
int taskNodeCount = networkView.nodeCount();
int taskCount = 0; // count all nodes in all regions to layout
@@ -487,8 +169,8 @@
for (int i = sra.length - 1; i >= 0; i--) { // count down from
// largest to smallest
Region r = sra[i];
- // System.out.println("Sorted: "+
- // sra[i].getAttValue()+"="+sra[i].getArea());
+// System.out.println("Sorted: "+
+// sra[i].getAttValue()+"="+sra[i].getArea());
// Place register nodes at region corners (for fit to
screen)
for (int j = 0; j < 4; j++) {
@@ -549,26 +231,6 @@
- Math.floor((nodeCount /
Math.floor(r.getFreeWidth()
/ distanceBetweenNodes
- 1)) - 0.3)
* distanceBetweenNodes / 2;
- // System.out.println("Region: "
- // + r.getAttValue()
- // + "("
- // + r.getNodeCount()
- // + ")"
- // + " startX,Y: "
- // + startX
- // + ","
- // + startY
- // + " X,Y,W,H: "
- // + r.getFreeCenterX()
- // + ","
- // + r.getFreeCenterY()
- // + ","
- // + r.getFreeWidth()
- // + ","
- // + r.getFreeHeight()
- // + ","
- // + ((nodeCount / Math.floor(r.getFreeWidth()
- // / distanceBetweenNodes - 1)) - 0.6));
nextX = startX;
nextY = startY;
@@ -699,10 +361,12 @@
// Uncross edges
List<NodeView> filteredNodeViews =
r.getFilteredNodeViews();
if (filteredNodeViews.size() < 30 ){
- //if more than 1 node
-// System.out.println("UNCROSSING: "+ r.getAttValue());
-// UnCrossAction.unCross(filteredNodeViews, false);
+ UnCrossAction.unCross(filteredNodeViews, false);
+ System.out.println("Uncrossed edges!");
}
+ else {
+ System.out.println("Uncross skipped:
Too many nodes in region \"" + r.getAttValue() + "\"");
+ }
r.repaint();
// transform nv list to node collection
@@ -712,7 +376,12 @@
}
// force directed, selected-only, then scale
- if (r.getAttValue() == "EXTRA-LAYOUT-OFF") {
+ if (r.getAttValue() != "plasma membrane" &&
filteredNodeViews.size() > 3) { //r.getShape() != "Line"
+
+ //TODO: There must be a better way of
deselecting all nodes!?
+ Collection allNodes =
Cytoscape.getCyNodesList();
+
Cytoscape.getCurrentNetwork().setSelectedNodeState(allNodes, false);
+
Cytoscape.getCurrentNetwork().setSelectedNodeState(regionNodes,
true);
@@ -743,21 +412,21 @@
}
double layoutHeight = south - north;
- double layoutWidth = west - east;
+ double layoutWidth = east - west;
double unitX = layoutWidth / 2;
double unitY = layoutHeight / 2;
double layoutCenterX = west + unitX;
double layoutCenterY = north + unitY;
- double scaleY = r.getFreeHeight() /
layoutHeight;
- double scaleX = r.getFreeWidth() / layoutWidth;
+ double regionUnitX = r.getFreeWidth() /2;
+ double regionUnitY = r.getFreeHeight() /2;
for (NodeView nv : filteredNodeViews) {
- double nodeXunits = (nv.getXPosition()
- layoutCenterX)
- / unitX;
- double nodeYunits = (nv.getYPosition()
- layoutCenterY)
- / unitY;
+ double nodeXunits = (nv.getXPosition()
- layoutCenterX);
+ double nodeYunits = (nv.getYPosition()
- layoutCenterY);
+ double scaleX = nodeXunits / unitX;
+ double scaleY = nodeYunits / unitY;
- nv.setOffset((nodeXunits * scaleX),
(nodeYunits * scaleY));
+ nv.setOffset(r.getFreeCenterX() +
regionUnitX * scaleX, r.getFreeCenterY() + regionUnitY * scaleY);
}
// cleanup
@@ -771,8 +440,8 @@
List<NodeView> nvToCheck = new
ArrayList<NodeView>();
List<NodeView> nvToMove = new
ArrayList<NodeView>();
for (Region or : r.getRegionsOverlapped()) {
- nvToCheck.addAll(or.getNodeViews());
- nvToCheck.removeAll(r.getNodeViews());
+
nvToCheck.addAll(or.getFilteredNodeViews());
+
nvToCheck.removeAll(r.getFilteredNodeViews());
// returns node views that are within
the bounds of this
// region
@@ -790,29 +459,31 @@
List<Double> pastW = new
ArrayList<Double>();
for (NodeView nv : nvToMove) {
-
+
double nvX = nv.getXPosition();
double nvY = nv.getYPosition();
// distance between node and
boundary around all
// regions
- double farNorth = nvY -
r.getRegionTop();
- double farSouth =
r.getRegionBottom() - nvY;
- double farWest = nvX -
r.getRegionLeft();
- double farEast =
r.getRegionRight() - nvX;
+ double bufferX =
MFNodeAppearanceCalculator.FEATURE_NODE_WIDTH;
+ double bufferY =
MFNodeAppearanceCalculator.FEATURE_NODE_HEIGHT;
+ double farNorth = nvY -
(r.getRegionTop() - bufferY);
+ double farSouth =
(r.getRegionBottom() + bufferY) - nvY;
+ double farWest = nvX -
(r.getRegionLeft() - bufferX);
+ double farEast =
(r.getRegionRight() + bufferX) - nvX;
// rule out directions where
there is not enough
// room in overlapped region
- if (!((r.getRegionTop() -
or.getRegionTop()) > distanceBetweenNodes)) {
+ if (!(((r.getRegionTop() -
bufferY) - or.getFreeTop()) > bufferY)) {
farNorth =
Double.MAX_VALUE;
}
- if (!((r.getRegionLeft() -
or.getRegionLeft()) > distanceBetweenNodes)) {
+ if (!(((r.getRegionLeft() -
bufferX) - or.getFreeLeft()) > bufferX)) {
farWest =
Double.MAX_VALUE;
}
- if (!((or.getRegionBottom() -
r.getRegionBottom()) > distanceBetweenNodes)) {
+ if (!((or.getFreeBottom() -
(r.getRegionBottom() + bufferY)) > bufferY)) {
farSouth =
Double.MAX_VALUE;
}
- if (!((or.getRegionRight() -
r.getRegionRight()) > distanceBetweenNodes)) {
+ if (!((or.getFreeRight() -
(r.getRegionRight() + bufferX)) > bufferX)) {
farEast =
Double.MAX_VALUE;
}
@@ -848,7 +519,7 @@
}
nv
.setXPosition(nvX
-
+ (farWest + countW
+
- (farWest + countW
* distanceBetweenNodes
/ 2));
pastW.add(nvY);
@@ -863,7 +534,7 @@
}
}
nv.setXPosition(nvX
-
- (farEast + countE
+
+ (farEast + countE
* distanceBetweenNodes / 2));
pastE.add(nvY);
} else {
@@ -876,7 +547,7 @@
}
}
nv.setXPosition(nvX
-
+ (farWest + countW
+
- (farWest + countW
* distanceBetweenNodes / 2));
pastW.add(nvY);
}
@@ -905,7 +576,7 @@
}
}
nv.setXPosition(nvX
-
+ (farWest + countW
+
- (farWest + countW
* distanceBetweenNodes / 2));
pastW.add(nvY);
}
@@ -918,7 +589,7 @@
}
}
nv.setXPosition(nvX
- -
(farEast + countE * distanceBetweenNodes
+ +
(farEast + countE * distanceBetweenNodes
/ 2));
pastE.add(nvY);
} else {
@@ -930,7 +601,7 @@
}
}
nv.setXPosition(nvX
- +
(farWest + countW * distanceBetweenNodes
+ -
(farWest + countW * distanceBetweenNodes
/ 2));
pastW.add(nvY);
}
Added:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellTemplate.java
===================================================================
---
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellTemplate.java
2009-04-02 23:50:45 UTC (rev 16450)
+++
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellTemplate.java
2009-04-03 03:28:04 UTC (rev 16451)
@@ -0,0 +1,334 @@
+package org.genmapp.golayout;
+
+import java.util.Collection;
+import java.util.List;
+
+import cytoscape.Cytoscape;
+import cytoscape.layout.LayoutProperties;
+import cytoscape.layout.Tunable;
+import ding.view.DGraphView;
+import ding.view.DingCanvas;
+
+public class CellTemplate {
+
+ public static void buildRegionsFromTepmlate(double dbn) {
+
+ double distanceBetweenNodes = dbn;
+
+ RegionManager.clearAll();
+
+ // Hard-coded templates
+ String Color;
+ String CenterX;
+ String CenterY;
+ String Width;
+ String Height;
+ String ZOrder;
+ String Rotation;
+ String cG;
+ Double xG;
+ Double yG;
+ Double wG;
+ Double hG;
+ int zG;
+ Double rG;
+
+ Color = "999999";
+ CenterX = "6254.75";
+ CenterY = "1837.25";
+ Width = "8670.5";
+ Height = "1185.5";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region a = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "extracellular region");
+
+ Color = "000000";
+ CenterX = "2767.25";
+ CenterY = "3877.25";
+ Width = "1305.5";
+ Height = "885.5";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region f = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "mitochondrion");
+
+ Color = "000000";
+ CenterX = "4987.25";
+ CenterY = "6067.5";
+ Width = "1395.5";
+ Height = "735.0";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region g = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "endoplasmic reticulum");
+
+ Color = "000000";
+ CenterX = "6269.75";
+ CenterY = "2635.25";
+ Width = "8640.5";
+ Height = "380.5";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region b = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "plasma membrane"); //Should be "Line"
+
+ Color = "000000";
+ CenterX = "8479.75";
+ CenterY = "5002.25";
+ Width = "3620.5";
+ Height = "2685.5";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region d = new Region("Oval", cG, xG, yG, wG, hG, zG, rG,
"nucleus");
+
+ Color = "999999";
+ CenterX = "6269.75";
+ CenterY = "4747.25";
+ Width = "8640.5";
+ Height = "3765.5";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region c = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "cytoplasm");
+
+ Color = "999999";
+ CenterX = "12089.75";
+ CenterY = "4020.0";
+ Width = "1920.5";
+ Height = "3990.0";
+ ZOrder = "16384";
+ Rotation = "0.0";
+ cG = "#".concat(Color);
+ xG = Double.parseDouble(CenterX);
+ yG = Double.parseDouble(CenterY);
+ wG = Double.parseDouble(Width);
+ hG = Double.parseDouble(Height);
+ zG = Integer.parseInt(ZOrder);
+ rG = Double.parseDouble(Rotation);
+ Region e = new Region("Rectangle", cG, xG, yG, wG, hG, zG, rG,
+ "unassigned");
+
+ // SIZE UP REGIONS:
+ Collection<Region> allRegions = RegionManager.getAllRegions();
+
+ // calculate free space in overlapped regions
+ for (Region r : allRegions) {
+
+ Double comX = 0.0d;
+ Double comY = 0.0d;
+
+ List<Region> orList = r.getOverlappingRegions();
+ // does not include Line shapes
+ int orListSize = orList.size();
+ Double[][] xy = new Double[orListSize * 8][2];
+ int i = 0;
+ for (Region or : orList) {
+ // define points to exclude: corners and
midpoints
+ xy[i][0] = or.getRegionLeft();
+ xy[i][1] = or.getRegionTop();
+ i++;
+ xy[i][0] = or.getRegionLeft();
+ xy[i][1] = or.getRegionTop() +
or.getRegionHeight() / 2;
+ i++;
+ xy[i][0] = or.getRegionLeft();
+ xy[i][1] = or.getRegionBottom();
+ i++;
+ xy[i][0] = or.getRegionLeft() +
or.getRegionWidth() / 2;
+ xy[i][1] = or.getRegionBottom();
+ i++;
+ xy[i][0] = or.getRegionRight();
+ xy[i][1] = or.getRegionBottom();
+ i++;
+ xy[i][0] = or.getRegionRight();
+ xy[i][1] = or.getRegionBottom() -
or.getRegionHeight() / 2;
+ i++;
+ xy[i][0] = or.getRegionRight();
+ xy[i][1] = or.getRegionTop();
+ i++;
+ xy[i][0] = or.getRegionRight() -
or.getRegionWidth() / 2;
+ xy[i][1] = or.getRegionTop();
+ i++;
+
+ // define center of overlapped region
+ // comX += or.getCenterX();
+ // comY += or.getCenterY();
+ }
+ // if (orListSize > 1) {
+ // comX = comX / orList.size();
+ // comY = comY / orList.size();
+ // } else {
+ comX = r.getCenterX();
+ comY = r.getCenterY();
+ // }
+ // check center against overlapping regions
+ boolean skip = false;
+ for (Region or : orList) {
+ if (comX > or.getRegionLeft() && comX <
or.getRegionRight()
+ && comY > or.getRegionTop()
+ && comY < or.getRegionBottom())
{
+ skip = true;
+ System.out.println("Inner area
skipped!");
+ }
+ }
+ if (skip)
+ continue;
+
+ // initialize with starting rectangle;
+ Double freeL = r.getFreeLeft();
+ Double freeR = r.getFreeRight();
+ Double freeT = r.getFreeTop();
+ Double freeB = r.getFreeBottom();
+
+ // shrink to fit free area around center
+ // adapted from ex2_1.m by E. Alpaydin, i2ml, Learning a
+ // rectangle
+ for (i = 0; i < orListSize * 8; i++) {
+ Double x = xy[i][0];
+ Double y = xy[i][1];
+ if (x > freeL && x < freeR && y > freeT && y <
freeB) {
+ if (x < comX)
+ freeL = x;
+ else if (x > comX)
+ freeR = x;
+ else if (y < comY)
+ freeT = y;
+ else if (y > comY)
+ freeB = y;
+ }
+ }
+ if (((freeR - freeL) < (distanceBetweenNodes * 2))
+ || ((freeB - freeT) <
(distanceBetweenNodes * 2))) {
+ continue; // skip using inner of too thin or
short
+ }
+// r.setFreeCenterX((freeL + freeR) / 2);
+// r.setFreeCenterY((freeT + freeB) / 2);
+// r.setFreeWidth(freeR - freeL);
+// r.setFreeHeight(freeB - freeT);
+ }
+
+ // calculate the maximum scale factor among all regions
+ double maxScaleFactor = Double.MIN_VALUE;
+ double minPanX = Double.MAX_VALUE;
+ double minPanY = Double.MAX_VALUE;
+ for (Region r : allRegions) {
+ // max scale
+ if (r.getShape() == "Line") {
+ int col = r.getNodeCount(); // columns == count
+ // calculate available length
+ double scaleX;
+ scaleX = ((col + 1) * distanceBetweenNodes) /
r.getLineLength();
+ if (scaleX > maxScaleFactor)
+ maxScaleFactor = scaleX;
+ } else { // Rectangle, Oval
+ int col = r.getColumns();
+ // System.out.println("col: " + r.getAttValue()
+ col);
+ double scaleX = ((col + 1) *
distanceBetweenNodes)
+ / r.getFreeWidth();
+ double scaleY = ((col + 1) *
distanceBetweenNodes)
+ / r.getFreeHeight();
+ double scaleAreaSqrt = Math.sqrt(scaleX *
scaleY);
+ // System.out.println("scaleX,Y,Area: " +
scaleX + "," + scaleY
+ // + "," + scaleAreaSqrt);
+ // use area to scale regions efficiently
+ if (scaleAreaSqrt > maxScaleFactor)
+ maxScaleFactor = scaleAreaSqrt;
+ }
+
+ // Allan hack!
+ maxScaleFactor *= 1.1;
+
+ // // min pan
+ // if (r.getShape() == "Line") {
+ // // don't bother
+ // } else { // Rectangle, Oval
+ // double x = r.getCenterX() - r.getRegionWidth() / 2;
+ // double y = r.getCenterY() - r.getRegionHeight() / 2;
+ // if (x < minPanX)
+ // minPanX = x;
+ // if (y < minPanY)
+ // minPanY = y;
+ // }
+ }
+
+ // apply max scale and min pan to all regions
+ for (Region r : allRegions) {
+ if (r.getShape() == "Line") {
+ r.setLineLength(r.getLineLength() *
maxScaleFactor);
+ r.setFreeLength(r.getFreeLength() *
maxScaleFactor);
+ } else { // Rectangle, Oval
+ r.setRegionWidth(r.getRegionWidth() *
maxScaleFactor);
+ r.setRegionHeight(r.getRegionHeight() *
maxScaleFactor);
+ r.setFreeWidth(r.getFreeWidth() *
maxScaleFactor);
+ r.setFreeHeight(r.getFreeHeight() *
maxScaleFactor);
+ }
+
+ // r.setCenterX(r.getCenterX() - minPanX);
+ // r.setCenterY(r.getCenterY() - minPanY);
+
+ r.setCenterX(r.getCenterX() * maxScaleFactor);
+ r.setCenterY(r.getCenterY() * maxScaleFactor);
+
+ // r.setFreeCenterX(r.getFreeCenterX() - minPanX);
+ // r.setFreeCenterY(r.getFreeCenterY() - minPanY);
+
+ r.setFreeCenterX(r.getFreeCenterX() * maxScaleFactor);
+ r.setFreeCenterY(r.getFreeCenterY() * maxScaleFactor);
+ }
+
+ // GRAPHICS
+ DGraphView dview = (DGraphView)
Cytoscape.getCurrentNetworkView();
+ DingCanvas bCanvas = dview
+ .getCanvas(DGraphView.Canvas.BACKGROUND_CANVAS);
+ bCanvas.add(a);
+ bCanvas.add(b);
+ bCanvas.add(c);
+ bCanvas.add(d);
+ bCanvas.add(e);
+ bCanvas.add(f);
+ bCanvas.add(g);
+ Cytoscape.getCurrentNetworkView().fitContent();
+ }
+}
Modified:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
===================================================================
---
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
2009-04-02 23:50:45 UTC (rev 16450)
+++
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
2009-04-03 03:28:04 UTC (rev 16451)
@@ -108,15 +108,19 @@
// additional parameters
this.attName = "annotation.GO CELLULAR_COMPONENT"; //
hard-coded, for
-
// now
+ // now
this.nodeViews = populateNodeViews();
this.nodeCount = this.nodeViews.size();
this.columns = (int) Math.sqrt(this.nodeCount);
this.freeCenterX = centerX;
this.freeCenterY = centerY;
- this.freeWidth = width;
- this.freeHeight = height;
+ // subtract proportional width and height
+ // for buffer around borders and region label
+ this.freeWidth = width - 10
+ * MFNodeAppearanceCalculator.FEATURE_NODE_WIDTH;
+ this.freeHeight = height - 20
+ *
MFNodeAppearanceCalculator.FEATURE_NODE_HEIGHT;
// define free area inside of ovals
if (this.shape == "Oval") {
@@ -351,36 +355,36 @@
g2d.draw(s);
// region label
-// int xLabelOffset = 5;
-// int yLabelOffset = 15;
+ // int xLabelOffset = 5;
+ // int yLabelOffset = 15;
// //TODO: debugging free region
-// Rectangle fb = relativeToBounds(
-//
viewportTransform(getFreeVRectangle())).getBounds();
-// int fsw = 1;
-// int fx = fb.x;
-// int fy = fb.y;
-// int fw = fb.width - fsw - 1;
-// int fh = fb.height - fsw - 1;
-// int fcx = fx + fw / 2;
-// int fcy = fy + fh / 2;
-//
-// java.awt.Shape fs = null;
-//
-// fs = ShapeRegistry.getShape(this.shape, fx, fy, fw, fh);
-//
-// AffineTransform ft = new AffineTransform();
-// ft.rotate(this.rotation, fcx, fcy);
-// fs = ft.createTransformedShape(fs);
-//
-// g2d.setColor(Color.gray);
-// Font font = new Font("Arial", Font.PLAIN, 10);
-// g2d.setFont(font);
-//
-// g2d.draw(fs);
+ // Rectangle fb = relativeToBounds(
+ // viewportTransform(getFreeVRectangle())).getBounds();
+ // int fsw = 1;
+ // int fx = fb.x;
+ // int fy = fb.y;
+ // int fw = fb.width - fsw - 1;
+ // int fh = fb.height - fsw - 1;
+ // int fcx = fx + fw / 2;
+ // int fcy = fy + fh / 2;
+ //
+ // java.awt.Shape fs = null;
+ //
+ // fs = ShapeRegistry.getShape(this.shape, fx, fy, fw,
fh);
+ //
+ // AffineTransform ft = new AffineTransform();
+ // ft.rotate(this.rotation, fcx, fcy);
+ // fs = ft.createTransformedShape(fs);
+ //
+ // g2d.setColor(Color.gray);
+ // Font font = new Font("Arial", Font.PLAIN, 10);
+ // g2d.setFont(font);
+ //
+ // g2d.draw(fs);
-// g2d.setColor(Color.DARK_GRAY);
-// g2d.setStroke(new BasicStroke());
-// g2d.drawString(this.attValue, xLabelOffset,
yLabelOffset);
+ // g2d.setColor(Color.DARK_GRAY);
+ // g2d.setStroke(new BasicStroke());
+ // g2d.drawString(this.attValue, xLabelOffset,
yLabelOffset);
}
}
@@ -396,6 +400,13 @@
List<NodeView> boundedNodeViews = new ArrayList<NodeView>();
double currentX;
double currentY;
+ double bufferX = MFNodeAppearanceCalculator.FEATURE_NODE_WIDTH;
+ double bufferY = MFNodeAppearanceCalculator.FEATURE_NODE_HEIGHT;
+// if (r.shape == "Oval") { // account for arcs beyond defining
rectangle
+// bufferX += r.width;
+// bufferY += r.height;
+// }
+
// first calculate the min/max x and y for the list of
*relevant*
// nodeviews
Iterator<NodeView> it = nodeViews.iterator();
@@ -403,9 +414,10 @@
NodeView nv = it.next();
currentX = nv.getXPosition();
currentY = nv.getYPosition();
- if (currentX > r.getRegionLeft() && currentX <
r.getRegionRight()
- && currentY > r.getRegionTop()
- && currentY < r.getRegionBottom()) {
+ if (currentX > (r.getRegionLeft() - bufferX)
+ && currentX < (r.getRegionRight() +
bufferX)
+ && currentY > (r.getRegionTop() -
bufferY)
+ && currentY < (r.getRegionBottom() +
bufferY)) {
boundedNodeViews.add(nv);
}
}
@@ -424,16 +436,18 @@
* @param nodeViews
* the nodeViews to set
*/
- public void setNodeViews(List<NodeView> nodeViews) {
- this.nodeViews = nodeViews;
- }
-
- public void removeFilteredNodeView(NodeView nv){
+// public void setNodeViews(List<NodeView> nodeViews) {
+// this.nodeViews = nodeViews;
+// }
+
+ public void removeFilteredNodeView(NodeView nv) {
this.filteredNodeViews.remove(nv);
}
- public void addFilteredNodeView(NodeView nv){
+
+ public void addFilteredNodeView(NodeView nv) {
this.filteredNodeViews.add(nv);
}
+
public List<NodeView> getFilteredNodeViews() {
return filteredNodeViews;
}
Modified:
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/UnCrossAction.java
===================================================================
---
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/UnCrossAction.java
2009-04-02 23:50:45 UTC (rev 16450)
+++
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/UnCrossAction.java
2009-04-03 03:28:04 UTC (rev 16451)
@@ -115,7 +115,7 @@
* for performance reasons, set threshold so that this doesn't execute
with
* large networks
*/
- public static final int UNCROSS_THRESHOLD = 100;
+ public static final int UNCROSS_THRESHOLD = 200;
/**
* iterations counter
@@ -157,10 +157,11 @@
public static void unCross(List<NodeView> nodeViews, boolean
calledByEndUser) {
// warn if no nodeViewss are selected
- if (nodeViews.size() <= 0) {
+ if (nodeViews.size() <= 1) {
// JOptionPane
//
.showMessageDialog(Cytoscape.getDesktop(),
// "You must first select
some nodes in order to minimize edge crossings.");
+ System.out.println("Uncross skipped! Too few nodes (one
or fewer)");
return;
} else if (Cytoscape.getCurrentNetwork().getNodeCount() >
UNCROSS_THRESHOLD) {
@@ -171,15 +172,18 @@
// "Sorry, this
network is too large to run incremental edge cross miminization."
//
+ "\nYou should one of the automated layout tools instead.");
// }
+ System.out.println("Uncross skipped! Too many nodes in
network (over " + UNCROSS_THRESHOLD + ")");
return;
}
else {
+
UnCrossAction uncross = new UnCrossAction();
Task unCrossTask = uncross.new UnCrossTask(nodeViews,
calledByEndUser);
+
JTaskConfig jTaskConfig = new JTaskConfig();
jTaskConfig.setOwner(Cytoscape.getDesktop());
jTaskConfig.displayCloseButton(true);
@@ -189,7 +193,7 @@
jTaskConfig.setAutoDispose(true);
// Execute Task in New Thread; pops open JTask Dialog
Box.
- TaskManager.executeTask(unCrossTask, jTaskConfig);
+ //TaskManager.executeTask(unCrossTask, jTaskConfig);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---