Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super(TestCascades, self).setUp()
self.n1 = Node._start_from_base_entity(yfg1)
self.n2 = Node._start_from_base_entity(yfg2)
self.n3 = Node._start_from_base_entity(yfg3)
self.e1 = make_increase_edge(self.n1, self.n2)
self.e2 = make_increase_edge(self.n2, self.n3)
self.e3 = make_increase_edge(self.n1, self.n3)
self.g1 = Network(name=n(), version=n(), edges=[self.e1, self.e2, self.e3])
self.g2 = Network(name=n(), version=n(), edges=[self.e1])
self.manager.session.add_all([self.n1, self.n2, self.n3, self.e1, self.e2, self.e3, self.g1, self.g2])
self.manager.session.commit()
self.assertEqual(3, self.manager.count_nodes())
self.assertEqual(3, self.manager.count_edges())
self.assertEqual(2, self.manager.count_networks())
def test_get_upstream_causal_subgraph(self):
"""Test get_upstream_causal_subgraph."""
a, b, c, d, e, f = [protein(namespace='test', name=n()) for _ in range(6)]
universe = BELGraph()
universe.namespace_pattern['test'] = 'test-url'
universe.add_increases(a, b, citation=n(), evidence=n())
universe.add_increases(b, c, citation=n(), evidence=n())
universe.add_association(d, a, citation=n(), evidence=n())
universe.add_increases(e, a, citation=n(), evidence=n())
universe.add_decreases(f, b, citation=n(), evidence=n())
subgraph = get_upstream_causal_subgraph(universe, [a, b])
self.assertIsInstance(subgraph, BELGraph)
self.assert_all_nodes_are_base_entities(subgraph)
self.assertIn('test', subgraph.namespace_pattern)
self.assertEqual('test-url', subgraph.namespace_pattern['test'])
self.assertIn(a, subgraph)
self.assertIn(b, subgraph)
self.assertNotIn(c, subgraph)
self.assertNotIn(d, subgraph)
self.assertIn(e, subgraph)
def help_test_convert(
self,
converter: Type[Converter],
u: BaseEntity,
v: BaseEntity,
edge_data: EdgeData,
triple: Tuple[str, str, str],
) -> None:
"""Test a converter class."""
self.assertTrue(issubclass(converter, Converter), msg='Not a Converter: {}'.format(converter.__name__))
key = n()
self.assertTrue(
converter.predicate(u, v, key, edge_data),
msg='Predicate failed: {}'.format(converter.__name__),
)
self.assertEqual(
triple,
converter.convert(u, v, key, edge_data),
msg='Conversion failed: {}'.format(converter.__name__),
)
graph = BELGraph()
graph.add_edge(u, v, key=key, **edge_data)
self.assertEqual(
triple,
get_triple(graph, u, v, key),
msg='get_triple failed: {}'.format(converter.__name__),
)
def test_get_top_hubs(self):
"""Test counting pathologies in the graph."""
graph = BELGraph()
a, b, c = protein(n(), n()), protein(n(), n()), pathology(n(), n())
graph.add_association(a, b, citation=n(), evidence=n())
graph.add_association(a, c, citation=n(), evidence=n())
top_hubs = get_top_hubs(graph, n=1)
self.assertEqual(1, len(top_hubs))
node, degree = top_hubs[0]
self.assertEqual(a, node)
self.assertEqual(4, degree) # higher than expected because association edges
def test_build_author_inclusion_filter(self):
"""Test getting a sub-graph by a single author."""
a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)]
a1, a2, a3, a4, a5 = n(), n(), n(), n(), n()
c1 = {
CITATION_TYPE: CITATION_TYPE_PUBMED,
CITATION_REFERENCE: n(),
CITATION_AUTHORS: [a1, a2, a3]
}
c2 = {
CITATION_TYPE: CITATION_TYPE_PUBMED,
CITATION_REFERENCE: n(),
CITATION_AUTHORS: [a1, a4]
}
graph = BELGraph()
keyword, url = n(), n()
graph.namespace_url[keyword] = url
graph.add_increases(a, b, evidence=n(), citation=c1)
graph.add_increases(a, b, evidence=n(), citation=c2)
graph.add_increases(b, c, evidence=n(), citation=c1)
graph.add_increases(c, d, evidence=n(), citation=c2)
subgraph1 = get_subgraph_by_authors(graph, a1)
self.assertIsInstance(subgraph1, BELGraph)
self.assert_all_nodes_are_base_entities(subgraph1)
def test_build_author_set_inclusion_filter(self):
"""Test getting a sub-graph by a set of authors."""
a, b, c, d = [protein(namespace='test', name=n()) for _ in range(4)]
a1, a2, a3, a4 = n(), n(), n(), n()
c1 = {
CITATION_TYPE: CITATION_TYPE_PUBMED,
CITATION_REFERENCE: n(),
CITATION_AUTHORS: [a1, a2, a3]
}
c2 = {
CITATION_TYPE: CITATION_TYPE_PUBMED,
CITATION_REFERENCE: n(),
CITATION_AUTHORS: [a1, a4]
}
graph = BELGraph()
keyword, url = n(), n()
graph.namespace_url[keyword] = url
graph.add_increases(a, b, evidence=n(), citation=c1)
def test_pmod_default_full(self, mock):
dummy_namespace = n()
dummy_name = n()
node_data = Protein(namespace=dummy_namespace, name=dummy_name,
variants=[ProteinModification('Me', code='Ser', position=5)])
self._help_reconstitute(node_data, 2, 1)
from pybel.manager import models
from pybel.manager.models import Author, Citation, Edge, Evidence, NamespaceEntry, Node
from pybel.testing.cases import FleetingTemporaryCacheMixin, TemporaryCacheClsMixin, TemporaryCacheMixin
from pybel.testing.constants import test_bel_simple
from pybel.testing.mocks import mock_bel_resources
from pybel.testing.utils import make_dummy_annotations, make_dummy_namespaces, n
from tests.constants import (
BelReconstitutionMixin, akt1, casp8, egfr, expected_test_simple_metadata, fadd, test_citation_dict,
test_evidence_text,
)
fos = hgnc(name='FOS')
jun = hgnc(name='JUN')
mirna_1 = mirbase(name=n())
mirna_2 = mirbase(name=n())
pathology_1 = Pathology('DO', n())
ap1_complex = ComplexAbundance([fos, jun])
egfr_dimer = ComplexAbundance([egfr, egfr])
yfg_data = hgnc(name='YFG')
e2f4_data = hgnc(name='E2F4')
bound_ap1_e2f4 = ComplexAbundance([ap1_complex, e2f4_data])
superoxide = chebi(name='superoxide')
hydrogen_peroxide = chebi(name='hydrogen peroxide')
oxygen = chebi(name='oxygen')
superoxide_decomposition = Reaction(reactants=[superoxide], products=[hydrogen_peroxide, oxygen])
def assert_unqualified_edge(test_case, u: BaseEntity, v: BaseEntity, rel: str) -> None:
"""Assert there's only one edge and get the data for it"""
def test_build_pmid_set_inclusion_filter(self):
"""Test getting a sub-graph by a set of PubMed identifiers."""
a, b, c, d, e, f = [protein(namespace='test', name=n()) for _ in range(6)]
p1, p2, p3, p4, p5, p6 = n(), n(), n(), n(), n(), n()
graph = BELGraph()
keyword, url = n(), n()
graph.namespace_url[keyword] = url
graph.add_increases(a, b, evidence=n(), citation=p1)
graph.add_increases(a, b, evidence=n(), citation=p2)
graph.add_increases(b, c, evidence=n(), citation=p1)
graph.add_increases(b, c, evidence=n(), citation=p3)
graph.add_increases(c, d, evidence=n(), citation=p3)
graph.add_increases(e, f, evidence=n(), citation=p4)
subgraph = get_subgraph_by_pubmed(graph, [p1, p4])
self.assertIsInstance(subgraph, BELGraph)
self.assert_all_nodes_are_base_entities(subgraph)