cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
49 stars 20 forks source link

Feature request: layout property access #30

Closed m-grimes closed 6 years ago

m-grimes commented 6 years ago

Layout property access: a request for access to selected nodes only, and to specify the data column that will be used as weight to drive the layout.

I would like the parent or gene nodes to be driving the layouts and the peptides to surround them. For this reason I set the edge weight from gene to peptide to be large. But my attempts to tweak existing layouts have not accomplished this goal. A workaround could be

selectNodes(net.cf[which(net.cf$Node.ID=="gene"), "id"], by="id") 
# The following use to work in RCytoscape. But NOT in RCy3
setLayoutProperties("force-directed", list(selected_only=TRUE) )
# But: selected_only is not a property in layout force-directed 
setLayoutProperties("kamada-kawai", list(selected_only=TRUE) )
# selected_only is not a property in layout kamada-kawai    
layouts <- getLayoutNames()
getLayoutPropertyNames("genemania-force-directed")
getLayoutPropertyNames("kamada-kawai")

Neither of these specify the quantitative edge attribute to drive the layout. This is important because I would sometimes like to use Alt.Weight instead of Weight, for example to drive negative correlation edges far compared to postitive correlation edges.

# The following are my unsuccessful tweaks
defalutgmvalues <-  data.frame(name=getLayoutPropertyNames("genemania-force-directed"), value=getLayoutPropertyValue(cy, "genemania-force-directed", getLayoutPropertyNames(cy, "genemania-force-directed")))
# Has to be manual without the ability to layout with selected_only=TRUE
# Manually: genemania force directed with weight works okay, after manually resizing
setLayoutProperties("genemania-force-directed", list(numIterations=100, defaultSpringCoefficient=0.1, defaultSpringLength=50, minNodeMass=0.001, maxNodeMass=2000, midpointEdges=250, curveSteepness=7.0e-03, isDeterministic=1, singlePartition=0, ignoreHiddenElements=1))
layoutNetwork(layout.name= "genemania-force-directed")
# Not bad, but not exacly heat I was trying to do.
defalutkkvalues <-  data.frame(name=getLayoutPropertyNames(cy, "kamada-kawai"), value=getLayoutPropertyValue(cy, "kamada-kawai", getLayoutPropertyNames(cy, "kamada-kawai")))
setLayoutProperties ("kamada-kawai", list (m_averageIterationsPerNode=50, m_nodeDistanceStrengthConstant=8000, m_nodeDistanceRestLengthConstant=400, m_disconnectedNodeDistanceSpringStrength=0.0001, m_disconnectedNodeDistanceSpringRestLength=2000, m_anticollisionSpringStrength=0, m_layoutPass=50, singlePartition=10, unweighted=1, randomize=10)) 
layoutNetwork(layout.name="kamada-kawai")
# Not happy with this.

(SessionInfo same as other issue today.)

AlexanderPico commented 6 years ago

I think you're looking for the layout commands api, where all the possible parameters for layouts are listed.

Open the swagger docs for commands: Help>Automation>CyREST Command API Then check out layouts. If you have Cytoscape launched, this link you bring you there as well: http://localhost:1234/v1/swaggerUI/swagger-ui/index.html?url=http%3A%2F%2Flocalhost%3A1234%2Fv1%2Fcommands%2Fswagger.json#!/layout/layout_force_directed

Use the swagger interface to get the parameter just you want them and then you can translate these into layoutNetwork() syntax by just including them directly, along with the layout name, e.g.,

layoutNetwork('force-directed defaultSpringCoefficient=0.0000008 defaultSpringLength=70 nodeList="selected" edgeAttribute="Alt.Weight"')

Skip the whole setLayoutProperties() step. That is only for a limited subset of parameters.

m-grimes commented 6 years ago

Thanks Alex, this is exactly what is needed! - Mark