Пример #1
0
    def test_causalr_rank_hypothesis_1(self):
        test_network = self.network4  # Defined in test.constants.TestNetworks

        observed_regulation_test = {
            protein(HGNC, 'a'): 0,
            protein(HGNC, 'b'): 1,
            gene(HGNC, 'c'): -1,
            rna(HGNC, 'd'): -1,
            protein(HGNC, 'e'): -1,
            gene(HGNC, 'f'): 1,
            protein(HGNC, 'g'): 1,
            protein(HGNC, 'h'): 1,
            protein(HGNC, 'i'): 1,
            protein(HGNC, 'j'): 1
        }

        upregulated_hypothesis, downregulated_hypothesis = rank_causalr_hypothesis(
            graph=test_network,
            node_to_regulation=observed_regulation_test,
            regulator_node=protein(HGNC, 'a'))

        self.assertEqual(5, upregulated_hypothesis['score'])
        self.assertEqual(6, upregulated_hypothesis['correct'])
        self.assertEqual(
            1, upregulated_hypothesis['incorrect'])  # 1 gene( HGNC, 'f')
        self.assertEqual(
            1, upregulated_hypothesis['ambiguous'])  # 1 gene( HGNC, 'h')
Пример #2
0
    def test_annotations_with_multilist(self):
        self.add_default_provenance()

        statements = [
            'SET TestAnnotation1 = {"A","B"}', 'SET TestAnnotation2 = "X"',
            'SET TestAnnotation3 = {"D","E"}', 'g(TESTNS:1) -> g(TESTNS:2)'
        ]
        self.parser.parse_lines(statements)

        test_node_1_dict = gene(namespace='TESTNS', name='1')
        test_node_2_dict = gene(namespace='TESTNS', name='2')

        self.assertEqual(2, self.parser.graph.number_of_nodes())
        self.assertIn(test_node_1_dict, self.graph)
        self.assertIn(test_node_2_dict, self.graph)

        self.assertEqual(1, self.parser.graph.number_of_edges())

        kwargs = {
            ANNOTATIONS: {
                'TestAnnotation1': {
                    'A': True,
                    'B': True
                },
                'TestAnnotation2': {
                    'X': True
                },
                'TestAnnotation3': {
                    'D': True,
                    'E': True
                }
            },
            CITATION: test_citation_dict
        }
        self.assert_has_edge(test_node_1_dict, test_node_2_dict, **kwargs)
Пример #3
0
 def test_gene_fusion_missing_implicit(self):
     """Test serialization of a gene fusion to BEL with a implicit missing fusion ranges."""
     dsl = gene_fusion(
         gene('HGNC', 'TMPRSS2'),
         gene('HGNC', 'ERG'),
     )
     self.assertEqual('g(fus(HGNC:TMPRSS2, "?", HGNC:ERG, "?"))', dsl.as_bel())
Пример #4
0
    def test_equivalentTo(self):
        statement = 'g(dbSNP:"rs123456") eq g(HGNC:YFG, var(c.123G>A))'
        result = self.parser.relation.parseString(statement)

        expected_result = {
            SUBJECT: {
                FUNCTION: GENE,
                NAMESPACE: 'dbSNP',
                NAME: 'rs123456',
            },
            RELATION: EQUIVALENT_TO,
            OBJECT: {
                FUNCTION: GENE,
                NAMESPACE: 'HGNC',
                NAME: 'YFG',
                VARIANTS: [{
                    KIND: HGVS,
                    IDENTIFIER: 'c.123G>A'
                }]
            }
        }
        self.assertEqual(expected_result, result.asDict())

        sub = gene('dbSNP', 'rs123456')
        self.assert_has_node(sub)

        obj = gene('HGNC', 'YFG', variants=hgvs('c.123G>A'))
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, **{RELATION: EQUIVALENT_TO})
        self.assert_has_edge(obj, sub, **{RELATION: EQUIVALENT_TO})
