Beispiel #1
0
    def test_remove_node_from_network_no_edges_no_attrs(self):
        net = NiceCXNetwork()
        node_id = net.create_node('node1', node_represents='ha')
        nef = NetworkNodeFactory()
        nn = nef.get_network_node_from_network(net_cx=net, node_id=node_id)

        nn.remove_node_from_network(net_cx=net)

        self.assertEqual(0, len(net.get_nodes()))
Beispiel #2
0
    def test_get_nodes(self):
        net = NiceCXNetwork()

        # Verify correct operation on empty network
        res = list(net.get_nodes())
        self.assertEqual(0, len(res))

        # add a node
        net.create_node('foo')
        res = list(net.get_nodes())
        self.assertEqual(1, len(res))
        self.assertEqual(res[0], (0, {'@id': 0, 'n': 'foo', 'r': 'foo'}))

        # add another node
        net.create_node('bar')
        res = list(net.get_nodes())
        self.assertEqual(2, len(res))
        self.assertEqual(res[0], (0, {'@id': 0, 'n': 'foo', 'r': 'foo'}))
        self.assertEqual(res[1], (1, {'@id': 1, 'n': 'bar', 'r': 'bar'}))
Beispiel #3
0
    def test_update_network(self):
        client = self.get_ndex2_client()
        # create network and add it
        net = NiceCXNetwork()
        oneid = net.create_node('node1')
        twoid = net.create_node('node2')
        net.create_edge(oneid, twoid, 'hello')
        netname = 'ndex2-client integration test network' + str(datetime.now())
        net.set_name(netname)
        res = client.save_new_network(net.to_cx(), visibility='PRIVATE')
        try:
            self.assertTrue('http' in res)
            netid = re.sub('^.*/', '', res)

            netsum = client.get_network_summary(network_id=netid)
            self.assertEqual(netid, netsum['externalId'])
            self.assertEqual(netname, netsum['name'])
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(1, netsum['edgeCount'])
            self.assertEqual(2, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])

            net.create_node(node_name='hello', node_represents='something')
            net.create_node(node_name='hoho', node_represents='heheh')
            newnetname = 'update ' + netname
            self.assertEqual(4, len(net.get_nodes()))
            net.set_name(newnetname)
            if sys.version_info.major == 3:
                stream = io.BytesIO(json.dumps(net.to_cx(),
                                               cls=DecimalEncoder)
                                    .encode('utf-8'))
            else:
                stream = io.BytesIO(json.dumps(net.to_cx(),
                                               cls=DecimalEncoder))
            newres = client.update_cx_network(stream, netid)
            self.assertEqual('', newres)
            netsum = client.get_network_summary(network_id=netid)
            self.assertEqual(netid, netsum['externalId'])
            self.assertEqual(newnetname, netsum['name'])
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(1, netsum['edgeCount'])
            self.assertEqual(4, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])
        finally:
            client.delete_network(netid)
            try:
                client.get_network_as_cx_stream(netid)
                self.fail('Expected exception')
            except HTTPError:
                pass
    def test_update_no_family_members(self):
        net = NiceCXNetwork()

        node1 = net.create_node('node1')
        node2 = net.create_node('node2')
        net.create_edge(edge_source=node1, edge_target=node2,
                        edge_interaction='activates')
        remover = ProteinFamilyNodeMemberRemover()
        remover.update(net)

        self.assertEqual(2, len(net.get_nodes()))
        self.assertEqual(1, len(net.get_edges()))
Beispiel #5
0
    def test_remove_node_from_network_with_edges_and_attrs(self):
        net = NiceCXNetwork()
        node_id = net.create_node('node1', node_represents='ha')
        other_node_id = net.create_node('node2', node_represents='ha')
        edge_id = net.create_edge(edge_source=node_id,
                                  edge_target=other_node_id,
                                  edge_interaction='activates')

        net.set_node_attribute(node_id, 'nodeattr', values='foo')
        net.set_node_attribute(node_id, 'nodeattr2', values='foo2')

        net.set_edge_attribute(edge_id, 'edgeattr', values='hello')
        net.set_edge_attribute(edge_id, 'edgeattr2', values='hello2')

        nef = NetworkNodeFactory()
        nn = nef.get_network_node_from_network(net_cx=net, node_id=node_id)

        nn.remove_node_from_network(net_cx=net)

        self.assertEqual(1, len(net.get_nodes()))
        self.assertEqual(0, len(net.get_edges()))
Beispiel #6
0
# In[ ]:

NiceCX_creatures = NiceCXNetwork()

#add 10 nodes to the network, each node has 5 attribute with value
for i in range(10):
    node_name = "node " + str(i)
    node_id = NiceCX_creatures.create_node(node_name)

    for j in range(5):
        attr_name = "attribute " + str(i) + str(j)
        attr_value = "attribute value is  " + str(i) + str(j)
        NiceCX_creatures.set_node_attribute(node_id, attr_name, attr_value)
        print("\n", NiceCX_creatures.get_node_attribute(node_id, attr_name))

NiceCX_creatures.get_nodes()

# #### *get_node(node)

# In[ ]:

NiceCX_creatures = NiceCXNetwork()
node_id = NiceCX_creatures.create_node("new node")
NiceCX_creatures.set_node_attribute(node_id, "new attribute",
                                    "new attribute value is nnnn")
NiceCX_creatures.get_node(node_id)

# #### create_edge(source, target, interaction)

# In[ ]:
Beispiel #7
0
    def test_update_network(self):
        client = self.get_ndex2_client()
        # create network and add it
        net = NiceCXNetwork()
        oneid = net.create_node('node1')
        twoid = net.create_node('node2')
        net.create_edge(oneid, twoid, 'hello')
        netname = 'NiceCXNetwork upload_to() test network' + str(
            datetime.now())
        net.set_name(netname)
        creds = self.get_ndex_credentials_as_tuple()
        res = net.upload_to(creds['server'],
                            creds['user'],
                            creds['password'],
                            user_agent=creds['user_agent'])
        try:
            self.assertTrue('http' in res)
            netid = re.sub('^.*/', '', res)
            netsum = self.wait_for_network_to_be_ready(client, netid)
            self.assertIsNotNone(
                netsum, 'Network is still not ready,'
                ' maybe server is busy?')
            self.assertEqual(netid, netsum['externalId'])
            self.assertTrue('name' in netsum, msg=str(netsum))
            self.assertEqual(netname, netsum['name'], str(netsum))
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(1, netsum['edgeCount'])
            self.assertEqual(2, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])

            net.create_node(node_name='hello', node_represents='something')
            net.create_node(node_name='hoho', node_represents='heheh')
            newnetname = 'update via upload_to() ' + netname
            self.assertEqual(4, len(net.get_nodes()))
            net.set_name(newnetname)
            newres = net.update_to(netid,
                                   creds['server'],
                                   creds['user'],
                                   creds['password'],
                                   user_agent=creds['user_agent'])
            self.assertEqual('', newres)
            netsum = self.wait_for_network_to_be_ready(client,
                                                       netid,
                                                       num_retries=5,
                                                       retry_weight=1)
            self.assertIsNotNone(
                netsum, 'Network is still not ready,'
                ' maybe server is busy?')
            self.assertEqual(netid, netsum['externalId'])
            self.assertEqual(newnetname, netsum['name'])
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(1, netsum['edgeCount'])
            self.assertEqual(4, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])
        finally:
            client.delete_network(netid)
            try:
                client.get_network_as_cx_stream(netid)
                self.fail('Expected exception')
            except HTTPError:
                pass