Author: scooter
Date: 2010-01-15 18:01:36 -0800 (Fri, 15 Jan 2010)
New Revision: 18949
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/AbstractClusterAlgorithm.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/DistanceMatrix.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/EdgeAttributeHandler.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
Log:
Continued work on splitting out edge attribute stuff
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/AbstractClusterAlgorithm.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/AbstractClusterAlgorithm.java
2010-01-16 00:46:15 UTC (rev 18948)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/AbstractClusterAlgorithm.java
2010-01-16 02:01:36 UTC (rev 18949)
@@ -74,7 +74,7 @@
}
protected void advancedProperties() {
- clusterProperties.add(new Tunable("advancedGroup", "Advanced",
+ clusterProperties.add(new Tunable("advancedGroup", "Advanced
Settings",
Tunable.GROUP, new Integer(2),
new Boolean(true), null,
Tunable.COLLAPSABLE));
clusterProperties.add(new Tunable("clusterAttrName", "Cluster
Attribute",
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/DistanceMatrix.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/DistanceMatrix.java
2010-01-16 00:46:15 UTC (rev 18948)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/DistanceMatrix.java
2010-01-16 02:01:36 UTC (rev 18949)
@@ -1,7 +1,9 @@
package clusterMaker.algorithms;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
// Cytoscape imports
import cytoscape.CyEdge;
@@ -23,6 +25,8 @@
private double maxAttribute = Double.MIN_VALUE;
private double edgeCutOff = 0.0;
private boolean unDirectedEdges = false;
+ private boolean distanceValues = false;
+ private boolean logValues = false;
private List<CyNode> nodes = null;
private List<CyEdge> edges = null;
private DoubleMatrix2D matrix = null;
@@ -32,6 +36,8 @@
public DistanceMatrix(String edgeAttributeName, boolean selectedOnly,
boolean distanceValues,
boolean takeNegLOG) {
this.edgeAttributeName = edgeAttributeName;
+ this.distanceValues = distanceValues;
+ this.logValues = takeNegLOG;
CyNetwork network = Cytoscape.getCurrentNetwork();
String networkID = network.getIdentifier();
@@ -79,25 +85,11 @@
double edgeWeight = edgeWeights[edgeIndex];
if (edgeWeight == Double.MIN_VALUE) continue;
- if (distanceValues) {
- if (edgeWeight != 0.0)
- edgeWeight = 1/edgeWeight;
- else {
- edgeWeight = Double.MIN_VALUE;
+ edgeWeight = scaleValue(edgeWeight);
+
+ if (edgeWeight == Double.MIN_VALUE)
edgeCase.add(edgeIndex);
- }
- }
- if (takeNegLOG) {
- if (minAttribute < 0.0)
- edgeWeight += Math.abs(minAttribute);
-
- if(edgeWeight != 0.0 && edgeWeight !=
Double.MAX_VALUE)
- edgeWeight = -Math.log10(edgeWeight);
- else
- edgeWeight = 500; // Assume 1e-500 as a
reasonble upper bound
- }
-
edgeWeights[edgeIndex] = edgeWeight;
if (edgeWeight != Double.MIN_VALUE) {
minWeight = Math.min(minWeight, edgeWeight);
@@ -115,7 +107,58 @@
return edgeWeights;
}
+ public double getEdgeValueFromMatrix(int row, int column) {
+ if (matrix == null)
+ getDistanceMatrix();
+ return matrix.get(row, column);
+ }
+
+ public double scaleValue(double value) {
+ if (distanceValues) {
+ if (value != 0.0)
+ value = 1/value;
+ else {
+ value = Double.MIN_VALUE;
+ }
+ }
+
+ if (logValues) {
+ if (minAttribute < 0.0)
+ value += Math.abs(minAttribute);
+
+ if(value != 0.0 && value != Double.MAX_VALUE)
+ value = -Math.log10(value);
+ else
+ value = 500; // Assume 1e-500 as a
reasonble upper bound
+ }
+ return value;
+ }
+
+ public boolean hasDistanceValues() { return this.distanceValues; }
+ public boolean hasLogValues() { return this.logValues; }
+
+ public double getNormalizedValue(double value) {
+ double span = maxWeight - minWeight;
+ return ((value-minWeight)/span);
+ }
+
+ public void normalizeMatrix(double factor) {
+ if (matrix == null)
+ getDistanceMatrix();
+
+ matrix.forEachNonZero(new Normalize(minWeight, maxWeight,
factor));
+ }
+
+ public Map<Integer, List<CyNode>> findConnectedComponents() {
+ if (matrix == null)
+ getDistanceMatrix();
+
+ Map<Integer, List<CyNode>> cmap = new HashMap();
+ matrix.forEachNonZero(new FindComponents(cmap));
+ return cmap;
+ }
+
public DoubleMatrix2D getDistanceMatrix(Double edgeCutOff, boolean
undirectedEdges) {
setEdgeCutOff(edgeCutOff);
setUndirectedEdges(undirectedEdges);
@@ -211,4 +254,80 @@
return value;
}
}
+
+ /**
+ * Normalize normalizes a cell in the matrix
+ */
+ private class Normalize implements IntIntDoubleFunction {
+ private double maxValue;
+ private double minValue;
+ private double span;
+ private double factor;
+
+ public Normalize(double minValue, double maxValue, double
factor) {
+ this.maxValue = maxValue;
+ this.minValue = minValue;
+ this.factor = factor;
+ span = maxValue - minValue;
+ }
+
+ public double apply(int row, int column, double value) {
+ return ((value-minWeight)/span)*factor;
+ }
+ }
+
+ /**
+ * Find the connected components in a matrix
+ */
+ private class FindComponents implements IntIntDoubleFunction {
+ Map<CyNode,Integer> nodeToCluster;
+ Map<Integer, List<CyNode>> clusterMap;
+
+ public FindComponents(Map<Integer, List<CyNode>> cMap) {
+ clusterMap = cMap;
+ nodeToCluster = new HashMap();
+ }
+
+ public double apply(int row, int column, double value) {
+ CyNode node1 = nodes.get(row);
+ CyNode node2 = nodes.get(column);
+ if (nodeToCluster.containsKey(node1)) {
+ if(!nodeToCluster.containsKey(node2))
+ addNodeToCluster(nodeToCluster.get(node1), node2);
+ else
+ combineClusters(nodeToCluster.get(node1), nodeToCluster.get(node2));
+ } else {
+ if (nodeToCluster.containsKey(node2))
+ addNodeToCluster(nodeToCluster.get(node2), node1);
+ else
+ createCluster(node1, node2);
+ }
+ return value;
+ }
+
+ private void addNodeToCluster(Integer cluster, CyNode node) {
+ List<CyNode> nodeList = clusterMap.get(cluster);
+ nodeList.add(node);
+ nodeToCluster.put(node, cluster);
+ }
+
+ private void createCluster(CyNode node1, CyNode node2) {
+ List<CyNode> nodeList = new ArrayList();
+ int clusterNumber = clusterMap.keySet().size();
+ clusterMap.put(clusterNumber, nodeList);
+ addNodeToCluster(clusterNumber, node1);
+ addNodeToCluster(clusterNumber, node2);
+ }
+
+ private void combineClusters(Integer cluster1, Integer cluster2) {
+ List<CyNode> list1 = clusterMap.get(cluster1);
+ List<CyNode> list2 = clusterMap.get(cluster2);
+ clusterMap.remove(cluster2);
+ for (CyNode node: list2) {
+ nodeToCluster.put(node, cluster1);
+ }
+ list1.addAll(list2);
+ }
+ }
+
}
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/EdgeAttributeHandler.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/EdgeAttributeHandler.java
2010-01-16 00:46:15 UTC (rev 18948)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/EdgeAttributeHandler.java
2010-01-16 02:01:36 UTC (rev 18949)
@@ -63,6 +63,7 @@
private boolean takeNegLOG = false;
private boolean selectedOnly = false;
private boolean distanceValues = false;
+ private boolean supportAdjustments = false;
private Double edgeCutOff = null;
private String[] attributeArray = new String[1];
@@ -70,29 +71,17 @@
private HistogramDialog histo = null;
- public EdgeAttributeHandler(ClusterProperties clusterProperties) {
+ public EdgeAttributeHandler(ClusterProperties clusterProperties,
boolean supportAdjustments) {
this.clusterProperties = clusterProperties;
+ this.supportAdjustments = supportAdjustments;
initializeTunables(clusterProperties);
}
public void initializeTunables(ClusterProperties clusterProperties) {
- // Whether or not to create a new network from the results
- Tunable selTune = new Tunable("selectedOnly","Cluster only
selected nodes",
- Tunable.BOOLEAN, new
Boolean(false));
- clusterProperties.add(selTune);
-
- //Whether or not to assume the edges are undirected
- clusterProperties.add(new Tunable("undirectedEdges","Assume
edges are undirected",
- Tunable.BOOLEAN, new
Boolean(true)));
-
- // Whether or not to adjust loops before clustering
- clusterProperties.add(new Tunable("adjustLoops","Adjust loops
before clustering",
- Tunable.BOOLEAN, new
Boolean(true)));
-
clusterProperties.add(new Tunable("attributeListGroup",
"Source for array data",
- Tunable.GROUP, new
Integer(5)));
+ Tunable.GROUP, new
Integer(6)));
// The attribute to use to get the weights
attributeArray = getAllAttributes();
@@ -103,6 +92,11 @@
clusterProperties.add(attrTunable);
+ // Whether or not to create a new network from the results
+ Tunable selTune = new Tunable("selectedOnly","Cluster only
selected nodes",
+ Tunable.BOOLEAN, new
Boolean(false));
+ clusterProperties.add(selTune);
+
//Whether the attribute values are weights or distances
Tunable dValue = new Tunable("distanceValues","Attributes
represent distance (use 1/value)",
Tunable.BOOLEAN, new Boolean(false));
@@ -131,6 +125,20 @@
clusterProperties.add(new Tunable("edgeHistogram",
"Set Edge Cutoff Using
Histogram",
Tunable.BUTTON, "Edge
Histogram", this, null, Tunable.IMMUTABLE));
+
+ if (supportAdjustments) {
+ clusterProperties.add(new Tunable("options_panel1",
+ "Array data
adjustments",
+ Tunable.GROUP, new
Integer(2)));
+
+ //Whether or not to assume the edges are undirected
+ clusterProperties.add(new
Tunable("undirectedEdges","Assume edges are undirected",
+ Tunable.BOOLEAN, new
Boolean(true)));
+
+ // Whether or not to adjust loops before clustering
+ clusterProperties.add(new Tunable("adjustLoops","Adjust
loops before clustering",
+ Tunable.BOOLEAN, new
Boolean(true)));
+ }
}
public void updateSettings(boolean force) {
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2010-01-16 00:46:15 UTC (rev 18948)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2010-01-16 02:01:36 UTC (rev 18949)
@@ -129,12 +129,8 @@
Tunable.DOUBLE, new
Double(.001),
(Object)null, (Object)null,
0));
- clusterProperties.add(new Tunable("options_panel1",
- "Data value options",
- Tunable.GROUP, new
Integer(3)));
-
// Use the standard edge attribute handling stuff....
- edgeAttributeHandler = new
EdgeAttributeHandler(clusterProperties);
+ edgeAttributeHandler = new
EdgeAttributeHandler(clusterProperties, true);
clusterProperties.add(new Tunable("options_panel2",
"Results options",
--
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.