コード例 #1
0
    def test_simple_create(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Food Web")
        fox_node = niceCx_creatures.create_node(node_name='Fox')
        mouse_node = niceCx_creatures.create_node(node_name='Mouse')
        bird_node = niceCx_creatures.create_node(node_name='Bird')

        fox_bird_edge = niceCx_creatures.create_edge(
            edge_source=fox_node,
            edge_target=bird_node,
            edge_interaction='interacts-with')

        fox_mouse_edge = niceCx_creatures.create_edge(
            edge_source=fox_node,
            edge_target=mouse_node,
            edge_interaction='interacts-with')

        niceCx_creatures.add_node_attribute(property_of=fox_node,
                                            name='Color',
                                            values='Red')

        niceCx_creatures.add_node_attribute(property_of=mouse_node,
                                            name='Color',
                                            values='Gray')

        niceCx_creatures.add_node_attribute(property_of=bird_node,
                                            name='Color',
                                            values='Blue')

        niceCx_creatures.add_edge_attribute(property_of=fox_mouse_edge,
                                            name='Hunted',
                                            values='On the ground')

        print(niceCx_creatures.get_node_attribute(fox_node, 'Color'))
コード例 #2
0
    def test_update_network_containing_all_types(self):
        pfdict = {'a': ['2', '3'], 'SIGNOR-PF10': ['7', '8']}
        cdict = {'e': ['5', '6'], 'SIGNOR-C1': ['9', '10']}

        net = NiceCXNetwork()
        aid = net.create_node('a')
        net.set_node_attribute(aid, NodeMemberUpdator.TYPE, 'proteinfamily')

        eid = net.create_node('e')
        net.set_node_attribute(eid, NodeMemberUpdator.TYPE, 'complex')

        oid = net.create_node('c')

        o2id = net.create_node('d')
        net.set_node_attribute(o2id, NodeMemberUpdator.TYPE, 'protein')

        notinid = net.create_node('x')
        net.set_node_attribute(notinid, NodeMemberUpdator.TYPE,
                               'proteinfamily')

        notinid2 = net.create_node('y')
        net.set_node_attribute(notinid2, NodeMemberUpdator.TYPE, 'complex')

        mock = GeneSymbolSearcher(bclient=None)
        mock.get_symbol = MagicMock(side_effect=['AA', 'BB', 'CC', 'DD'])
        updator = NodeMemberUpdator(pfdict, cdict, genesearcher=mock)
        res = updator.update(net)
        self.assertTrue(
            "No entry in proteinfamily map for node: {'@id': 4, 'n': 'x', 'r': 'x'}"
            in res)
        self.assertTrue(
            "No entry in complexes map for node: {'@id': 5, 'n': 'y', 'r': 'y'}"
            in res)

        res = net.get_node_attribute(aid, NodeMemberUpdator.MEMBER)
        self.assertTrue('hgnc.symbol:AA' in res['v'])
        self.assertTrue('hgnc.symbol:BB' in res['v'])

        res = net.get_node_attribute(eid, NodeMemberUpdator.MEMBER)
        self.assertTrue('hgnc.symbol:CC' in res['v'])
        self.assertTrue('hgnc.symbol:DD' in res['v'])

        res = net.get_node_attribute(oid, NodeMemberUpdator.MEMBER)
        self.assertEqual(None, res)

        res = net.get_node_attribute(o2id, NodeMemberUpdator.MEMBER)
        self.assertEqual(None, res)
コード例 #3
0
    def test_update_network_containing_all_types(self):
        updator = UpdatePrefixesForNodeRepresents()
        net = NiceCXNetwork()

        uni_one = net.create_node('somenode', node_represents='rep1')
        net.set_node_attribute(uni_one, 'DATABASE', 'UNIPROT')

        uni_two = net.create_node('somenode2', node_represents='uniprot:rep2')
        net.set_node_attribute(uni_two, 'DATABASE', 'UNIPROT')

        sig_one = net.create_node('somenode3', node_represents='rep3')
        net.set_node_attribute(sig_one, 'DATABASE', 'SIGNOR')

        sig_two = net.create_node('somenode4', node_represents='signor:rep4')
        net.set_node_attribute(sig_two, 'DATABASE', 'SIGNOR')

        other = net.create_node('somenode5', node_represents='blah:rep5')
        net.set_node_attribute(other, 'DATABASE', 'other')

        self.assertEqual([], updator.update(net))

        res = net.get_node(uni_one)
        self.assertEqual('uniprot:rep1', res['r'])
        self.assertEqual(None, net.get_node_attribute(uni_one, 'DATABASE'))

        res = net.get_node(uni_two)
        self.assertEqual('uniprot:rep2', res['r'])
        self.assertEqual(None, net.get_node_attribute(uni_two, 'DATABASE'))

        res = net.get_node(sig_one)
        self.assertEqual('signor:rep3', res['r'])
        self.assertEqual(None, net.get_node_attribute(sig_one, 'DATABASE'))

        res = net.get_node(sig_two)
        self.assertEqual('signor:rep4', res['r'])
        self.assertEqual(None, net.get_node_attribute(sig_two, 'DATABASE'))

        res = net.get_node(other)
        self.assertEqual('blah:rep5', res['r'])
        self.assertEqual(None, net.get_node_attribute(other, 'DATABASE'))
コード例 #4
0
    def test_update_network_containing_all_types(self):
        updator = NodeLocationUpdator()
        net = NiceCXNetwork()

        comp_attr = NodeLocationUpdator.LOCATION
        no_attr = net.create_node('somenode', node_represents='rep1')

        e_attr = net.create_node('somenode2',
                                 node_represents='uniprot:rep2')
        net.set_node_attribute(e_attr,
                               NodeLocationUpdator.LOCATION,
                               '')

        o_attr = net.create_node('somenode2',
                                 node_represents='uniprot:rep2')
        net.set_node_attribute(o_attr,
                               NodeLocationUpdator.LOCATION,
                               'blah')

        ph_attr = net.create_node('anothernode', node_represents='rep3')

        net.set_node_attribute(ph_attr,
                               NodeLocationUpdator.LOCATION,
                               NodeLocationUpdator.PHENOTYPESLIST)

        self.assertEqual([],
                         updator.update(net))

        self.assertEqual(NodeLocationUpdator.CYTOPLASM,
                         net.get_node_attribute(no_attr, comp_attr)['v'])

        self.assertEqual(NodeLocationUpdator.CYTOPLASM,
                         net.get_node_attribute(e_attr, comp_attr)['v'])

        self.assertEqual('blah',
                         net.get_node_attribute(o_attr, comp_attr)['v'])

        self.assertEqual('',
                         net.get_node_attribute(ph_attr, comp_attr)['v'])
コード例 #5
0
    def test_simple_create(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Food Web")
        fox_node = niceCx_creatures.create_node(node_name='Fox')
        mouse_node = niceCx_creatures.create_node(node_name='Mouse')
        bird_node = niceCx_creatures.create_node(node_name='Bird')

        fox_bird_edge = niceCx_creatures.create_edge(edge_source=fox_node, edge_target=bird_node, edge_interaction='interacts-with')

        fox_mouse_edge = niceCx_creatures.create_edge(edge_source=fox_node, edge_target=mouse_node, edge_interaction='interacts-with')

        niceCx_creatures.add_node_attribute(property_of=fox_node, name='Color', values='Red')

        niceCx_creatures.add_node_attribute(property_of=mouse_node, name='Color', values='Gray')

        niceCx_creatures.add_node_attribute(property_of=bird_node, name='Color', values='Blue')

        niceCx_creatures.add_edge_attribute(property_of=fox_mouse_edge, name='Hunted', values='On the ground')

        print(niceCx_creatures.get_node_attribute(fox_node, 'Color'))
コード例 #6
0
# In[ ]:

NiceCX_creatures = NiceCXNetwork()
node_id = NiceCX_creatures.create_node("new node")
NiceCX_creatures.add_node_attribute(node_id, "new attribute",
                                    "new attribute value is xxxx")

# #### get_node_attribute(node, attribute_name, subnetwork=None)

# 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_attribute(node_id, "new attribute")

# ##### get_node_attribute_objects(node, attribute_name)

# In[ ]:

#get_node_attribute_objects() is deprecated.  Please use get_node_attribute() instead

# #### get_node_attributes(node)

# In[ ]:

NiceCX_creatures = NiceCXNetwork()

#create one node
node_id = NiceCX_creatures.create_node("new node")