Example #1
0
    def test_basic_network_where_neighbor_of_citations_merges_disabled(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator(disablcitededgemerge=True)
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION, ['pubmed:5'],
                               type='list_of_string')
        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        oid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='someother')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        self.assertEqual('controls-state-change-of', net.get_edge(cid)['i'])
        self.assertEqual('someother', net.get_edge(oid)['i'])

        self.assertEqual([], adjud.update(net))
        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        self.assertEqual(None, net.get_edge(cid))
        self.assertEqual('someother', net.get_edge(oid)['i'])
        res = net.get_edge_attribute(nid, RedundantEdgeAdjudicator.CITATION)
        res['v'].sort()
        self.assertEqual(['pubmed:5'], res['v'])
        res = net.get_edge_attribute(oid, RedundantEdgeAdjudicator.CITATION)

        self.assertEqual((None, None), res)
    def test_update_edge_with_dict(self):
        collapser = RedundantEdgeCollapser()
        net = NiceCXNetwork()

        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='something')
        net.set_edge_attribute(eid, 'sentence', 'hi', type='string')

        edge_dict = {
            'citation': (set(['pubmed:123']), 'list_of_string'),
            'sentence': (set(['sentence1', 'sentence2']), 'string'),
            'direct': (set([True, False]), 'boolean')
        }

        res = collapser._update_edge_with_dict(net, eid, edge_dict)

        self.assertTrue('direct attribute has multiple values:' in res[0])

        edata = net.get_edge_attribute(eid, 'citation')
        self.assertEqual('list_of_string', edata['d'])
        self.assertEqual(['pubmed:123'], edata['v'])

        edata = net.get_edge_attribute(eid, 'sentence')
        self.assertEqual('list_of_string', edata['d'])
        self.assertTrue('sentence1' in edata['v'])
        self.assertTrue('sentence2' in edata['v'])
        self.assertEqual(2, len(edata['v']))

        edata = net.get_edge_attribute(eid, 'direct')
        self.assertEqual('boolean', edata['d'])
        self.assertEqual(False, edata['v'])
    def test_remove_edge(self):
        collapser = RedundantEdgeCollapser()
        net = NiceCXNetwork()

        # test remove on non existant edge
        collapser._remove_edge(net, 10)

        # test removing edge with no attributes
        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='needs')
        self.assertEqual('needs', net.get_edge(eid)['i'])
        collapser._remove_edge(net, eid)
        self.assertEqual(None, net.get_edge(eid))

        # test removing edge with attributes
        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='needs')

        net.set_edge_attribute(eid, 'foo', 'someval')
        net.set_edge_attribute(eid, 'foo2', 'someval2')

        self.assertEqual('needs', net.get_edge(eid)['i'])
        self.assertEqual('someval', net.get_edge_attribute(eid, 'foo')['v'])
        self.assertEqual('someval2', net.get_edge_attribute(eid, 'foo2')['v'])
        collapser._remove_edge(net, eid)
        self.assertEqual(None, net.get_edge(eid))
        self.assertEqual((None, None), net.get_edge_attribute(eid, 'foo'))
        self.assertEqual((None, None), net.get_edge_attribute(eid, 'foo2'))
Example #4
0
 def test_remove_edge_with_attributes(self):
     adjud = RedundantEdgeAdjudicator()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     net.set_edge_attribute(edgeid, 'attr1', 'someval')
     self.assertEqual('someval',
                      net.get_edge_attribute(edgeid, 'attr1')['v'])
     self.assertEqual('foo', net.get_edge(edgeid)['i'])
     adjud._remove_edge(net, edgeid)
     self.assertEqual(None, net.get_edge(edgeid))
     self.assertEqual((None, None), net.get_edge_attribute(edgeid, 'attr1'))
    def test_update(self):
        collapser = RedundantEdgeCollapser()
        net = NiceCXNetwork()
        ctext = {'pubmed': 'http://p/'}
        net.set_network_attribute('@context', values=json.dumps(ctext))
        collapser._set_pubmedurl_from_network(net)

        eid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='something')

        net.set_edge_attribute(eid, 'sentence', 'sent1', type='string')
        net.set_edge_attribute(eid, 'direct', True, type='boolean')
        net.set_edge_attribute(eid, 'citation', 'pubmed:123', type='string')

        eidtwo = net.create_edge(edge_source=0,
                                 edge_target=1,
                                 edge_interaction='something')
        net.set_edge_attribute(eidtwo, 'sentence', 'sent2', type='string')
        net.set_edge_attribute(eidtwo, 'direct', True, type='boolean')
        net.set_edge_attribute(eidtwo, 'citation', 'pubmed:456', type='string')
        res = collapser.update(net)

        self.assertEqual([], res)

        edata = net.get_edge_attribute(eid, 'sentence')
        self.assertEqual(2, len(edata['v']))

        self.assertTrue('<a target="_blank" href="http://p/456">'
                        'pubmed:456</a>  sent2' in edata['v'])
        self.assertTrue('<a target="_blank" href="http://p/123">'
                        'pubmed:123</a> sent1' in edata['v'])