Пример #5
0
    def test_annotations(self):
        self.add_default_provenance()

        statements = [
            'SET TestAnnotation1 = "A"', 'SET TestAnnotation2 = "X"',
            'g(TESTNS:1) -> g(TESTNS:2)'
        ]

        self.parser.parse_lines(statements)

        test_node_1 = gene(namespace='TESTNS', name='1')
        test_node_2 = gene(namespace='TESTNS', name='2')

        self.assertEqual(2, self.graph.number_of_nodes())
        self.assertIn(test_node_1, self.graph)
        self.assertIn(test_node_2, self.graph)

        self.assertEqual(1, self.parser.graph.number_of_edges())

        kwargs = {
            ANNOTATIONS: {
                'TestAnnotation1': {
                    'A': True
                },
                'TestAnnotation2': {
                    'X': True
                },
            },
            EVIDENCE: test_evidence_text,
            CITATION: test_citation_dict
        }
        self.assert_has_edge(test_node_1, test_node_2, **kwargs)
Пример #6
0
    def test_annotations_with_list(self):
        self.add_default_provenance()

        statements = [
            'SET TestAnnotation1 = {"A","B"}', 'SET TestAnnotation2 = "X"',
            'g(TESTNS:1) -> g(TESTNS:2)'
        ]
        self.parser.parse_lines(statements)

        test_node_1_dict = gene(namespace='TESTNS', name='1')
        test_node_2_dict = gene(namespace='TESTNS', name='2')

        self.assertEqual(2, self.parser.graph.number_of_nodes())
        self.assertTrue(self.parser.graph.has_node_with_data(test_node_1_dict))
        self.assertTrue(self.parser.graph.has_node_with_data(test_node_2_dict))

        test_node_1 = test_node_1_dict.as_tuple()
        test_node_2 = test_node_2_dict.as_tuple()

        self.assertEqual(1, self.parser.graph.number_of_edges())

        kwargs = {
            ANNOTATIONS: {
                'TestAnnotation1': {
                    'A': True,
                    'B': True
                },
                'TestAnnotation2': {
                    'X': True
                }
            },
            CITATION: test_citation_dict
        }
        self.assertHasEdge(test_node_1, test_node_2, **kwargs)
Пример #7
0
    def test_cna(self):
        test_network = self.network3  # Defined in test.constants.TestNetworks

        a_as_root = run_cna(graph=test_network,
                            root=protein(HGNC, 'a'),
                            targets=[gene(HGNC, 'c')])

        self.assertEqual(-1, a_as_root[0][2].value)  # A -| C

        d_as_root = run_cna(graph=test_network,
                            root=rna(HGNC, 'd'),
                            targets=[gene(HGNC, 'c'),
                                     gene(HGNC, 'f')])

        self.assertEqual(-1, d_as_root[0][2].value)  # D -| C
        self.assertEqual(-1, d_as_root[1][2].value)  # A -| F

        e_as_root = run_cna(graph=test_network,
                            root=protein(HGNC, 'e'),
                            targets=[gene(HGNC, 'c'),
                                     gene(HGNC, 'f')])

        self.assertEqual(1, e_as_root[0][2].value)  # E -> C
        self.assertEqual(1, e_as_root[1][2].value)  # E -> F

        failed_results = run_cna(graph=test_network,
                                 root=protein(HGNC, 'e'),
                                 targets=[protein(HGNC, 'g')])

        self.assertEqual(0, failed_results[0][2].value)  # E -> G
Пример #8
0
 def test_gene_fusion(self):
     """Test serialization of a gene fusion to BEL with a explicit fusion ranges."""
     dsl = gene_fusion(gene('HGNC', 'TMPRSS2'), gene('HGNC', 'ERG'),
                       fusion_range('c', 1, 79),
                       fusion_range('c', 312, 5034))
     self.assertEqual(
         'g(fus(HGNC:TMPRSS2, "c.1_79", HGNC:ERG, "c.312_5034"))',
         dsl.as_bel())
Пример #9
0
    def test_gene_fusion_specified(self):
        node = gene_fusion(partner_5p=gene(namespace='HGNC', name='TMPRSS2'),
                           range_5p=fusion_range('c', 1, 79),
                           partner_3p=gene(namespace='HGNC', name='ERG'),
                           range_3p=fusion_range('c', 312, 5034))

        self.assertEqual(
            'g(fus(HGNC:TMPRSS2, "c.1_79", HGNC:ERG, "c.312_5034"))',
            str(node))
Пример #10
0
    def test_enrich_orthologs_on_entrez(self):
        """Test enriching a graph that contains an HGNC node identified by Entrez."""
        for namespace in entrez_namespaces:
            graph = BELGraph()
            node = gene(namespace=namespace,
                        name=hgnc_gene_symbol,
                        identifier='5594')
            graph.add_node_from_data(node)
            self.help_test_enrich_orthologs_on_hgnc(graph, node)

        for namespace in entrez_namespaces:
            graph = BELGraph()
            node = gene(namespace=namespace, identifier='5594')
            graph.add_node_from_data(node)
            self.help_test_enrich_orthologs_on_hgnc(graph, node)
Пример #11
0
    def test_multiple(self):
        """Test building a node predicate with multiple functions."""
        f = function_inclusion_filter_builder([GENE, PROTEIN])

        p1 = protein(n(), n())
        g1 = gene(n(), n())
        b1 = bioprocess(n(), n())

        g = BELGraph()
        g.add_node_from_data(p1)
        g.add_node_from_data(g1)
        g.add_node_from_data(b1)

        self.assertIn(p1, g)
        self.assertIn(g1, g)
        self.assertIn(b1, g)

        self.assertTrue(f(g, p1))
        self.assertTrue(f(g, g1))
        self.assertFalse(f(g, b1))

        f = invert_node_predicate(f)

        self.assertFalse(f(g, p1))
        self.assertFalse(f(g, g1))
        self.assertTrue(f(g, b1))
Пример #12
0
    def test_directlyDecreases_annotationExpansion(self):
        """
        3.1.4 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#XdDecreases
        Tests simple triple"""
        statement = 'g(HGNC:CAT, location(GO:intracellular)) directlyDecreases abundance(CHEBI:"hydrogen peroxide")'

        annotations = {
            'ListAnnotation': {'a', 'b'},
            'ScalarAnnotation': {'c'}
        }

        self.parser.control_parser.annotations.update(annotations)

        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                FUNCTION: GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'CAT',
                },
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular',
                }
            },
            RELATION: DIRECTLY_DECREASES,
            OBJECT: {
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: 'CHEBI',
                    NAME: 'hydrogen peroxide',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = gene('HGNC', 'CAT')
        self.assert_has_node(sub)

        obj = abundance('CHEBI', 'hydrogen peroxide')
        self.assert_has_node(obj)

        expected_attrs = {
            SUBJECT: {
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular'
                }
            },
            RELATION: DIRECTLY_DECREASES,
            CITATION: test_citation_dict,
            EVIDENCE: test_evidence_text,
            ANNOTATIONS: {
                'ListAnnotation': {'a': True, 'b': True},
                'ScalarAnnotation': {'c': True},
            }
        }
        self.assert_has_edge(sub, obj, **expected_attrs)
Пример #13
0
    def test_label_1(self):
        statement = 'g(HGNC:APOE, var(c.526C>T), var(c.388T>C)) labeled "APOE E2"'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                FUNCTION:
                GENE,
                NAMESPACE:
                'HGNC',
                NAME:
                'APOE',
                VARIANTS: [{
                    KIND: HGVS,
                    IDENTIFIER: 'c.526C>T'
                }, {
                    KIND: HGVS,
                    IDENTIFIER: 'c.388T>C'
                }]
            },
            OBJECT: 'APOE E2'
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = gene('HGNC',
                             'APOE',
                             variants=[hgvs('c.526C>T'),
                                       hgvs('c.388T>C')])
        self.assert_has_node(expected_node)

        self.assertTrue(self.parser.graph.has_node_description(expected_node))
        self.assertEqual('APOE E2',
                         self.parser.graph.get_node_description(expected_node))
