Cytoscape Desktop: Order of source nodes if group attributes layout is applied by target node attribute - cytoscape

I am using the Group Attributes Layout on a target node column in Cytoscape Desktop. All target nodes are grouped and sorted as expected. The source nodes are also grouped in a circle which is desired, I just cannot figure out how to get those (source nodes) in a custom order.
Thanks in advance!
Chris

It's pretty easy -- just start by selecting your target nodes, then doing the layout using "Selected Only". That will only layout your target nodes. Then repeat the process for your source nodes.
-- scooter

Related

Cytoscape3 Desktop: remove labels for traget nodes only

I'd like to remove the labels for target nodes only (i.e. keep the labels for the source nodes). Style>Edit>Remove Mappings from selected Visual Properties removes the labels for both, target and source nodes.
Thanks
Unfortunately, there is no way to do that directly :-( You could create a column and copy over labels if that node is a source node and then point your mapping to that column, but that could be a fairly big hassle.
-- scooter

How do I create a link between nodes based on a subnode link in Neo4j

I have a database with two clusters. There is a hard link between the nodes near the bottom. But when you select just the top nodes, I would like to see that the root nodes are connected somehere.
So the links at the bottom are connected but when you select only the top nodes, I would like to show that at some point (any point) these are connected.
1) I can find the link to between groups by matching a child connection where the target has different groupid (group id is on every node)
2) I think I then have to run up the tree and find the root node. I can't seem to make that work. I can see it, but can't come up with the cypher to do it. It would be a node with no parents.
3) then link (with a different link ID :peerLink)) from group a to group b. Thats easy enough to do once I have 2
I am having a beast putting them together. I did create a separate field for a list of peerLinks so they didnt confuse my parent logic. So again, the goal is to produce the dashed line based on subnode connection.
I DON'T Need to show it at the sublevels. They will appear in the UI as an offpage connector
Anyone done this before ?
Can you please try this?
MATCH (A_leaf)->(B_leaf)
WHERE A_leaf.GroupID <> B_leaf.GroupID
WITH A_leaf
MATCH (A_leaf)<-[*]-(A_root)
WHERE NOT (A_root)<-()
WITH B_leaf
MATCH (B_leaf)<-[*]-(B_root)
WHERE B_leaf.GroupID == B_root.GroupID
AND NOT (B_root)<-()
CREATE (A_root)-[:relName]->(B_root)

Select all nodes that are 1 or 3 nodes away from a gene of interest

I am working with a network and as a filter I would like to keep only genes that are related to a specific gene.
How can I select only those genes that are 2 or 3 nodes maximum far from a single node?
Ty
If you select the node in the Cytoscape network view, then hit Control-6 (or Apple-6 on a Mac), you'll select all the first neighbors of that node. Do it again to select all of the first neighbors of those nodes and you'll have selected all of the first and second neighbors of the original node. The same thing can be done by using Cytoscape automation (commands, RCy3, or py2cytoscape), and by the menu using Select->Nodes->First neighbors of selected nodes->Undirected.
-- scooter

Change node color based on properties - neo4j

I want to change the color of my nodes based on their properties:
Say I have many "Person" nodes. And I want those who live in New York to be red and those who live in Los Angeles to be blue. How would I write that. In cypher or in py2neo?
The styling of nodes and relationships in Neo4j Browser is controlled by a graph style sheet (GRASS), a cousin of CSS. You can view the current style by typing :style in the browser. To edit it, you can click on nodes and relationships and pick colors and sizes, or you can view the style sheet (:style), download it, make changes, and drag-n-drop it back into the view window.
Unfortunately for your case, color can only be controlled a) for all nodes and all relationships or b) for nodes by label and relationships by type. Properties can only be used for the text displayed on the node/rel.
It is not possible to interact with neo4j browser pro-grammatically. But the end goal could be achieved through a hack.
Even though I am a bit late here want to help others who might be finding a way. It is not possible to change the color of the nodes based on the property but there is a way it can be achieved by creating nodes based on the property. Keep in mind that after applying these queries your data wont be the same. So it is always a good idea to keep a backup of your data.
This is how labels are colored by default (Before):
Color based on the property
Suppose there is a label called Case with a property nationality and you want to color the nodes based on nationality. So following query could be used to create labels out of nationality property. For this you will need to install apoc library. check here for installation.
// BY NATIONALITY
MATCH (n:Case)
WITH DISTINCT n.nationality AS nationality, collect(DISTINCT n) AS persons
CALL apoc.create.addLabels(persons, [apoc.text.upperCamelCase(nationality)]) YIELD node
RETURN *
This will return all the people by nationality. Now you can color by country of nationality. Below shows an example.
Color based on the property and load with other labels
Lets say you also have a label called Cluster.The cases are attached to clusters via relationships. Just change the query to following to get the clusters with their relationships to cases.
//BY NATIONALITY WITH CLUSTERS
MATCH (n:Case),(c:Cluster)
WITH DISTINCT n.nationality AS nationality,
collect(DISTINCT n) AS persons,
collect(DISTINCT c) AS clusters
CALL apoc.create.addLabels(persons, [apoc.text.upperCamelCase(nationality)]) YIELD node
RETURN *
It will return cases and clusters with all the relationships. Below shows example.
Please leave an up vote if this was helpful and want to let others know that this is an acceptable answer. Thank you.
You cannot include formatting of the output in Cypher queries in the neo4j browser. Currently, the only way is to change the graph view manually or load a graph style file.
See tutorial here: http://neo4j.com/developer/guide-neo4j-browser/
Also, you cannot interact with the neo4j browser from py2neo.
If you are happy setting the color through a graphical user interface rather than programatically, Neo4j also supplies a data exploration addon named bloom. When using this addon (now automatically installed when using neo4j desktop), it is possible to set node color based on its properties.
In the example below, movies released after 2002 are colored green.

Deriving the label names from other node in neo4j

I'm using ne04j 2.1.2 community edition.
I have a nodes with a label called Company and I created these nodes and label by loading CSV file along with the MERGE and CREATE commands.
So in future if my label names changes,say Company to Organization, I wanted to maintain the createddate, UpdatedDate, NewLabelName, OldLabelName values somewhere.
So in order to achieve that I thought of maintaining one master node which holds the label information i.e., it should have the properties like NewLabelName, OldLabelName, CreatedDate, UpdatedDate. So the label name should come from the Master Node to other nodes. Whenever we made any changes to label ,then the corresponding UpdatedDate property value should be updated in the master node and NewLabelName should come from the master node to other nodes (nodes for which that label belongs to) .
Hope you understand the scenario here.
But how can i achieve this ? is it possible to achieve ? if yes, then how can i define the relationship between master and other nodes?
(Here my other nodes are Name of the Companies like Google, Yahoo, Samsung etc.. and those will be having some other child nodes like location)
Please suggest the solution. (I wanted to achieve these using cypher not using java)
Thanks
Although labels can be changed, you should do that rarely (e.g., to recover from a mistake). Changing a large number of labels is very expensive and should never be done as a part of normal processing.
Also, like a Java class name, a label name is not something you'd normally show to end users. So, there is really no reason to ever change them. Just try to pick reasonable label names to start with, and don't plan to change them.

Resources