You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'fornode_id, node_objinnet_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'}
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
Running above gives this output:
Extracted from: https://ndexbio.atlassian.net/browse/UD-1753
The text was updated successfully, but these errors were encountered: