Ejemplo n.º 1
0
def test_validator_good():
    """
    A fake test to establish a success condition for validation.
    """
    G = NxGraph()
    G.add_node(
        "UniProtKB:P123456", id="UniProtKB:P123456", name="fake", category=["Protein"]
    )
    G.add_node(
        "UBERON:0000001", id="UBERON:0000001", name="fake", category=["NamedThing"]
    )
    G.add_node(
        "UBERON:0000002", id="UBERON:0000002", name="fake", category=["NamedThing"]
    )
    G.add_edge(
        "UBERON:0000001",
        "UBERON:0000002",
        id="UBERON:0000001-part_of-UBERON:0000002",
        relation="RO:1",
        predicate="part_of",
        subject="UBERON:0000001",
        object="UBERON:0000002",
        category=["biolink:Association"],
    )
    validator = Validator(verbose=True)
    validator.validate(G)
    print(validator.get_errors())
    assert len(validator.get_errors()) == 0
Ejemplo n.º 2
0
def test_validator_good():
    """
    A fake test to establish a success condition for validation.
    """
    G = NxGraph()
    G.add_node('UniProtKB:P123456',
               id='UniProtKB:P123456',
               name='fake',
               category=['Protein'])
    G.add_node('UBERON:0000001',
               id='UBERON:0000001',
               name='fake',
               category=['NamedThing'])
    G.add_node('UBERON:0000002',
               id='UBERON:0000002',
               name='fake',
               category=['NamedThing'])
    G.add_edge(
        'UBERON:0000001',
        'UBERON:0000002',
        id='UBERON:0000001-part_of-UBERON:0000002',
        relation='RO:1',
        predicate='part_of',
        subject='UBERON:0000001',
        object='UBERON:0000002',
        category=['biolink:Association'],
    )
    validator = Validator(verbose=True)
    e = validator.validate(G)
    print(validator.report(e))
    assert len(e) == 0
Ejemplo n.º 3
0
def test_add_edge():
    """
    Test adding an edge to an NxGraph.
    """
    g = NxGraph()
    g.add_node('A')
    g.add_node('B')
    g.add_edge('A', 'B', predicate='biolink:related_to', provided_by='test')
    assert g.has_edge('A', 'B')
    g.add_edge('B', 'C', edge_key='B-biolink:related_to-C', provided_by='test')
    assert g.has_edge('B', 'C')
Ejemplo n.º 4
0
def test_add_edge():
    """
    Test adding an edge to an NxGraph.
    """
    g = NxGraph()
    g.add_node("A")
    g.add_node("B")
    g.add_edge("A", "B", predicate="biolink:related_to", provided_by="test")
    assert g.has_edge("A", "B")
    g.add_edge("B", "C", edge_key="B-biolink:related_to-C", provided_by="test")
    assert g.has_edge("B", "C")
Ejemplo n.º 5
0
def test_relabel_nodes():
    """
    Test relabelling of nodes in an NxGraph.
    """
    g = get_graphs()[1]
    m = {'A': 'A:1', 'E': 'E:1'}
    NxGraph.relabel_nodes(g, m)
    assert not g.has_node('A')
    assert g.has_node('A:1')
    assert not g.has_node('E')
    assert g.has_node('E:1')

    assert len(g.in_edges('A:1')) == 3
Ejemplo n.º 6
0
def test_relabel_nodes():
    """
    Test relabelling of nodes in an NxGraph.
    """
    g = get_graphs()[1]
    m = {"A": "A:1", "E": "E:1"}
    NxGraph.relabel_nodes(g, m)
    assert not g.has_node("A")
    assert g.has_node("A:1")
    assert not g.has_node("E")
    assert g.has_node("E:1")

    assert len(g.in_edges("A:1")) == 3