Пример #14
0
    def test_enrich_orthologs_on_rgd_symbol(self):
        """Test enriching a graph that contains an RGD node identified by Entrez."""
        # Test that if there's a name and identifier that the name gets thrown away
        for entrez_namespace in entrez_namespaces:
            graph = BELGraph()
            rat_node = gene(namespace=entrez_namespace,
                            name=rgd_gene_symbol,
                            identifier='116590')
            graph.add_node_from_data(rat_node)
            self.help_test_enrich_orthologs_on_rgd(graph, rat_node)

        # Test the case when there's no name
        for entrez_namespace in entrez_namespaces:
            graph = BELGraph()
            rat_node = gene(namespace=entrez_namespace, identifier='116590')
            graph.add_node_from_data(rat_node)
            self.help_test_enrich_orthologs_on_rgd(graph, rat_node)
Пример #15
0
    def test_orthologous(self):
        """
        3.3.1 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_orthologous
        """
        statement = 'g(HGNC:AKT1) orthologous g(MGI:AKT1)'
        result = self.parser.relation.parseString(statement)
        expected_result = [[GENE, 'HGNC', 'AKT1'], ORTHOLOGOUS,
                           [GENE, 'MGI', 'AKT1']]
        self.assertEqual(expected_result, result.asList())

        sub = gene('HGNC', 'AKT1')
        self.assert_has_node(sub)

        obj = gene('MGI', 'AKT1')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=ORTHOLOGOUS)
        self.assert_has_edge(obj, sub, relation=ORTHOLOGOUS)
Пример #16
0
    def test_has_variant(self):
        statement = 'g(HGNC:AKT1) hasVariant g(HGNC:AKT1, gmod(M))'
        self.parser.relation.parseString(statement)

        expected_parent = gene('HGNC', 'AKT1')
        expected_child = expected_parent.with_variants(gmod('Me'))

        self.assert_has_node(expected_parent)
        self.assert_has_node(expected_child)

        self.assertEqual('g(HGNC:AKT1)', self.graph.node_to_bel(expected_parent))
        self.assertEqual('g(HGNC:AKT1, gmod(Me))', self.graph.node_to_bel(expected_child))

        self.assert_has_edge(expected_parent, expected_child, **{RELATION: HAS_VARIANT})
Пример #17
0
def node_to_bel(node: Dict, hgnc_manager: Manager, pathway_id) -> BaseEntity:
    """Create a BEL node."""
    node_types = node['node_types']
    uri_id = node['uri_id']

    # Get identifier from if exists else use uri_id as identifier
    if 'identifier' in node:
        identifier = node['identifier']
    else:
        identifier = uri_id

    identifier = check_multiple(identifier, 'identifier', pathway_id)

    uri_id = check_multiple(uri_id, 'uri_id', pathway_id)
    _, _, namespace, _ = parse_id_uri(uri_id)

    name = check_multiple(node['name'], 'name', pathway_id)

    # Get dictinoary of multiple identifiers
    if 'identifiers' in node:
        node_ids_dict = node['identifiers']
    else:
        node_ids_dict = node

    if any(node_type in node_types for node_type in ('Protein', 'Rna', 'GeneProduct')):
        namespace, name, identifier = get_valid_gene_identifier(node_ids_dict, hgnc_manager, pathway_id)
        if 'Protein' in node_types:
            return protein(namespace=namespace.upper(), name=name, identifier=identifier)
        elif 'Rna' in node_types:
            return rna(namespace=namespace.upper(), name=name, identifier=identifier)
        else:  # 'GeneProduct' in node_types
            return gene(namespace=HGNC, name=name, identifier=identifier)

    elif 'Metabolite' in node_types:
        # Parse URI to get namespace
        _, _, namespace, _ = parse_id_uri(uri_id)
        return abundance(namespace=namespace.upper(), name=name, identifier=identifier)

    elif '/wikipathways/WP' in str(uri_id) and {'DataNode'} == node_types:
        # Check the uri_id if is a Pathway
        _, _, namespace, _ = parse_id_uri(uri_id)
        return bioprocess(namespace=namespace.upper(), name=name, identifier=identifier)

    elif 'DataNode' in node_types:
        # Parse URI to get namespace
        _, _, namespace, _ = parse_id_uri(uri_id)
        return abundance(namespace=namespace.upper(), name=name, identifier=identifier)

    else:
        logger.debug('Unknown %s [pathway=%s]', node_types, pathway_id)
