示例#1
0
 def test_str_has_name(self):
     namespace, name = n(), n()
     node = abundance(namespace=namespace, name=name)
     self.assertEqual(
         'a({namespace}:{name})'.format(namespace=namespace,
                                        name=ensure_quotes(name)),
         str(node))
示例#2
0
 def test_str_has_both(self):
     namespace, identifier = n(), n()
     node = abundance(namespace=namespace, identifier=identifier)
     self.assertEqual(
         'a({namespace}:{identifier})'.format(
             namespace=namespace, identifier=ensure_quotes(identifier)),
         str(node))
示例#3
0
    def test_as_tuple(self):
        namespace, name = n(), n()

        node_tuple = ABUNDANCE, namespace, name
        node = abundance(namespace=namespace, name=name)

        self.assertEqual(node_tuple, node.as_tuple())
        self.assertEqual(hash(node_tuple), hash(node))
示例#4
0
    def test_add_simple(self):
        g = BELGraph()

        namespace, name = n(), n()

        g.add_node_from_data(protein(namespace=namespace, name=name))
        self.assertEqual(1, g.number_of_nodes())

        g.add_node_from_data(protein(namespace=namespace, name=name))
        self.assertEqual(1, g.number_of_nodes())
示例#5
0
    def test_citation(self):
        ref = n()
        model = Citation(type=CITATION_TYPE_PUBMED, reference=ref)
        expected = {
            CITATION_TYPE: CITATION_TYPE_PUBMED,
            CITATION_REFERENCE: ref
        }

        self.assertEqual(expected, model.to_json())

        expected[CITATION_TITLE] = model.title = n()
示例#6
0
    def test_get_node_properties(self):
        test_name = n()
        test_identifier = n()

        node = self.graph.add_node_from_data(protein(namespace='TEST', name=test_name, identifier=test_identifier))

        self.assertEqual(test_name, self.graph.get_node_name(node))
        self.assertEqual(test_identifier, self.graph.get_node_identifier(node))

        self.assertIsNone(self.graph.get_node_description(node))

        test_description = n()
        self.graph.set_node_description(node, test_description)
        self.assertEqual(test_description, self.graph.get_node_description(node))
示例#7
0
    def test_network(self):
        name = n()
        version = n()
        model = Network(name=name, version=version)
        expected = {
            METADATA_NAME: name,
            METADATA_VERSION: version,
            'created': None,
        }

        self.assertEqual(expected, model.to_json())

        expected[METADATA_AUTHORS] = model.authors = n()
        self.assertEqual(expected, model.to_json())

        expected[METADATA_CONTACT] = model.contact = n()
        self.assertEqual(expected, model.to_json())

        expected[METADATA_DESCRIPTION] = model.description = n()
        self.assertEqual(expected, model.to_json())

        expected[METADATA_COPYRIGHT] = model.copyright = n()
        self.assertEqual(expected, model.to_json())

        expected[METADATA_DISCLAIMER] = model.disclaimer = n()
        self.assertEqual(expected, model.to_json())

        expected[METADATA_LICENSES] = model.licenses = n()
        self.assertEqual(expected, model.to_json())

        expected['id'] = None
        self.assertEqual(expected, model.to_json(include_id=True))
示例#8
0
    def test_name(self):
        (
            name,
            version,
            description,
            authors,
            contact,
            licenses,
            copyrights,
            disclaimer
        ) = [n() for _ in range(8)]

        g = BELGraph()

        g.name = name
        g.version = version
        g.description = description
        g.authors = authors
        g.contact = contact
        g.license = licenses
        g.copyright = copyrights
        g.disclaimer = disclaimer

        self.assertEqual(name, g.name)
        self.assertEqual(version, g.version)
        self.assertEqual(description, g.description)
        self.assertEqual(authors, g.authors)
        self.assertEqual(contact, g.contact)
        self.assertEqual(licenses, g.license)
        self.assertEqual(copyrights, g.copyright)
        self.assertEqual(disclaimer, g.disclaimer)

        self.assertEqual('{name} v{version}'.format(name=name, version=version), str(g))
示例#9
0
    def add_edge(self, subject_modifier=None, object_modifier=None, annotations=None):
        self.key += 1

        self.g.add_qualified_edge(
            self.u,
            self.v,
            relation=INCREASES,
            evidence=n(),
            citation=n(),
            subject_modifier=subject_modifier,
            object_modifier=object_modifier,
            annotations=annotations,
            key=self.key
        )

        return canonicalize_edge(self.get_data(self.key))
示例#10
0
    def test_multiple_annotations(self):
        a1, v1, v2 = map(lambda _: n(), range(3))
        v1, v2 = sorted([v1, v2])

        self.graph.add_qualified_edge(protein(namespace='HGNC', name='YFG1'),
                                      protein(namespace='HGNC', name='YFG'),
                                      relation=INCREASES,
                                      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 = [
            '#' * 80,
            'SET Citation = {{"PubMed", "{}"}}'.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',
        ]

        self.help_check_lines(expected_lines)
示例#11
0
    def setUp(self):
        super(TestCascades, self).setUp()

        self.n1 = Node(type=PROTEIN, bel='p(HGNC:A)')
        self.n2 = Node(type=PROTEIN, bel='p(HGNC:B)')
        self.n3 = Node(type=PROTEIN, bel='p(HGNC:C)')
        self.e1 = Edge(source=self.n1, target=self.n2, relation=INCREASES, bel='p(HGNC:A) increases p(HGNC:B)')
        self.e2 = Edge(source=self.n2, target=self.n3, relation=INCREASES, bel='p(HGNC:B) increases p(HGNC:C)')
        self.e3 = Edge(source=self.n1, target=self.n3, relation=INCREASES, bel='p(HGNC:A) increases p(HGNC:C)')
        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())
示例#12
0
    def test_get_qualified_edge(self):
        test_source = self.graph.add_node_from_data(protein(namespace='TEST', name='YFG'))
        test_target = self.graph.add_node_from_data(protein(namespace='TEST', name='YFG2'))
        test_key = n()
        test_evidence = n()
        test_pmid = n()

        self.graph.add_qualified_edge(
            test_source,
            test_target,
            relation=INCREASES,
            citation=test_pmid,
            evidence=test_evidence,
            annotations={
                'Species': '9606',
                'Confidence': 'Very High'
            },
            key=test_key
        )

        citation = self.graph.get_edge_citation(test_source, test_target, test_key)

        self.assertIsNotNone(citation)
        self.assertIsInstance(citation, dict)
        self.assertIn(CITATION_TYPE, citation)
        self.assertEqual(CITATION_TYPE_PUBMED, citation[CITATION_TYPE])
        self.assertIn(CITATION_REFERENCE, citation)
        self.assertEqual(test_pmid, citation[CITATION_REFERENCE])

        evidence = self.graph.get_edge_evidence(test_source, test_target, test_key)

        self.assertIsNotNone(evidence)
        self.assertIsInstance(evidence, string_types)
        self.assertEqual(test_evidence, evidence)

        annotations = self.graph.get_edge_annotations(test_source, test_target, test_key)
        self.assertIsNotNone(annotations)
        self.assertIsInstance(annotations, dict)
        self.assertIn('Species', annotations)
        self.assertIn('9606', annotations['Species'])
        self.assertTrue(annotations['Species']['9606'])
        self.assertIn('Confidence', annotations)
        self.assertIn('Very High', annotations['Confidence'])
        self.assertTrue(annotations['Confidence']['Very High'])
示例#13
0
    def test_citation_type_error(self):
        g = BELGraph()

        with self.assertRaises(TypeError):
            g.add_qualified_edge(
                protein(namespace='TEST', name='YFG1'),
                protein(namespace='TEST', name='YFG2'),
                relation=INCREASES,
                evidence=n(),
                citation=5
            )
示例#14
0
    def test_drop_namespace(self):
        keyword, url = n(), n()

        namespace = Namespace(keyword=keyword, url=url)
        self.manager.session.add(namespace)

        n_entries = 5

        for _ in range(n_entries):
            entry = NamespaceEntry(name=n(), namespace=namespace)
            self.manager.session.add(entry)

        self.manager.session.commit()

        self.assertEqual(1, self.manager.count_namespaces(), msg='Should have one namespace')
        self.assertEqual(n_entries, self.manager.count_namespace_entries(),
                         msg='Should have {} entries'.format(n_entries))

        self.manager.drop_namespace_by_url(url)

        self.assertEqual(0, self.manager.count_namespaces(), msg='Should have no namespaces')
        self.assertEqual(0, self.manager.count_namespace_entries(), msg='Entries should have been dropped')
示例#15
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_qualified_edge(protein(namespace='HGNC', name='YFG1'),
                                      protein(namespace='HGNC', name='YFG'),
                                      relation=INCREASES,
                                      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 = [
            '#' * 80,
            'SET Citation = {{"PubMed", "{}"}}'.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'
        ]

        self.help_check_lines(expected_lines)
示例#16
0
 def setUp(self):
     self.citation = n()
     self.evidence = n()
     self.url = n()
     self.graph = BELGraph()
     self.graph.namespace_url['HGNC'] = self.url
示例#17
0
 def test_get_node_identifier(self):
     test_name = n()
     node = self.graph.add_node_from_data(protein(namespace='TEST', name=test_name))
     self.assertIsNotNone(self.graph.get_node_name(node))
     self.assertIsNone(self.graph.get_node_identifier(node))