Ejemplo n.º 7
0
def test_validator_explicit_biolink_version():
    """
    A fake test to establish a success condition for validation.
    """
    G = NxGraph()
    G.add_node(
        "CHEMBL.COMPOUND:1222250",
        id="CHEMBL.COMPOUND:1222250",
        name="Dextrose",
        category=["Carbohydrate"],
    )
    G.add_node(
        "UBERON:0000001", id="UBERON:0000001", name="fake", category=["NamedThing"]
    )
    G.add_edge(
        "CHEMBL.COMPOUND:1222250",
        "UBERON:0000001",
        id="CHEMBL.COMPOUND:1222250-part_of-UBERON:0000001",
        relation="RO:1",
        predicate="part_of",
        subject="CHEMBL.COMPOUND:1222250",
        object="UBERON:0000001",
        category=["biolink:Association"],
    )
    Validator.set_biolink_model(version="1.8.2")
    validator = Validator(verbose=True)
    validator.validate(G)
    print(validator.get_errors())
    assert len(validator.get_errors()) == 0
Ejemplo n.º 8
0
def test_set_edge_attributes():
    """
    Test setting edge attributes in bulk.
    """
    g = NxGraph()
    g.add_node("X:1", alias="A:1")
    g.add_node("X:2", alias="B:2")
    g.add_edge("X:2", 'X:1', edge_key='edge1', source="Source 1")
    d = {('X:2', 'X:1', 'edge1'): {'source': 'Modified Source 1'}}
    NxGraph.set_edge_attributes(g, d)
    e = list(g.edges(keys=True, data=True))[0]
    assert e[3]['source'] == 'Modified Source 1'
Ejemplo n.º 9
0
def test_set_edge_attributes():
    """
    Test setting edge attributes in bulk.
    """
    g = NxGraph()
    g.add_node("X:1", alias="A:1")
    g.add_node("X:2", alias="B:2")
    g.add_edge("X:2", "X:1", edge_key="edge1", source="Source 1")
    d = {("X:2", "X:1", "edge1"): {"source": "Modified Source 1"}}
    NxGraph.set_edge_attributes(g, d)
    e = list(g.edges(keys=True, data=True))[0]
    assert e[3]["source"] == "Modified Source 1"
def test_clique_merge():
    """
    Test for clique merge.
    """
    input_args = {
        'filename': [
            os.path.join(RESOURCE_DIR, 'cm_nodes.csv'),
            os.path.join(RESOURCE_DIR, 'cm_edges.csv'),
        ],
        'format':
        'csv',
    }
    t = Transformer()
    t.transform(input_args)
    updated_graph, clique_graph = clique_merge(
        target_graph=t.store.graph,
        prefix_prioritization_map=prefix_prioritization_map)
    leaders = NxGraph.get_node_attributes(updated_graph, 'clique_leader')
    leader_list = list(leaders.keys())
    leader_list.sort()
    assert len(leader_list) == 2
    n1 = updated_graph.nodes()[leader_list[0]]
    assert n1['election_strategy'] == 'PREFIX_PRIORITIZATION'
    assert 'NCBIGene:100302240' in n1['same_as']
    assert 'ENSEMBL:ENSG00000284458' in n1['same_as']
    n2 = updated_graph.nodes()[leader_list[1]]
    assert n2['election_strategy'] == 'PREFIX_PRIORITIZATION'
    assert 'NCBIGene:8202' in n2['same_as']
    assert 'OMIM:601937' in n2['same_as']
    assert 'ENSEMBL:ENSG00000124151' not in n2['same_as']
