Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_add_node_with_variant(self):
"""Test that the identifier is carried through to the child."""
graph = BELGraph()
namespace, name, identifier, variant_name = n(), n(), n(), n()
node = protein(namespace=namespace, name=name, identifier=identifier, variants=hgvs(variant_name))
node.get_parent()
graph.add_node_from_data(node)
self.assertEqual(2, graph.number_of_nodes())
def test_object_activity_custom(self, mock):
p1_name = n()
p2_name = n()
dummy_activity_namespace = n8()
dummy_activity_name = n()
self.graph.add_qualified_edge(
protein(name=p1_name, namespace='HGNC'),
protein(name=p2_name, namespace='HGNC'),
evidence=n(),
citation=n(),
relation=INCREASES,
object_modifier=activity(name=dummy_activity_name, namespace=dummy_activity_namespace)
)
make_dummy_namespaces(self.manager, self.graph, {
'HGNC': [p1_name, p2_name], dummy_activity_namespace: [dummy_activity_name]
})
network = self.manager.insert_graph(self.graph, store_parts=True)
self.assertEqual(2, network.nodes.count())
self.assertEqual(1, network.edges.count())
kin_list = self.manager.session.query(models.NamespaceEntry).filter(
from pybel.struct.filters.edge_predicates import (
edge_has_activity, edge_has_annotation, edge_has_degradation,
edge_has_translocation, has_authors, has_polarity, has_provenance, has_pubmed, is_associative_relation,
is_causal_relation, is_direct_causal_relation,
)
from pybel.struct.filters.node_predicates import (
has_activity, has_causal_in_edges, has_causal_out_edges, has_fragment,
has_gene_modification, has_hgvs, has_protein_modification, has_variant, is_abundance, is_causal_central,
is_causal_sink, is_causal_source, is_degraded, is_gene, is_pathology, is_protein, is_translocated,
keep_node_permissive, node_exclusion_predicate_builder, node_inclusion_predicate_builder, not_pathology,
)
from pybel.testing.utils import n
p1 = protein(name='BRAF', namespace='HGNC')
p2 = protein(name='BRAF', namespace='HGNC', variants=[hgvs('p.Val600Glu'), pmod('Ph')])
p3 = protein(name='APP', namespace='HGNC', variants=fragment(start=672, stop=713))
p4 = protein(name='2', namespace='HGNC')
g1 = gene(name='BRAF', namespace='HGNC', variants=gmod('Me'))
class TestNodePredicates(unittest.TestCase):
"""Tests for node predicates."""
def test_none_data(self):
"""Test permissive node predicate with a node data dictionary."""
self.assertTrue(keep_node_permissive(p1))
def test_none(self):
"""Test permissive node predicate with graph and tuple."""
g = BELGraph()
g.add_node_from_data(p1)
def test_protein_fragment_descriptor(self):
"""2.2.3 fragment with unknown start/stop and a descriptor"""
statement = 'p(HGNC:YFG, frag(?, "55kD"))'
result = self.parser.protein.parseString(statement)
parent = protein('HGNC', 'YFG')
expected_node = parent.with_variants(fragment('?', description='55kD'))
self.assert_has_node(expected_node)
self.assertEqual('p(HGNC:YFG, frag("?", "55kD"))', self.graph.node_to_bel(expected_node))
self.assert_has_node(parent)
self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
def test_get_subgraph_by_annotation_value(self):
"""Test getting a subgraph by a single annotation value."""
graph = BELGraph()
a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)]
k1 = graph.add_increases(a, b, citation=n(), evidence=n(), annotations={
'Subgraph': {'A'}
})
k2 = graph.add_increases(a, b, citation=n(), evidence=n(), annotations={
'Subgraph': {'B'}
})
k3 = graph.add_increases(a, b, citation=n(), evidence=n(), annotations={
'Subgraph': {'A', 'C', 'D'}
})
subgraph = get_subgraph_by_annotation_value(graph, 'Subgraph', 'A')
self.assertIsInstance(subgraph, BELGraph)
def test_translocation_secretion(self):
"""cell secretion short form"""
statement = 'sec(p(HGNC:EGFR))'
result = self.parser.transformation.parseString(statement)
expected_result = [CELL_SECRETION, PROTEIN, ['HGNC', 'EGFR']]
self.assertEqual(expected_result, result.asList())
mod = modifier_po_to_dict(result)
expected_mod = secretion()
self.assertEqual(expected_mod, mod)
node = protein('HGNC', 'EGFR')
self.assert_has_node(node)
def test_strip_annotations(self):
"""Test the strip_annotation function."""
x = protein(namespace='HGNC', name='X')
y = protein(namespace='HGNC', name='X')
graph = BELGraph()
key = graph.add_increases(
x,
y,
citation='123456',
evidence='Fake',
annotations={
'A': {'B': True}
},
)
self.assertIn(ANNOTATIONS, graph[x][y][key])
strip_annotations(graph)
def test_fragment_specified_start_only(self, mock):
dummy_namespace = n8()
dummy_name = n()
node_data = protein(namespace=dummy_namespace, name=dummy_name, variants=[fragment(start=5, stop='*')])
namespaces = {dummy_namespace: [dummy_name]}
self.help_reconstitute(node_data, namespaces, 2, 1)
result = self.parser.relation.parseString(statement)
expected_result = [
[PROTEIN, ['FPLX', 'PKC']],
'hasMembers',
[
[PROTEIN, ['HGNC', 'PRKCA']],
[PROTEIN, ['HGNC', 'PRKCB']],
[PROTEIN, ['HGNC', 'PRKCD']],
[PROTEIN, ['HGNC', 'PRKCE']],
]
]
self.assertEqual(expected_result, result.asList())
sub = protein('FPLX', 'PKC')
obj_1 = protein('HGNC', 'PRKCA')
obj_2 = protein('HGNC', 'PRKCB')
obj_3 = protein('HGNC', 'PRKCD')
obj_4 = protein('HGNC', 'PRKCE')
self.assert_has_node(sub)
self.assert_has_node(obj_1)
self.assert_has_edge(obj_1, sub, relation=IS_A)
self.assert_has_node(obj_2)
self.assert_has_edge(obj_2, sub, relation=IS_A)
self.assert_has_node(obj_3)
self.assert_has_edge(obj_3, sub, relation=IS_A)
self.assert_has_node(obj_4)
self.assert_has_edge(obj_4, sub, relation=IS_A)
def test_protein_fragment_known(self):
"""2.2.3 fragment with known start/stop"""
statement = 'p(HGNC:YFG, frag(5_20))'
self.parser.protein.parseString(statement)
parent = protein('HGNC', 'YFG')
expected_node = parent.with_variants(fragment(5, 20))
self.assert_has_node(expected_node)
self.assertEqual('p(HGNC:YFG, frag("5_20"))', self.graph.node_to_bel(expected_node))
self.assert_has_node(parent)
self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)