def test_add_member_genes(self):

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

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

        mock = GeneSymbolSearcher(bclient=None)
        mock.get_symbol = MagicMock(side_effect=['', None])
        updator = NodeMemberUpdator(None, None, genesearcher=mock)

        aidnode = net.get_node(aid)
        res = updator._add_member_genes(net, aidnode, [])
        self.assertEqual(['No proteins obtained for node: ' + str(aidnode)],
                         res)

        notinidnode = net.get_node(notinid)
        res = updator._add_member_genes(net, notinidnode, ['x'])
        self.assertTrue('For node ' + str(notinidnode) +
                        ' No gene symbol found for x. Skipping.' in res)

        self.assertTrue('Not a single gene symbol found. Skipping insertion '
                        'of member attribute for node ' +
                        str(notinidnode) in res)
    def test_update_one_node_to_update_symbol_not_none(self):
        mock = MagicMock()
        mock.get_symbol = MagicMock(return_value='SMILE')
        updater = UniProtToGeneSymbolUpdater(searcher=mock)
        net = NiceCXNetwork()

        nodeone = net.create_node(node_name='Q1', node_represents='uniprot:q1')
        res = updater.update(net)
        self.assertEqual(0, len(res))
        self.assertEqual('SMILE', net.get_node(nodeone)['n'])
        self.assertEqual('uniprot:q1', net.get_node(nodeone)['r'])

        mock.get_symbol.assert_called_with('Q1')
    def test_update_one_node_to_update_symbol_is_none(self):
        mock = MagicMock()
        mock.get_symbol = MagicMock(return_value=None)
        updater = UniProtToGeneSymbolUpdater(searcher=mock)
        net = NiceCXNetwork()

        nodeone = net.create_node(node_name='bob',
                                  node_represents='uniprot:bob')
        res = updater.update(net)
        self.assertEqual(1, len(res))
        self.assertTrue('No symbol found to replace' in res[0])
        self.assertEqual('bob', net.get_node(nodeone)['n'])
        self.assertEqual('uniprot:bob', net.get_node(nodeone)['r'])

        mock.get_symbol.assert_called_with('bob')
 def test_update_no_nodes_start_with_uniprot(self):
     updater = UniProtToGeneSymbolUpdater()
     net = NiceCXNetwork()
     nodeone = net.create_node(node_name='node1', node_represents='node1')
     nodetwo = net.create_node(node_name='node2', node_represents='node2')
     res = updater.update(net)
     self.assertEqual(0, len(res))
     self.assertEqual('node1', net.get_node(nodeone)['n'])
     self.assertEqual('node2', net.get_node(nodetwo)['n'])
Beispiel #5
0
    def test_create_edge_with_node_dict_passed_in_for_edge_ids(self):
        net = NiceCXNetwork()

        nodeone = net.get_node(net.create_node('node1'))
        nodetwo = net.get_node(net.create_node('node2'))
        edge_id = net.create_edge(edge_source=nodeone,
                                  edge_target=nodetwo)
        res = net.get_edge(edge_id)
        self.assertEqual(edge_id, res[constants.EDGE_ID])
        self.assertEqual(0, res[constants.EDGE_SOURCE])
        self.assertEqual(1, res[constants.EDGE_TARGET])
Beispiel #6
0
 def test_set_node_attribute_passing_node_object(self):
     # try int
     net = NiceCXNetwork()
     node_id = net.create_node(node_name='foo')
     node = net.get_node(node_id)
     net.set_node_attribute(node, 'attrname', 5)
     res = net.get_node_attributes(node_id)
     self.assertEqual(len(res), 1)
     self.assertEqual(res[0][constants.NODE_ATTR_PROPERTYOF], node_id)
     self.assertEqual(res[0][constants.NODE_ATTR_NAME], 'attrname')
     self.assertEqual(res[0][constants.NODE_ATTR_VALUE], 5)
     self.assertEqual(res[0][constants.NODE_ATTR_DATATYPE], 'integer')
    def test_update_no_represents_in_nodes(self):
        updater = UniProtToGeneSymbolUpdater()
        net = NiceCXNetwork()
        nodeone = net.create_node(node_name='node1', node_represents=None)
        nodetwo = net.create_node(node_name='node2', node_represents=None)

        # so in NDEx2 python client 3.2.0 and earlier if you
        # pass node_represents=None the represents field is set
        # to the values set in node_name which doesn't seem like
        # correct behavior...
        firstnode = net.get_node(nodeone)
        del firstnode['r']
        secondnode = net.get_node(nodetwo)
        del secondnode['r']

        res = updater.update(net)
        self.assertEqual(2, len(res))
        self.assertTrue('(0) and name (node1) no represents' in res[0])
        self.assertTrue('(1) and name (node2) no represents' in res[1])
        self.assertEqual('node1', net.get_node(nodeone)['n'])
        self.assertEqual('node2', net.get_node(nodetwo)['n'])
    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'))
Beispiel #9
0
        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[ ]:

NiceCX_creatures = NiceCXNetwork()

#create_edge() method returns the new edge id. IDs are always assigned in an ascending order.
print(NiceCX_creatures.create_edge("A", "B"))
print(NiceCX_creatures.create_edge("C", "D"))
print(NiceCX_creatures.create_edge("B", "C"))

# #### add_edge(edge)

# In[ ]: