Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting NiceCXNetwork to networkx and back does not handle node name consistently #84

Closed
coleslaw481 opened this issue Jun 15, 2021 · 1 comment
Assignees
Labels
Milestone

Comments

@coleslaw481
Copy link
Contributor

Converting networkx to NiceCXNetwork should take the name attribute and set it as the node name and NOT as a separate nodeAttribute or as represents

import ndex2
import networkx as nx

# create simple 2 node / 1 edge network
net = ndex2.nice_cx_network.NiceCXNetwork()
node_one = net.create_node('Node 1')
node_two = net.create_node('Node 2')
net.create_edge(edge_source=node_one, edge_target=node_two)

print(net.get_nodes())

netx_net = net.to_networkx(mode='default')

print(nx.get_node_attributes(netx_net, 'name'))

# convert back to NiceCXNetwork
net_roundtrip = ndex2.create_nice_cx_from_networkx(netx_net)
print(net_roundtrip.get_nodes())

# there should NOT be any node attributes with name 'name'
for node_id, node_obj in net_roundtrip.get_nodes():
    print(net_roundtrip.get_node_attribute(node_id, 'name'))

Running above gives this output:

# the node names for original NiceCXNetwork
{0: 'Node 1', 1: 'Node 2'}

# the node names after round trip (they are now set to id of node and node name is set to represents)
dict_items([(0, {'@id': 0, 'n': 0, 'r': 'Node 1'}), (1, {'@id': 1, 'n': 1, 'r': 'Node 2'})])

# the node name is also set as node attributes:
{'po': 0, 'n': 'name', 'v': 'Node 1', 'd': 'string'}
{'po': 1, 'n': 'name', 'v': 'Node 2', 'd': 'string'}

Extracted from: https://ndexbio.atlassian.net/browse/UD-1753

@coleslaw481 coleslaw481 self-assigned this Jun 15, 2021
@coleslaw481 coleslaw481 added this to the 3.5.0 milestone May 5, 2022
@coleslaw481
Copy link
Contributor Author

Fixed with commit:
To github.com:ndexbio/ndex2-client.git
d0d90e2..3f62959 v3.5.0 -> v3.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant