コード例 #1
0
    def test_different_key_and_namespace(self):
        key, namespace, value = map(lambda _: n(), range(3))

        self.graph.annotation_curie.add(key)
        self.graph.add_increases(Protein(namespace='HGNC', name='YFG1'),
                                 Protein(namespace='HGNC', name='YFG'),
                                 citation=self.citation,
                                 evidence=self.evidence,
                                 annotations={
                                     key:
                                     Entity(namespace=namespace,
                                            identifier=value),
                                 })

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertEqual(1, self.graph.number_of_edges())

        expected_lines = [
            f'SET Citation = {{"{CITATION_TYPE_PUBMED}", "{self.citation}"}}\n',
            f'SET SupportingText = "{self.evidence}"',
            f'SET {key} = "{namespace}:{value}"',
            'p(HGNC:YFG1) increases p(HGNC:YFG)',
            f'UNSET {key}',
            'UNSET SupportingText',
            'UNSET Citation\n',
            ('#' * 80),
        ]

        self._help_check_lines(expected_lines)
コード例 #2
0
    def test_subject_activity_custom(self, mock):
        p1_name = n()
        p2_name = n()
        dummy_activity_namespace = n()
        dummy_activity_name = n()

        self.graph.add_increases(Protein(name=p1_name, namespace='HGNC'),
                                 Protein(name=p2_name, namespace='HGNC'),
                                 evidence=n(),
                                 citation=n(),
                                 subject_modifier=activity(
                                     name=dummy_activity_name,
                                     namespace=dummy_activity_namespace))

        make_dummy_namespaces(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        kin_list = self.manager.session.query(NamespaceEntry).filter(
            NamespaceEntry.name == dummy_activity_name).all()
        self.assertEqual(1, len(kin_list))

        kin = list(kin_list)[0]
        self.assertEqual(dummy_activity_name, kin.name)
コード例 #3
0
    def test_multiple_annotations(self):
        a1, v1, v2 = map(lambda _: n(), range(3))
        v1, v2 = sorted([v1, v2])

        self.graph.add_increases(Protein(namespace='HGNC', name='YFG1'),
                                 Protein(namespace='HGNC', name='YFG'),
                                 citation=self.citation,
                                 evidence=self.evidence,
                                 annotations={a1: {v1, v2}})

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertEqual(1, self.graph.number_of_edges())

        expected_lines = [
            'SET Citation = {{"PubMed", "{}"}}\n'.format(self.citation),
            'SET SupportingText = "{}"'.format(self.evidence),
            'SET {} = {{"{}", "{}"}}'.format(a1, v1, v2),
            'p(HGNC:YFG1) increases p(HGNC:YFG)',
            'UNSET {}'.format(a1),
            'UNSET SupportingText',
            'UNSET Citation\n',
            ('#' * 80),
        ]

        self._help_check_lines(expected_lines)
コード例 #4
0
ファイル: test_node_selection.py プロジェクト: plin1112/pybel
    def test_get_node_by_namespace(self):
        """Test getting nodes with a given namespace."""
        g = BELGraph()
        a = Protein(namespace='N1', name='a')
        b = Protein(namespace='N1', name='b')
        c = Protein(namespace='N2', name='c')
        d = Protein(namespace='N3', name='d')
        g.add_node_from_data(a)
        g.add_node_from_data(b)
        g.add_node_from_data(c)
        g.add_node_from_data(d)

        nodes = set(get_nodes_by_namespace(g, 'N1'))

        self.assertIn(a, nodes)
        self.assertIn(b, nodes)
        self.assertNotIn(c, nodes)
        self.assertNotIn(d, nodes)

        nodes = set(get_nodes_by_namespace(g, ('N1', 'N2')))

        self.assertIn(a, nodes)
        self.assertIn(b, nodes)
        self.assertIn(c, nodes)
        self.assertNotIn(d, nodes)
コード例 #5
0
ファイル: test_node_utils.py プロジェクト: pybel/pybel-tools
    def test_merge_nodes_by_name(self):
        graph = BELGraph()
        priority = ['ncbigene', 'hgnc']
        a_hgnc, a_entrez = [
            Protein(namespace=namespace, name='a')
            for namespace in ('hgnc', 'ncbigene')
        ]
        b = Protein('ncbigene', 'b')
        graph.add_increases(a_hgnc, b, citation=n(), evidence=n())
        graph.add_increases(a_entrez, b, citation=n(), evidence=n())

        self.assertEqual(3, graph.number_of_nodes())
        self.assertEqual(2, graph.number_of_edges())

        collapse_nodes_with_same_names(graph,
                                       priority=priority,
                                       use_tqdm=False)
        self.assertEqual(2,
                         graph.number_of_nodes(),
                         msg='Wrong number remaining nodes: {}'.format(
                             graph.nodes()))
        self.assertEqual(2,
                         graph.number_of_edges(),
                         msg=f'Wrong number remaining edges: {graph.edges()}')
        self.assertIn(a_entrez, graph, msg=f'Nodes: {list(graph)}')
        self.assertIn(b, graph)
        self.assertNotIn(a_hgnc, graph)
コード例 #6
0
 def setUp(self):
     self.g = BELGraph()
     self.g.annotation_pattern['Species'] = r'\d+'
     self.u = Protein(name='u', namespace='TEST')
     self.v = Protein(name='v', namespace='TEST')
     self.g.add_node_from_data(self.u)
     self.g.add_node_from_data(self.v)
コード例 #7
0
    def test_all_filter(self):
        graph = BELGraph()
        graph.add_increases(Protein(n(), n()),
                            Protein(n(), n()),
                            citation=n(),
                            evidence=n(),
                            annotations={'A': {'1', '2', '3'}})

        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2'}})))
        self.assertEqual(
            1,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'1', '2',
                                                               '3'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph,
                build_annotation_dict_all_filter({'A': {'1', '2', '3', '4'}})))
        self.assertEqual(
            0,
            count_passed_edge_filter(
                graph, build_annotation_dict_all_filter({'A': {'4'}})))
コード例 #8
0
    def test_mixed_1(self):
        """Test mixed having location and something else."""
        self.graph.add_increases(
            Protein(namespace='HGNC', name='CDC42'),
            Protein(namespace='HGNC', name='PAK2'),
            evidence=
            """Summary: PAK proteins, a family of serine/threonine p21-activating kinases, include PAK1, PAK2,
         PAK3 and PAK4. PAK proteins are critical effectors that link Rho GTPases to cytoskeleton reorganization
         and nuclear signaling. They serve as targets for the small GTP binding proteins Cdc42 and Rac and have
         been implicated in a wide range of biological activities. PAK4 interacts specifically with the GTP-bound
         form of Cdc42Hs and weakly activates the JNK family of MAP kinases. PAK4 is a mediator of filopodia
         formation and may play a role in the reorganization of the actin cytoskeleton. Multiple alternatively
         spliced transcript variants encoding distinct isoforms have been found for this gene.""",
            citation={
                CITATION_DB: "Online Resource",
                CITATION_IDENTIFIER: "PAK4 Hs ENTREZ Gene Summary"
            },
            annotations={'Species': '9606'},
            subject_modifier=activity('gtp'),
            object_modifier=activity('kin'),
        )

        make_dummy_namespaces(self.manager, self.graph)
        make_dummy_annotations(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        edge = network.edges.first()
コード例 #9
0
    def test_mixed_2(self):
        """Tests both subject and object activity with location information as well."""
        self.graph.add_directly_increases(
            Protein(namespace='HGNC', name='HDAC4'),
            Protein(namespace='HGNC', name='MEF2A'),
            citation='10487761',
            evidence=
            """"In the nucleus, HDAC4 associates with the myocyte enhancer factor MEF2A. Binding of HDAC4 to
        MEF2A results in the repression of MEF2A transcriptional activation, a function that requires the
        deacetylase domain of HDAC4.""",
            annotations={'Species': '9606'},
            subject_modifier=activity('cat',
                                      location=Entity(namespace='GO',
                                                      name='nucleus')),
            object_modifier=activity('tscript',
                                     location=Entity(namespace='GO',
                                                     name='nucleus')))

        make_dummy_namespaces(self.manager, self.graph)
        make_dummy_annotations(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        edge = network.edges.first()
コード例 #10
0
    def test_subject_activity_default(self, mock):
        p1_name = n()
        p2_name = n()

        self.graph.add_increases(Protein(name=p1_name, namespace='HGNC'),
                                 Protein(name=p2_name, namespace='HGNC'),
                                 evidence=n(),
                                 citation=n(),
                                 subject_modifier=activity('kin'))

        make_dummy_namespaces(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count(), msg='number of nodes')
        self.assertEqual(1, network.edges.count(), msg='number of edges')

        kin_list = self.manager.session.query(NamespaceEntry).filter(
            NamespaceEntry.name == 'kin').all()
        self.assertEqual(1,
                         len(kin_list),
                         msg='number of kinase NamespaceEntrys')

        kin = list(kin_list)[0]
        self.assertEqual('kin', kin.name)

        effects = self.manager.session.query(Property).join(
            NamespaceEntry).filter(Property.effect == kin)
        self.assertEqual(1, effects.count(), msg='number of effects')
コード例 #11
0
    def test_single_annotation(self):
        """Tests a scenario with a qualified edge, but no annotaitons"""
        a1, v1 = map(lambda _: n(), range(2))

        self.graph.add_increases(Protein(namespace='HGNC', name='YFG1'),
                                 Protein(namespace='HGNC', name='YFG'),
                                 citation=self.citation,
                                 evidence=self.evidence,
                                 annotations={a1: {v1}})

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertEqual(1, self.graph.number_of_edges())

        expected_lines = [
            'SET Citation = {{"PubMed", "{}"}}\n'.format(self.citation),
            'SET SupportingText = "{}"'.format(self.evidence),
            'SET {} = "{}"'.format(a1, v1),
            'p(HGNC:YFG1) increases p(HGNC:YFG)',
            'UNSET {}'.format(a1),
            'UNSET SupportingText',
            'UNSET Citation\n',
            '#' * 80,
        ]

        self._help_check_lines(expected_lines)
コード例 #12
0
    def test_single_annotation(self):
        """Test a scenario with a qualified edge, but no annotations."""
        a1, v1 = map(lambda _: n(), range(2))
        self.graph.annotation_list[a1] = {v1}
        self.graph.add_increases(Protein(namespace='HGNC', name='YFG1'),
                                 Protein(namespace='HGNC', name='YFG'),
                                 citation=self.citation,
                                 evidence=self.evidence,
                                 annotations={
                                     a1: {v1},
                                 })

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertEqual(1, self.graph.number_of_edges())

        # Means that only the identifier needs to be written out
        self.assertNotIn(a1, self.graph.annotation_curie)

        expected_lines = [
            f'SET Citation = {{"{CITATION_TYPE_PUBMED}", "{self.citation}"}}\n',
            f'SET SupportingText = "{self.evidence}"',
            f'SET {a1} = "{v1}"',
            'p(HGNC:YFG1) increases p(HGNC:YFG)',
            f'UNSET {a1}',
            'UNSET SupportingText',
            'UNSET Citation\n',
            '#' * 80,
        ]

        self._help_check_lines(expected_lines)
コード例 #13
0
    def test_complex_with_name(self):
        """Test what happens with a named complex.

        .. code-block::

            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:HUS1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD9A)

        """
        hus1 = Protein(namespace='HGNC', name='HUS1')
        rad1 = Protein(namespace='HGNC', name='RAD1')
        rad9a = Protein(namespace='HGNC', name='RAD9A')
        members = [hus1, rad1, rad9a]

        nine_one_one = ComplexAbundance(members=members,
                                        namespace='SCOMP',
                                        name='9-1-1 Complex')

        graph = BELGraph()

        graph.add_node_from_data(nine_one_one)
        self.assertIn(nine_one_one, graph)
        self.assertIn(hus1, graph)
        self.assertIn(rad1, graph)
        self.assertIn(rad9a, graph)
コード例 #14
0
    def test_multiple_annotations(self):
        a1, v1, v2 = map(lambda _: n(), range(3))
        v1, v2 = sorted([v1, v2])

        self.graph.annotation_list[a1] = {v1, v2}
        self.graph.add_increases(Protein(namespace='HGNC', name='YFG1'),
                                 Protein(namespace='HGNC', name='YFG'),
                                 citation=self.citation,
                                 evidence=self.evidence,
                                 annotations={
                                     a1: {v1, v2},
                                 })

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertEqual(1, self.graph.number_of_edges())

        expected_lines = [
            f'SET Citation = {{"{CITATION_TYPE_PUBMED}", "{self.citation}"}}\n',
            f'SET SupportingText = "{self.evidence}"',
            f'SET {a1} = {{"{v1}", "{v2}"}}',
            'p(HGNC:YFG1) increases p(HGNC:YFG)',
            f'UNSET {a1}',
            'UNSET SupportingText',
            'UNSET Citation\n',
            ('#' * 80),
        ]

        self._help_check_lines(expected_lines)
コード例 #15
0
 def test_get_parent(self):
     """Test the get_parent function in :class:`CentralDogmaAbundance`s."""
     ab42 = Protein(name='APP',
                    namespace='HGNC',
                    variants=[Fragment(start=672, stop=713)])
     app = ab42.get_parent()
     self.assertEqual('p(HGNC:APP)', app.as_bel())
     self.assertEqual('p(HGNC:APP, frag("672_713"))', ab42.as_bel())
コード例 #16
0
ファイル: test_enrich.py プロジェクト: bio2bel/excape
 def setUp(self):
     self.graph: BELGraph = BELGraph()
     test_chem: Abundance = Abundance('INCHIKEY', 'AAAAZQPHATYWOK-YRBRRWAQNA-N')
     test_chem2: Abundance = Abundance('INCHIKEY', 'AAABHMIRDIOYOK-NPVYFSBINA-N')
     self.graph.add_node_from_data(test_chem)
     self.graph.add_node_from_data(test_chem2)
     test_target: Protein = Protein('EGID', '2740')
     test_target2: Protein = Protein('EGID', '2778')
     self.graph.add_node_from_data(test_target)
     self.graph.add_node_from_data(test_target2)
コード例 #17
0
    def test_any_filter(self):
        graph = BELGraph()
        graph.annotation_list['A'] = set('12345')
        graph.add_increases(Protein(n(), n()), Protein(n(), n()), citation=n(), evidence=n(), annotations={
            'A': {'1', '2', '3'}
        })

        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1'}}))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1', '2'}}))))
        self.assertEqual(1, count_passed_edge_filter(graph, build_annotation_dict_any_filter(graph._clean_annotations({'A': {'1', '2', '3'}}))))
コード例 #18
0
    def test_binds(self):
        """Test the ``binds`` relation."""
        statement = 'p(HGNC:X) binds p(HGNC:Y)'
        self.parser.relation.parseString(statement)

        source = Protein('HGNC', 'X')
        target = Protein('HGNC', 'Y')
        x_y_complex = ComplexAbundance([source, target])
        self.assert_has_node(x_y_complex)
        self.assert_has_edge(source, x_y_complex, relation=PART_OF)
        self.assert_has_edge(target, x_y_complex, relation=PART_OF)
コード例 #19
0
 def test_all_filter_no_query(self):
     """Test that the all filter returns true when there's no argument"""
     graph = BELGraph()
     graph.add_increases(Protein(n(), n()),
                         Protein(n(), n()),
                         citation=n(),
                         evidence=n())
     self.assertEqual(
         1,
         count_passed_edge_filter(graph,
                                  build_annotation_dict_all_filter({})))
コード例 #20
0
ファイル: test_import.py プロジェクト: djinnome/pybel
    def test_bep_0008(self):
        """Test parsing works right"""
        graph = from_bel_script(test_bel_with_obo)
        self.assertIn('hgnc', graph.namespace_pattern)
        self.assertEqual(r'\d+', graph.namespace_pattern['hgnc'])

        self.assertEqual(0, graph.number_of_warnings(), msg=',\n'.join(map(str, graph.warnings)))

        self.assertEqual(2, graph.number_of_nodes())
        self.assertIn(Protein(namespace='hgnc', identifier='391', name='AKT1'), graph)
        self.assertIn(Protein(namespace='hgnc', identifier='3236', name='EGFR'), graph)
コード例 #21
0
    def test_named_complex(self):
        x = ComplexAbundance(namespace='a',
                             identifier='b',
                             members=[
                                 Protein(namespace='c', identifier='d'),
                                 Protein(namespace='c', identifier='e'),
                             ])

        y = parse_result_to_dsl(dict(x))
        self.assertIsInstance(y, ComplexAbundance)
        self.assertIn(pc.MEMBERS, y)
        self.assertIn(pc.CONCEPT, y)
コード例 #22
0
    def test_direct_has_namespace(self):
        graph = BELGraph()

        n1 = Protein(namespace='HGNC', name='CD33', identifier='1659')
        n2 = Protein(namespace='NOPE', name='NOPE', identifier='NOPE')

        graph.add_increases(n1, n2, citation=n(), evidence=n())

        self.assertEqual({n1}, graph.get_equivalent_nodes(n1))

        self.assertTrue(graph.node_has_namespace(n1, 'HGNC'))
        self.assertFalse(graph.node_has_namespace(n2, 'HGNC'))
コード例 #23
0
ファイル: test_mapping.py プロジェクト: pybel/pybel-tools
    def test_variants_mapping(self):
        graph = BELGraph()

        app = Protein(HGNC, 'APP')
        app_fragment = app.with_variants(Fragment('1_49'))
        graph.add_node_from_data(app_fragment)

        mapped_nodes = get_mapped_nodes(graph, HGNC, {'APP'})

        self.assertEqual(1, len(mapped_nodes))
        self.assertIn(app, mapped_nodes)
        self.assertEqual({app_fragment}, mapped_nodes[app])