Ejemplo n.º 11
0
def test_clique_merge():
    """
    Test for clique merge.
    """
    input_args = {
        "filename": [
            os.path.join(RESOURCE_DIR, "cm_nodes.csv"),
            os.path.join(RESOURCE_DIR, "cm_edges.csv"),
        ],
        "format": "csv",
    }
    t = Transformer()
    t.transform(input_args)
    updated_graph, clique_graph = clique_merge(
        target_graph=t.store.graph, prefix_prioritization_map=prefix_prioritization_map
    )
    leaders = NxGraph.get_node_attributes(updated_graph, "clique_leader")
    leader_list = list(leaders.keys())
    leader_list.sort()
    assert len(leader_list) == 2
    n1 = updated_graph.nodes()[leader_list[0]]
    assert n1["election_strategy"] == "PREFIX_PRIORITIZATION"
    assert "NCBIGene:100302240" in n1["same_as"]
    assert "ENSEMBL:ENSG00000284458" in n1["same_as"]
    n2 = updated_graph.nodes()[leader_list[1]]
    assert n2["election_strategy"] == "PREFIX_PRIORITIZATION"
    assert "NCBIGene:8202" in n2["same_as"]
    assert "OMIM:601937" in n2["same_as"]
    assert "ENSEMBL:ENSG00000124151" not in n2["same_as"]
Ejemplo n.º 12
0
def test_get_edge_attributes():
    """
    Test getting edge attributes in bulk.
    """
    g = get_graphs()[1]
    d = NxGraph.get_edge_attributes(g, 'relation')
    assert ('B', 'A', 'B-biolink:related_to-A') in d
    assert d[('B', 'A', 'B-biolink:related_to-A')] == 'biolink:related_to'
Ejemplo n.º 13
0
def test_get_node_attributes():
    """
    Test getting node attributes in bulk.
    """
    g = get_graphs()[1]
    d = NxGraph.get_node_attributes(g, 'name')
    assert 'A' in d and d['A'] == 'Node A'
    assert 'E' in d and d['E'] == 'Node E'
Ejemplo n.º 14
0
def test_get_node_attributes():
    """
    Test getting node attributes in bulk.
    """
    g = get_graphs()[1]
    d = NxGraph.get_node_attributes(g, "name")
    assert "A" in d and d["A"] == "Node A"
    assert "E" in d and d["E"] == "Node E"
Ejemplo n.º 15
0
def test_get_edge_attributes():
    """
    Test getting edge attributes in bulk.
    """
    g = get_graphs()[1]
    d = NxGraph.get_edge_attributes(g, "relation")
    assert ("B", "A", "B-biolink:related_to-A") in d
    assert d[("B", "A", "B-biolink:related_to-A")] == "biolink:related_to"
Ejemplo n.º 16
0
def test_validator_bad():
    """
    A fake test to establish a fail condition for validation.
    """
    G = NxGraph()
    G.add_node("x", foo=3)
    G.add_node("ZZZ:3", **{"nosuch": 1})
    G.add_edge("x", "y", **{"baz": 6})
    validator = Validator(verbose=True)
    validator.validate(G)
    assert len(validator.get_errors()) > 0
Ejemplo n.º 17
0
def test_validator_bad():
    """
    A fake test to establish a fail condition for validation.
    """
    G = NxGraph()
    G.add_node('x', foo=3)
    G.add_node('ZZZ:3', **{'nosuch': 1})
    G.add_edge('x', 'y', **{'baz': 6})
    validator = Validator(verbose=True)
    e = validator.validate(G)
    assert len(e) > 0
Ejemplo n.º 18
0
def test_add_node():
    """
    Test adding a node to an NxGraph.
    """
    g = NxGraph()
    g.add_node("A")
    g.add_node("A", name="Node A", description="Node A")
    assert g.has_node("A")
Ejemplo n.º 19
0
def test_add_node():
    """
    Test adding a node to an NxGraph.
    """
    g = NxGraph()
    g.add_node('A')
    g.add_node('A', name='Node A', description='Node A')
    assert g.has_node('A')
Ejemplo n.º 20
0
def test_merge_graphs():
    """
    Test for merging 3 graphs into one,
    while not preserving conflicting node and edge properties.
    """
    graphs = get_graphs()
    merged_graph = merge_graphs(NxGraph(), graphs)
    assert merged_graph.number_of_nodes() == 6
    assert merged_graph.number_of_edges() == 6
    assert merged_graph.name not in [x.name for x in graphs]