Пример #18
0
    def test_transcription(self):
        """
        3.3.2 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_transcribedto
        """
        statement = 'g(HGNC:AKT1) :> r(HGNC:AKT1)'
        result = self.parser.relation.parseString(statement)

        expected_result = [[GENE, ['HGNC', 'AKT1']], TRANSCRIBED_TO, [RNA, ['HGNC', 'AKT1']]]
        self.assertEqual(expected_result, result.asList())

        sub = gene('HGNC', 'AKT1')
        self.assert_has_node(sub)

        obj = rna('HGNC', 'AKT1')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, **{RELATION: TRANSCRIBED_TO})
Пример #19
0
    def test_cnc_with_subject_variant(self):
        """Test a causesNoChange relationship with a variant in the subject.

        See also: 3.1.6 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#Xcnc
        """
        statement = 'g(HGNC:APP,sub(G,275341,C)) cnc path(MESH:"Alzheimer Disease")'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SOURCE: {
                FUNCTION: GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'APP',
                },
                VARIANTS: [
                    {
                        KIND: HGVS,
                        HGVS: 'c.275341G>C'
                    },
                ],
            },
            RELATION: CAUSES_NO_CHANGE,
            TARGET: {
                FUNCTION: PATHOLOGY,
                CONCEPT: {
                    NAMESPACE: 'MESH',
                    NAME: 'Alzheimer Disease',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        app_gene = gene(namespace='HGNC', name='APP')
        self.assert_has_node(app_gene)
        sub = app_gene.with_variants(hgvs('c.275341G>C'))
        self.assert_has_node(sub)

        obj = Pathology('MESH', 'Alzheimer Disease')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
Пример #20
0
    def test_ensure_no_dup_nodes(self):
        """Ensure node isn't added twice, even if from different statements"""
        self.parser.gene.addParseAction(self.parser.handle_term)
        result = self.parser.bel_term.parseString('g(HGNC:AKT1)')

        expected_result_dict = {
            FUNCTION: GENE,
            NAMESPACE: 'HGNC',
            NAME: 'AKT1'
        }

        self.assertEqual(expected_result_dict, result.asDict())

        self.parser.degradation.addParseAction(self.parser.handle_term)
        self.parser.degradation.parseString('deg(g(HGNC:AKT1))')

        akt1_gene = gene('HGNC', 'AKT1')

        self.assertEqual(1, self.parser.graph.number_of_nodes())
        self.assert_has_node(akt1_gene)
Пример #21
0
    def test_single(self):
        """Test building a node predicate with a single function."""
        f = function_inclusion_filter_builder(GENE)

        p1 = protein(n(), n())
        g1 = gene(n(), n())

        g = BELGraph()
        g.add_node_from_data(p1)
        g.add_node_from_data(g1)

        self.assertIn(p1, g)
        self.assertIn(g1, g)

        self.assertFalse(f(g, p1))
        self.assertTrue(f(g, g1))

        f = invert_node_predicate(f)

        self.assertTrue(f(g, p1))
        self.assertFalse(f(g, g1))
Пример #22
0
    def _help_test_increases_methylation(self, x):
        statement = f'a(CHEBI:"lead atom") -> g(HGNC:APP, gmod({x}))'
        result = self.parser.relation.parseString(statement)
        expected_dict = {
            TARGET: {
                FUNCTION:
                GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'APP',
                },
                VARIANTS: [
                    {
                        KIND: GMOD,
                        CONCEPT: {
                            NAMESPACE: 'go',
                            IDENTIFIER: '0006306',
                            NAME: 'DNA methylation',
                        },
                    },
                ],
            },
            RELATION: INCREASES,
            SOURCE: {
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: 'CHEBI',
                    NAME: 'lead atom',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = abundance('CHEBI', 'lead atom')
        obj = gene('HGNC', 'APP', variants=gmod('Me'))

        self.assert_has_edge(sub, obj, relation=INCREASES)
Пример #23
0
    def test_increases_methylation(self):
        """Test a causal statement with a gene modification."""
        statement = 'a(CHEBI:"lead atom") -> g(HGNC:APP, gmod(Me))'
        result = self.parser.relation.parseString(statement)
        expected_dict = {
            OBJECT: {
                FUNCTION:
                GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'APP',
                },
                VARIANTS: [
                    {
                        KIND: GMOD,
                        CONCEPT: {
                            NAMESPACE: BEL_DEFAULT_NAMESPACE,
                            NAME: 'Me',
                        },
                    },
                ],
            },
            RELATION: INCREASES,
            SUBJECT: {
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: 'CHEBI',
                    NAME: 'lead atom',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = abundance('CHEBI', 'lead atom')
        obj = gene('HGNC', 'APP', variants=gmod('Me'))

        self.assert_has_edge(sub, obj, relation=INCREASES)
Пример #24
0
    def test_directlyDecreases_annotationExpansion(self):
        """
        3.1.4 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#XdDecreases
        Tests simple triple"""
        statement = 'g(HGNC:CAT, location(GO:intracellular)) directlyDecreases abundance(CHEBI:"hydrogen peroxide")'

        self.graph.annotation_list.update({
            'ListAnnotation': set('abef'),
            'ScalarAnnotation': set('cghi'),
        })
        annotations = self.parser.graph._clean_annotations({
            'ListAnnotation': {'a', 'b'},
            'ScalarAnnotation': {'c'},
        })

        self.parser.control_parser.annotations.update(annotations)

        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SOURCE: {
                FUNCTION: GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'CAT',
                },
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular',
                }
            },
            RELATION: DIRECTLY_DECREASES,
            TARGET: {
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: 'CHEBI',
                    NAME: 'hydrogen peroxide',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = gene('HGNC', 'CAT')
        self.assert_has_node(sub)

        obj = abundance('CHEBI', 'hydrogen peroxide')
        self.assert_has_node(obj)

        expected_attrs = {
            SOURCE_MODIFIER: {
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular'
                }
            },
            RELATION: DIRECTLY_DECREASES,
            CITATION: test_citation_dict,
            EVIDENCE: test_evidence_text,
            ANNOTATIONS: {
                'ListAnnotation': [
                    Entity(namespace='ListAnnotation', identifier='a'),
                    Entity(namespace='ListAnnotation', identifier='b'),
                ],
                'ScalarAnnotation': [
                    Entity(namespace='ScalarAnnotation', identifier='c'),
                ],
            },
        }
        self.assert_has_edge(sub, obj, only=True, **expected_attrs)
Пример #25
0
import unittest

from pybel import BELGraph
from pybel.constants import POSITIVE_CORRELATION, RELATION
from pybel.dsl import CompositeAbundance, Protein, gene, hgvs, pathology, protein_fusion, rna, rna_fusion
from pybel.struct.mutation import (
    enrich_protein_and_rna_origins,
    prune_protein_rna_origins,
    remove_associations,
    remove_isolated_list_abundances,
    remove_pathologies,
)
from pybel.struct.mutation.utils import remove_isolated_nodes, remove_isolated_nodes_op
from pybel.testing.utils import n

trem2_gene = gene(namespace='HGNC', name='TREM2')
trem2_rna = rna(namespace='HGNC', name='TREM2')
trem2_protein = Protein(namespace='HGNC', name='TREM2')


class TestDeletions(unittest.TestCase):
    """Test cases for deletion functions."""
    def test_remove_pathologies(self):
        """Test removal of pathologies."""
        g = BELGraph()

        p1, p2, p3 = (Protein(namespace='HGNC', name=n()) for _ in range(3))
        d1, d2 = (pathology(namespace='MESH', name=n()) for _ in range(2))

        g.add_increases(p1, p2, citation=n(), evidence=n())
        g.add_increases(p2, p3, citation=n(), evidence=n())
Пример #26
0
example_graph.add_decreases(mthfr_c677t, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_decreases(mthfr_a1298c, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_negative_correlation(mthfr_c677t, folic_acid, citation=c2, evidence=e2)
example_graph.add_positive_correlation(mthfr_c677t, alzheimer_disease, citation=c2, evidence=e2)

c3 = '17948130'
e3 = 'A polymorphism in the NDUFB6 promoter region that creates a possible DNA methylation site (rs629566, A/G) was ' \
     'associated with a decline in muscle NDUFB6 expression with age. Although young subjects with the rs629566 G/G ' \
     'genotype exhibited higher muscle NDUFB6 expression, this genotype was associated with reduced expression in' \
     ' elderly subjects. This was subsequently explained by the finding of increased DNA methylation in the promoter ' \
     'of elderly, but not young, subjects carrying the rs629566 G/G genotype. Furthermore, the degree of DNA' \
     ' methylation correlated negatively with muscle NDUFB6 expression, which in turn was associated with insulin ' \
     'sensitivity.'
e3 = str(hash(e3))

rs629566 = gene('DBSNP', 'rs629566', variants=[gmod('Me')])
ndufb6_gene = gene('HGNC', 'NDUFB6')
ndufb6_rna = rna('HGNC', 'NDUFB6')

example_graph.add_unqualified_edge(ndufb6_gene, rs629566, HAS_VARIANT)
example_graph.add_negative_correlation(rs629566, ndufb6_rna, citation=c3, evidence=e3,
                                       annotations={'Confidence': 'Low', 'Number': '50'})

"""
SET Evidence = "% Entrez Gene summary: Rat: SUMMARY: precursor protein of kinin which is found in plasma; cysteine protease inhibitor and a major acute phase reactant [RGD] OMIM summary: (summary is not available from this source) kininogens; Endogenous peptides present in most body fluids. Certain enzymes convert them to active kinins which are involved in inflammation, blood clotting, complement reactions, etc. Kininogens belong to the cystatin superfamily. They are cysteine proteinase inhibitors. High-molecular-weight kininogen (hmwk) is split by plasma kallikrein to produce bradykinin. Low-molecular-weight kininogen (lmwk) is split by tissue kallikrein to produce kallidin. kinins; Inflammatory mediators that cause dilation of blood vessels and altered vascular permeability.  Kinins are small peptides produced from kininogen by kallikrein and are broken down by kininases. Act on phospholipase and increase arachidonic acid release and thus prostaglandin (PGE2) production. bradykinin; Vasoactive nonapeptide (RPPGFSPFR) formed by action of proteases on kininogens. Very similar to kallidin (which has the same sequence but with an additional N terminal lysine). Bradykinin is a very potent vasodilator and increases permeability of post capillary venules, it acts on endothelial cells to activate phospholipase A2. It is also spasmogenic for some smooth muscle and will cause pain. kallidin; Decapeptide (lysyl bradykinin, amino acid sequence KRPPGFSPFR) produced in kidney. Like bradykinin, an inflammatory mediator (a kinin), causes dilation of renal blood vessels and increased water excretion."
SET Species = 9606
SET Citation = {"Other","Genstruct Kininogen Overview","Genstruct Kininogen Overview","","",""}

bp(GOBP:"inflammatory response") increases rxn(reactants(p(HGNC:KNG1)),products(a(SCHEM:Kallidin)))
path(SDIS:"tissue damage") increases rxn(reactants(p(HGNC:KNG1)),products(a(SCHEM:Kallidin)))
a(SCHEM:Kallidin) increases cat(p(HGNC:BDKRB1))
Пример #27
0
    def setUp(self):
        super(ManagerMixin, self).setUp()

        self.db_fd, self.db_file = tempfile.mkstemp()

        self.connection = 'sqlite:///' + self.db_file
        self.manager = Manager(connection=self.connection)

    def tearDown(self):
        os.close(self.db_fd)
        os.unlink(self.db_file)


protein_a = protein(namespace=HGNC, name='a')
protein_b = protein(namespace=HGNC, name='b')
gene_c = gene(namespace=HGNC, name='c')
rna_d = rna(namespace=HGNC, name='d')
protein_e = protein(namespace=HGNC, name='e')
gene_f = gene(namespace=HGNC, name='f')
protein_g = protein(namespace=HGNC, name='g')
protein_h = protein(namespace=HGNC, name='h')
protein_i = protein(namespace=HGNC, name='i')
protein_j = protein(namespace=HGNC, name='j')


def make_graph_1() -> BELGraph:
    graph = BELGraph(
        name='Lab course example',
        version='1.1.0',
        description='',
        authors='LSI',
Пример #28
0
# -*- coding: utf-8 -*-
"""Tests for collapse functions."""

import unittest

from pybel import BELGraph
from pybel.constants import DIRECTLY_INCREASES
from pybel.dsl import gene, mirna, pathology, pmod, protein, rna
from pybel.struct.mutation.collapse import collapse_all_variants, collapse_nodes, collapse_to_genes
from pybel.testing.utils import n

HGNC = 'HGNC'
GO = 'GO'
CHEBI = 'CHEBI'

g1 = gene(HGNC, '1')
r1 = rna(HGNC, '1')
p1 = protein(HGNC, '1')
p1_phosphorylated = protein(HGNC, '1', variants=[pmod('Ph')])

g2 = gene(HGNC, '2')
r2 = rna(HGNC, '2')
p2 = protein(HGNC, '2')

g3 = gene(HGNC, '3')
r3 = rna(HGNC, '3')
p3 = protein(HGNC, '3')

g4 = gene(HGNC, '4')
m4 = mirna(HGNC, '4')
Пример #29
0
def node_to_bel(node: Dict, graph, hgnc_manager: HgncManager,
                chebi_manager: ChebiManager, species) -> BaseEntity:
    """Convert node dictionary to BEL node object."""
    node_types = node['entity_type']

    identifier, name, namespace = get_valid_node_parameters(
        node, hgnc_manager, chebi_manager, species)
    members = set()

    if namespace == 'hgnc_multiple_entry':
        return composite_abundance(process_multiple_proteins(identifier))

    elif 'Protein' in node_types:
        return protein(namespace=namespace.upper(),
                       name=name,
                       identifier=identifier)

    elif 'Dna' in node_types:
        return gene(namespace=namespace.upper(),
                    name=name,
                    identifier=identifier)

    elif 'Rna' in node_types:
        return rna(namespace=namespace.upper(),
                   name=name,
                   identifier=identifier)

    elif 'SmallMolecule' in node_types:
        return abundance(namespace=namespace.upper(),
                         name=name,
                         identifier=identifier)

    elif 'PhysicalEntity' in node_types:
        return abundance(namespace=namespace.upper(),
                         name=name,
                         identifier=identifier)

    elif 'Complex' in node_types:
        complex_components = node.get('complex_components')

        if complex_components:
            for component in complex_components:
                bel_node = node_to_bel(component, graph, hgnc_manager,
                                       chebi_manager, species)

                members.add(bel_node)

        if members:
            return complex_abundance(name=node.get('display_name'),
                                     members=members,
                                     identifier=identifier,
                                     namespace=namespace.upper())
        else:
            return NamedComplexAbundance(name=node.get('display_name'),
                                         identifier=identifier,
                                         namespace=namespace.upper())

    elif 'Pathway' in node_types:
        bioprocess_node = bioprocess(identifier=identifier,
                                     name=name,
                                     namespace=namespace.upper())
        graph.add_node_from_data(bioprocess_node)
        return bioprocess_node
    else:
        log.warning('Entity type not recognized', node_types)
Пример #30
0
    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()
        p1_tuple = g.add_node_from_data(p1)
        self.assertTrue(keep_node_permissive(g, p1_tuple))

    def test_p1_data_variants(self):