コード例 #24
0
    def test_indirect_has_namespace(self):
        graph = BELGraph()

        a = Protein(namespace='HGNC', name='CD33')
        b = Protein(namespace='HGNCID', identifier='1659')

        graph.add_equivalence(a, b)

        self.assertEqual({a, b}, graph.get_equivalent_nodes(a))
        self.assertEqual({a, b}, graph.get_equivalent_nodes(b))

        self.assertTrue(graph.node_has_namespace(a, 'HGNC'))
        self.assertTrue(graph.node_has_namespace(b, 'HGNC'))
コード例 #25
0
    def test_missing_information(self):
        """Test that entity and abundance functions raise on missing name/identifier."""
        with self.assertRaises(ValueError):
            Entity(namespace='test')

        with self.assertRaises(ValueError):
            Protein(namespace='test')

        with self.assertRaises(ValueError):
            Protein(namespace='')

        with self.assertRaises(TypeError):
            Protein(namespace='uniprot', name=1234)

        with self.assertRaises(TypeError):
            Protein(namespace='uniprot', identifier=1234)

        with self.assertRaises(ValueError):
            Protein(namespace='uniprot', name='')

        with self.assertRaises(ValueError):
            Protein(namespace='uniprot', identifier='')

        with self.assertRaises(ValueError):
            Protein(namespace='uniprot', identifier='12345', name='')

        with self.assertRaises(ValueError):
            Protein(namespace='uniprot', identifier='', name='123')
コード例 #26
0
 def test_fragment_specified_end_only(self, mock):
     dummy_namespace = n()
     dummy_name = n()
     node_data = Protein(namespace=dummy_namespace,
                         name=dummy_name,
                         variants=[Fragment(start='*', stop=1000)])
     self._help_reconstitute(node_data, 2, 1)
コード例 #27
0
    def test_object_degradation(self):
        self.graph.add_increases(
            Protein(name='YFG', namespace='HGNC'),
            Protein(name='YFG2', namespace='HGNC'),
            evidence=n(),
            citation=n(),
            object_modifier=degradation(),
        )
        make_dummy_namespaces(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)

        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        edge = network.edges.first()
コード例 #28
0
 def test_protein_pmod(self):
     node = Protein(name='PLCG1',
                    namespace='HGNC',
                    variants=[ProteinModification(name='Ph', code='Tyr')])
     self.assertEqual(
         'p(HGNC:PLCG1, pmod(go:0006468 ! "protein phosphorylation", Tyr))',
         str(node))
コード例 #29
0
    def test_composite(self):
        il23 = NamedComplexAbundance(namespace='GO',
                                     name='interleukin-23 complex')
        il6 = Protein(namespace='HGNC', name='IL6')
        node_data = CompositeAbundance([il23, il6])

        self.graph.add_node_from_data(node_data)
        self.assertIn(node_data, self.graph)
        self.assertEqual(3, self.graph.number_of_nodes())
        self.assertIn(il6,
                      self.graph,
                      msg='Nodes:\n'.format('\n'.join(map(str, self.graph))))
        self.assertIn(il23, self.graph)
        self.assertEqual(2, self.graph.number_of_edges())

        self.assertIn(node_data, self.graph[il6])
        edges = list(self.graph[il6][node_data].values())
        self.assertEqual(1, len(edges))
        data = edges[0]
        self.assertEqual(PART_OF, data[RELATION])

        self.assertIn(node_data, self.graph[il23])
        edges = list(self.graph[il23][node_data].values())
        self.assertEqual(1, len(edges))
        data = edges[0]
        self.assertEqual(PART_OF, data[RELATION])
コード例 #30
0
 def test_fragment_unspecified(self, mock):
     dummy_namespace = n()
     dummy_name = n()
     node_data = Protein(namespace=dummy_namespace,
                         name=dummy_name,
                         variants=[Fragment()])
     self._help_reconstitute(node_data, 2, 1)