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 #2
0
    def test_basic_network(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        nid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='neighbor-of')

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

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

        oid = net.create_edge(edge_source=0,
                              edge_target=1,
                              edge_interaction='someother')
        net.set_edge_attribute(oid,
                               RedundantEdgeAdjudicator.CITATION,
                               ['pubmed:123'],
                               type='list_of_string')

        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(None, net.get_edge(nid))
        self.assertEqual(None, net.get_edge(cid))
        self.assertEqual('someother', net.get_edge(oid)['i'])
    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'])
Example #4
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)
Example #5
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 #6
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 #7
0
 def test_edge_with_emptylistcitation(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=[],
                            type='list_of_string')
     self.assertEqual([], updator.update(net))
     edge = net.get_edge_attribute(edgeid, 'citation')
     self.assertEqual([], edge['v'])
Example #8
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'))
Example #9
0
    def test_remove_if_redundant_with_citation_and_other_lacks_citation(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: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])
        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
    def test_basic_network_where_neighbor_of_citations_merges_enabled(self):
        net = NiceCXNetwork()
        adjud = RedundantEdgeAdjudicator()
        edge_map = {}
        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')
        net.set_edge_attribute(cid,
                               RedundantEdgeAdjudicator.CITATION, ['pubmed:6'],
                               type='list_of_string')

        neighbor_of_map = {}
        controls_state_change_map = {}
        other_edge_exists = {}
        for k, v in net.get_edges():
            s = v['s']
            t = v['t']
            i = v['i']

            if i == 'neighbor-of':
                if not s in neighbor_of_map:
                    neighbor_of_map[s] = {}
                if not t in neighbor_of_map:
                    neighbor_of_map[t] = {}
                neighbor_of_map[s][t] = k
                neighbor_of_map[t][s] = k
            elif i == 'controls-state-change-of':
                adjud._add_to_edge_map(controls_state_change_map, k, s, t)
            else:
                adjud._add_to_edge_map(other_edge_exists, k, s, t)

        adjud.remove_and_merge_neighbor_of(net, neighbor_of_map, edge_map)

        net.print_summary()
Example #11
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()))
Example #12
0
    def test_remove_if_redundant_with_multiple_edges_same_citations(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')

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

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

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

        self.assertEqual('neighbor-of', net.get_edge(nid)['i'])
        adjud._remove_if_redundant(net, nid, [cid, cidtwo])
        self.assertEqual(None, net.get_edge(nid))
Example #13
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 #14
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'])
    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)
Example #16
0
class NiceCxAssembler(object):
    """Assembles a Nice CX network from a set of INDRA Statements.

    Parameters
    ----------
    stmts : Optional[list[indra.statements.Statement]]
        A list of INDRA Statements to be assembled.
    network_name : Optional[str]
        The name of the network to be assembled. Default: indra_assembled

    Attributes
    ----------
    network : ndex2.nice_cx_network.NiceCXNetwork
        A Nice CX network object that is assembled from Statements.
    """
    def __init__(self, stmts=None, network_name=None):
        self.statements = stmts if stmts else []
        self.network = NiceCXNetwork()
        self.network.set_network_attribute(
            'name', (network_name if network_name else 'indra_assembled'))
        self.node_keys = {}
        self.context_prefixes = {
            'pubmed': 'https://identifiers.org/pubmed:',
            'hgnc.symbol': 'https://identifiers.org/hgnc.symbol:'
        }

    def make_model(self, self_loops=False, network_attributes=None):
        """Return a Nice CX network object after running assembly.

        Parameters
        ----------
        self_loops : Optional[bool]
            If False, self-loops are excluded from the network. Default: False
        network_attributes : Optional[dict]
            A dictionary containing attributes to be added to the
            assembled network.

        Returns
        -------
        ndex2.nice_cx_network.NiceCXNetwork
            The assembled Nice CX network.
        """
        for stmt in self.statements:
            agents = stmt.agent_list()
            not_none_agents = [a for a in agents if a is not None]
            if len(not_none_agents) < 2:
                continue
            for a1, a2 in itertools.combinations(not_none_agents, 2):
                a1_id = self.add_node(a1)
                a2_id = self.add_node(a2)
                if not self_loops and a1_id == a2_id:
                    continue
                edge_id = self.add_edge(a1_id, a2_id, stmt)

        self.network.set_network_attribute('@context',
                                           json.dumps(self.context_prefixes))
        if network_attributes:
            for k, v in network_attributes.items():
                self.network.set_network_attribute(k, v, 'string')
        return self.network

    def add_node(self, agent):
        """Add an Agent to the network as a node."""
        agent_key = self.get_agent_key(agent)
        # If the node already exists
        if agent_key in self.node_keys:
            return self.node_keys[agent_key]

        # If the node doesn't exist yet
        db_ns, db_id = agent.get_grounding()
        # TODO: handle more represents name spaces
        if db_ns == 'HGNC':
            represents = 'hgnc.symbol:%s' % agent.name
        else:
            represents = None
        node_id = self.network.create_node(agent.name,
                                           node_represents=represents)
        self.node_keys[agent_key] = node_id

        # Add db_refs as aliases
        db_refs_list = [
            '%s:%s' % (db_name, db_id)
            for db_name, db_id in agent.db_refs.items()
            if db_name in url_prefixes
        ]
        if db_refs_list:
            self.network.add_node_attribute(property_of=node_id,
                                            name='aliases',
                                            values=db_refs_list,
                                            type='list_of_string')

        # Add the type of the node, inferred from grounding
        if db_ns:
            mapped_type = db_ns_type_mappings.get(db_ns)
            if mapped_type:
                self.network.add_node_attribute(property_of=node_id,
                                                name='type',
                                                values=mapped_type,
                                                type='string')

        return node_id

    def add_edge(self, a1_id, a2_id, stmt):
        """Add a Statement to the network as an edge."""
        stmt_type = stmt.__class__.__name__
        edge_id = self.network.create_edge(a1_id, a2_id, stmt_type)
        evs = []
        for ev in stmt.evidence:
            # We skip evidences with no PMID
            if not ev.pmid:
                continue
            # We take a maximum 200 character snippet of the evidence text
            if not ev.text:
                ev_txt = 'Evidence text not available.'
            elif len(ev.text) > 200:
                ev_txt = ev.text[:200] + '...'
            else:
                ev_txt = ev.text
            # Construct a clickable PMID link with the source and evidence text
            ev_str = ('<a target="_blank" '
                      'href="https://identifiers.org/pubmed:%s">'
                      'pubmed:%s</a> (%s) %s') % (ev.pmid, ev.pmid,
                                                  ev.source_api, ev_txt)
            evs.append((ev_str, 0 if ev.text is None else 1))
        # Reorder to have ones with text first
        evs = sorted(evs, key=lambda x: x[1], reverse=True)
        # Cap at 10 pieces of evidence
        evs = [e[0] for e in evs[:10]]
        self.network.set_edge_attribute(edge_id,
                                        'citation',
                                        evs,
                                        type='list_of_string')
        return edge_id

    def print_model(self):
        """Return the CX string of the assembled model."""
        return self.network.to_cx()

    @staticmethod
    def get_agent_key(agent):
        return agent.name
    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 #18
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'])
Example #19
0
print(NiceCX_creatures.create_edge("C", "D"))
print(NiceCX_creatures.create_edge("B", "C"))