Example #6
0
 def test_edge_with_no_edgecitation(self):
     updator = EmptyCitationAttributeRemover()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0, edge_target=1,
                              edge_interaction='foo')
     self.assertEqual([], updator.update(net))
     self.assertEqual((None, None), net.get_edge_attribute(edgeid,
                                                           'citation'))
 def test_with_network_with_edge_not_supposed_to_be_directed(self):
     setter = DirectedEdgeSetter()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     self.assertEqual([], setter.update(net))
     directed = DirectedEdgeSetter.DIRECTED_ATTRIB
     self.assertEqual(False, net.get_edge_attribute(edgeid, directed)['v'])
Example #8
0
 def test_edge_with_emptystring(self):
     updator = EmptyCitationAttributeRemover()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0, edge_target=1,
                              edge_interaction='foo')
     net.set_edge_attribute(edgeid, 'citation', values=[''],
                            type='list_of_string')
     self.assertEqual([], updator.update(net))
     self.assertEqual((None, None), net.get_edge_attribute(edgeid,
                                                           'citation'))
Example #9
0
 def test_edge_with_no_edgecitation(self):
     updator = EmptyCitationAttributeUpdator()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     self.assertEqual([], updator.update(net))
     edge = net.get_edge_attribute(edgeid, 'citation')
     self.assertEqual([], edge['v'])
     self.assertEqual('list_of_string', edge['d'])
Example #10
0
 def test_edge_with_emptyelementincitationlist(self):
     updator = EmptyCitationAttributeRemover()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0, edge_target=1,
                              edge_interaction='foo')
     net.set_edge_attribute(edgeid, 'citation',
                            values=['foo', 'pubmed:', 'hi'],
                            type='list_of_string')
     self.assertEqual([], updator.update(net))
     self.assertEqual(['foo', 'hi'],
                      net.get_edge_attribute(edgeid, 'citation')['v'])
Example #11
0
 def test_edge_with_emptypubmedcitation(self):
     updator = EmptyCitationAttributeUpdator()
     net = NiceCXNetwork()
     edgeid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='foo')
     net.set_edge_attribute(edgeid,
                            'citation',
                            values=['pubmed:'],
                            type='list_of_string')
     self.assertEqual([], updator.update(net))
     edge = net.get_edge_attribute(edgeid, 'citation')
     self.assertEqual([], edge['v'])
    def test_update_network_containing_all_types(self):
        updator = DirectEdgeAttributeUpdator()
        net = NiceCXNetwork()

        noattredge = net.create_edge(edge_source=0, edge_target=1,
                                     edge_interaction='foo')
        t_edge = net.create_edge(edge_source=2, edge_target=3,
                                 edge_interaction='blah')
        net.set_edge_attribute(t_edge,
                               DirectEdgeAttributeUpdator.DIRECTED_ATTRIB,
                               't', type='string')

        f_edge = net.create_edge(edge_source=3, edge_target=4,
                                 edge_interaction='blah')
        net.set_edge_attribute(f_edge,
                               DirectEdgeAttributeUpdator.DIRECTED_ATTRIB,
                               'f', type='string')

        o_edge = net.create_edge(edge_source=3, edge_target=4,
                                 edge_interaction='blah')
        net.set_edge_attribute(o_edge,
                               DirectEdgeAttributeUpdator.DIRECTED_ATTRIB,
                               'blah', type='string')
        self.assertEqual([],
                         updator.update(net))

        d_attrib = DirectEdgeAttributeUpdator.DIRECTED_ATTRIB
        res = net.get_edge_attribute(noattredge, d_attrib)
        self.assertEqual((None, None), res)

        res = net.get_edge_attribute(t_edge, d_attrib)
        self.assertEqual(res['v'], True)

        res = net.get_edge_attribute(f_edge, d_attrib)
        self.assertEqual(res['v'], False)

        res = net.get_edge_attribute(o_edge, d_attrib)
        self.assertEqual(res['v'], False)
    def test_with_network_with_edges_that_are_directed(self):
        setter = DirectedEdgeSetter()
        net = NiceCXNetwork()
        directed = DirectedEdgeSetter.DIRECTED_ATTRIB
        cntr = 1
        for entry in loadndexncipidloader.DIRECTED_INTERACTIONS:

            edgeid = net.create_edge(edge_source=0,
                                     edge_target=cntr,
                                     edge_interaction=entry)
            self.assertEqual([], setter.update(net))
            self.assertEqual(True,
                             net.get_edge_attribute(edgeid, directed)['v'])
            cntr = cntr + 1