Ejemplo n.º 21
0
def test_add_node_attribute():
    """
    Test adding a node attribute to an NxGraph.
    """
    g = NxGraph()
    g.add_node('A')
    g.add_node_attribute('A', 'provided_by', 'test')
    n = g.get_node('A')
    assert 'provided_by' in n and n['provided_by'] == 'test'
Ejemplo n.º 22
0
def test_update_edge_attribute():
    """
    Test updating an edge attribute for an edge in an NxGraph.
    """
    g = NxGraph()
    g.add_edge('A', 'B', 'edge_ab')
    g.update_edge_attribute('A', 'B', 'edge_ab', 'source', 'test')
    e = g.get_edge('A', 'B', 'edge_ab')
    assert 'source' in e and e['source'] == 'test'
Ejemplo n.º 23
0
def test_update_edge_attribute():
    """
    Test updating an edge attribute for an edge in an NxGraph.
    """
    g = NxGraph()
    g.add_edge("A", "B", "edge_ab")
    g.update_edge_attribute("A", "B", "edge_ab", "source", "test")
    e = g.get_edge("A", "B", "edge_ab")
    assert "source" in e and e["source"] == "test"
Ejemplo n.º 24
0
def test_add_node_attribute():
    """
    Test adding a node attribute to an NxGraph.
    """
    g = NxGraph()
    g.add_node("A")
    g.add_node_attribute("A", "provided_by", "test")
    n = g.get_node("A")
    assert "provided_by" in n and n["provided_by"] == "test"
Ejemplo n.º 25
0
def test_update_node_attribute():
    """
    Test updating a node attribute for a node in an NxGraph.
    """
    g = NxGraph()
    g.add_node('A', name='A', description='Node A')
    g.update_node_attribute('A', 'description', 'Modified description')
    n = g.get_node('A')
    assert 'name' in n and n['name'] == 'A'
    assert 'description' in n and n['description'] == 'Modified description'
Ejemplo n.º 26
0
def test_update_node_attribute():
    """
    Test updating a node attribute for a node in an NxGraph.
    """
    g = NxGraph()
    g.add_node("A", name="A", description="Node A")
    g.update_node_attribute("A", "description", "Modified description")
    n = g.get_node("A")
    assert "name" in n and n["name"] == "A"
    assert "description" in n and n["description"] == "Modified description"
Ejemplo n.º 27
0
def test_add_edge_attribute():
    """
    Test adding an edge attribute to an NxGraph.
    """
    g = NxGraph()
    g.add_edge('A', 'B')
    g.add_edge_attribute('A', 'B', 'edge_ab', 'predicate',
                         'biolink:related_to')
Ejemplo n.º 28
0
def test_add_edge_attribute():
    """
    Test adding an edge attribute to an NxGraph.
    """
    g = NxGraph()
    g.add_edge("A", "B")
    g.add_edge_attribute("A", "B", "edge_ab", "predicate",
                         "biolink:related_to")
Ejemplo n.º 29
0
def test_set_node_attributes():
    """
    Test setting node attributes in bulk.
    """
    g = NxGraph()
    g.add_node("X:1", alias="A:1")
    g.add_node("X:2", alias="B:2")
    d = {'X:1': {'alias': 'ABC:1'}, 'X:2': {'alias': 'DEF:2'}}
    NxGraph.set_node_attributes(g, d)
Ejemplo n.º 30
0
def test_set_node_attributes():
    """
    Test setting node attributes in bulk.
    """
    g = NxGraph()
    g.add_node("X:1", alias="A:1")
    g.add_node("X:2", alias="B:2")
    d = {"X:1": {"alias": "ABC:1"}, "X:2": {"alias": "DEF:2"}}
    NxGraph.set_node_attributes(g, d)