# #### add_edge(edge)

# In[ ]:

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

# #### set_edge_attribute(edge, attribute_name, values, type=None, subnetwork=None)

# 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[ ]:
Example #20
0
    def test_two_node_one_edge_network(self):
        net = NiceCXNetwork()
        net.create_node('first')
        net.create_node('second')
        edge_one = net.create_edge(edge_source=0, edge_target=1)
        net.set_name('bob')

        net.set_edge_attribute(edge_one,
                               'booleanattrib',
                               'false',
                               type='boolean')
        net.set_edge_attribute(edge_one, 'integerattrib', '1', type='integer')
        net.set_edge_attribute(edge_one, 'doubleattrib', '2.0', type='double')
        net.set_edge_attribute(edge_one, 'longattrib', '3', type='long')
        net.set_edge_attribute(edge_one,
                               'stringattrib',
                               'false',
                               type='string')
        net.set_edge_attribute(edge_one,
                               'list_of_booleanattrib', ['True'],
                               type='list_of_boolean')
        net.set_edge_attribute(edge_one,
                               'list_of_doubleattrib', ['4.0'],
                               type='list_of_double')
        net.set_edge_attribute(edge_one,
                               'list_of_integerattrib', ['5'],
                               type='list_of_integer')
        net.set_edge_attribute(edge_one,
                               'list_of_longattrib', ['6'],
                               type='list_of_long')
        net.set_edge_attribute(edge_one,
                               'list_of_stringattrib', ['false'],
                               type='list_of_string')

        fac = DefaultNetworkXFactory()
        g = fac.get_graph(net)
        self.assertEqual('bob', g.graph['name'])
        self.assertEqual(2, len(g))
        self.assertEqual(1, g.number_of_edges())
        self.assertTrue(0 in g)

        if NETWORKX_MAJOR_VERSION >= 2:
            nodelist = list(g.nodes(data=True))
            edgelist = list(g.edges(data=True))
        else:
            nodelist = g.nodes(data=True)
            edgelist = g.edges(data=True)

        self.assertEqual('first', nodelist[0][1]['name'])
        self.assertEqual('second', nodelist[1][1]['name'])
        self.assertEqual(0, edgelist[0][0])
        self.assertEqual(1, edgelist[0][1])
        self.assertEqual(None, edgelist[0][2]['interaction'])

        self.assertEqual('false', edgelist[0][2]['booleanattrib'])
        self.assertEqual('1', edgelist[0][2]['integerattrib'])
        self.assertEqual('2.0', edgelist[0][2]['doubleattrib'])
        self.assertEqual('3', edgelist[0][2]['longattrib'])
        self.assertEqual('false', edgelist[0][2]['stringattrib'])

        self.assertEqual(['True'], edgelist[0][2]['list_of_booleanattrib'])
        self.assertEqual(['4.0'], edgelist[0][2]['list_of_doubleattrib'])
        self.assertEqual(['5'], edgelist[0][2]['list_of_integerattrib'])
        self.assertEqual(['6'], edgelist[0][2]['list_of_longattrib'])
        self.assertEqual(['false'], edgelist[0][2]['list_of_stringattrib'])