Example #14
0
    def test_remove_if_redundant_mergecitations_true(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

        net.set_edge_attribute(nid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:4', 'pubmed:123'],
                               type='list_of_string')

        cid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='controls-state-change-of')

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid], mergecitations=True)
        self.assertEqual(None, net.get_edge(nid))
        res = net.get_edge_attribute(cid, RedundantEdgeAdjudicator.CITATION)
        res['v'].sort()
        self.assertEqual(['pubmed:123', 'pubmed:4'], res['v'])
Example #15
0
    def test_update_network_with_pmc_citation(self):
        updator = InvalidEdgeCitationRemover()
        net = NiceCXNetwork()

        noattredge = net.create_edge(edge_source=0,
                                     edge_target=1,
                                     edge_interaction='foo')
        t_edge = net.create_edge(edge_source=2,
                                 edge_target=3,
                                 edge_interaction='blah')
        net.set_edge_attribute(t_edge,
                               InvalidEdgeCitationRemover.CITATION_ATTRIB,
                               ['pubmed:PMC3619734'],
                               type='list_of_string')

        issues = updator.update(net)
        self.assertEqual(1, len(issues))
        self.assertTrue('Replacing' in issues[0])

        res = net.get_edge_attribute(
            t_edge, InvalidEdgeCitationRemover.CITATION_ATTRIB)
        self.assertEqual(['pubmed:15109499'], res['v'])
Example #16
0
# In[ ]:

NiceCX_creatures = NiceCXNetwork()
edge_id = NiceCX_creatures.create_edge("A", "B")
NiceCX_creatures.set_edge_attribute(edge_id, "new edge attribute",
                                    "edge attribute value is nnnnn")

# #### get_edge_attribute(edge, attribute_name, subnetwork=None)

# In[ ]:

NiceCX_creatures = NiceCXNetwork()
edge_id = NiceCX_creatures.create_edge("A", "B")
NiceCX_creatures.set_edge_attribute(edge_id, "new edge attribute",
                                    "new edge attribute value is nnnnn")
NiceCX_creatures.get_edge_attribute(edge_id, "new edge attribute")

# #### get_edge_attribute_objects(edge, attribute_name)

# In[ ]:

#This method has been deprecated. Please use get_edge_attributes()

# #### get_edge_attributes(edge)

# In[ ]:

NiceCX_creatures = NiceCXNetwork()
edge_id = NiceCX_creatures.create_edge("A", "B")

# add 5 attributes to the edge
Example #17
0
    def test_update_network_containing_several_citations(self):
        updator = InvalidEdgeCitationRemover()
        net = NiceCXNetwork()

        noattredge = net.create_edge(edge_source=0,
                                     edge_target=1,
                                     edge_interaction='foo')
        t_edge = net.create_edge(edge_source=2,
                                 edge_target=3,
                                 edge_interaction='blah')
        net.set_edge_attribute(t_edge,
                               InvalidEdgeCitationRemover.CITATION_ATTRIB, [],
                               type='list_of_string')

        v_edge = net.create_edge(edge_source=3,
                                 edge_target=4,
                                 edge_interaction='blah')
        net.set_edge_attribute(v_edge,
                               InvalidEdgeCitationRemover.CITATION_ATTRIB,
                               ['pubmed:1234'],
                               type='list_of_string')

        o_edge = net.create_edge(edge_source=3,
                                 edge_target=4,
                                 edge_interaction='blah')
        net.set_edge_attribute(o_edge,
                               InvalidEdgeCitationRemover.CITATION_ATTRIB,
                               ['pubmed:Other'],
                               type='list_of_string')

        neg_edge = net.create_edge(edge_source=5,
                                   edge_target=6,
                                   edge_interaction='blah')

        net.set_edge_attribute(neg_edge,
                               InvalidEdgeCitationRemover.CITATION_ATTRIB,
                               ['pubmed:-100', 'pubmed:5'],
                               type='list_of_string')

        issues = updator.update(net)
        self.assertEqual(2, len(issues))
        self.assertTrue('Removing invalid citation id: '
                        'pubmed:Other on edge id: ' + str(o_edge) in issues)
        self.assertTrue('Removing invalid citation id: '
                        'pubmed:-100 on edge id: ' + str(neg_edge) in issues)

        d_attrib = InvalidEdgeCitationRemover.CITATION_ATTRIB
        res = net.get_edge_attribute(noattredge, d_attrib)
        self.assertEqual((None, None), res)

        res = net.get_edge_attribute(t_edge, d_attrib)
        self.assertEqual([], res['v'])

        res = net.get_edge_attribute(v_edge, d_attrib)
        self.assertEqual(['pubmed:1234'], res['v'])

        res = net.get_edge_attribute(o_edge, d_attrib)
        self.assertEqual([], res['v'])

        res = net.get_edge_attribute(neg_edge, d_attrib)
        self.assertEqual(['pubmed:5'], res['v'])