Using the edge weight for force directed layout (CoSE) in cytoscape.js

时间:2015-10-30 21:50:36

标签: cytoscape.js

  1. I am not sure how best to utilize the edge weight (e.g. strength of interaction between two interacting proteins) while generating a force directed layout using the CoSE plugin in cytoscape.js. Could someone provide any pointers. Should it be "idealEdgeLength" or "edgeElasticity"?

  2. (EDIT) Following is a figure showing what I currently get (A) and what I am trying to achieve (B). Also below are the parameters I used for generating the layout.

Thanks, Datta.

PS: Click to view a figure showing the current (labelled "A") and expected (labelled "B") layouts. Following are layout options for "A".

    var options = {
        name: 'cose',
        // Called on `layoutready`
        ready: function () { },
        // Called on `layoutstop`
        stop: function () { },
        // Whether to animate while running the layout
        animate: true,
        // Number of iterations between consecutive screen positions update (0 -> only updated on the end)
        refresh: 20,
        // Whether to fit the network view after when done
        fit: true,
        // Padding on fit
        padding: 30,
        // Constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
        boundingBox: undefined,
        componentSpacing: 100,
        // Whether to randomize node positions on the beginning
        randomize: true,
        // Whether to use the JS console to print debug messages
        debug: false,
        // Node repulsion (non overlapping) multiplier
        nodeRepulsion: 400000,
        // Node repulsion (overlapping) multiplier
        nodeOverlap: 10,
        // Ideal edge (non nested) length
        idealEdgeLength: 10,
        // Divisor to compute edge forces
        edgeElasticity: 100,
        // Nesting factor (multiplier) to compute ideal edge length for nested edges
        nestingFactor: 5,
        // Gravity force (constant)
        gravity: 80,
        // Maximum number of iterations to perform
        numIter: 10000,
        // Initial temperature (maximum node displacement)
        initialTemp: 100,
        // Cooling factor (how the temperature is reduced between consecutive iterations
        coolingFactor: 0.95,
        // Lower temperature threshold (below this point the layout will end)
        minTemp: 1.0
    };

2 个答案:

答案 0 :(得分:2)

您可以为某些关键CoSE布局设置指定函数而不是静态数字。这些函数采用边(或节点,在某些情况下),因此您可以根据边属性定制布局。

所以你可以这样做:

      idealEdgeLength: function (edge) {
        // Default is: 10
        // Instead, base it on "weight"
        return edge.data().weight * .5
      },

      edgeElasticity: function (edge) {
        // Default is: 100
        // Instead, base it on "weight"
        return edge.data().weight * 4
      },

你将不得不尝试使用布局引擎的范围和你期望作为输入的重量范围,但这种方法应该适用于AOK。

答案 1 :(得分:0)

理想边长指定类似默认值,而弹性指定确定最终长度的力之一。通常,对于物理模拟布局,您需要尝试不同的值并评估特定图形的结果。