Exemple #1
0
class CTDTestCase(SourceTestCase):
    def setUp(self):
        self.source = CTD()
        self.source.settestonly(True)
        self.source.setnobnodes(True)
        self._setDirToSource()
        return

    def tearDown(self):
        self.source = None
        return

    def test_therapeutic_relationship(self):
        from dipper.utils.TestUtils import TestUtils
        from dipper.utils.GraphUtils import GraphUtils
        from dipper import curie_map

        # Make testutils object and load ttl
        test_query = TestUtils(self.source.graph)
        test_query.load_testgraph_from_turtle(self.source)

        # Expected structure
        # TODO can this be unified OBAN and the Annot models to be automatically generated?
        sparql_query = """
                       SELECT ?assoc ?pubmed ?disease ?chemical
                       WHERE {
                       ?assoc a Annotation: ;
                           dc:evidence OBO:ECO_0000033 ;
                           dc:source ?pubmed ;
                           :hasObject ?disease ;
                           :hasPredicate OBO:RO_0002606 ;
                           :hasSubject ?chemical .}
                       """

        # SPARQL variables to check
        gu = GraphUtils(curie_map.get())
        chem_id = 'MESH:D009538'
        chem_uri = gu.getNode(chem_id)
        disease_id = 'OMIM:188890'
        disease_uri = gu.getNode(disease_id)
        eco = 'ECO:0000033'
        rel_id = gu.object_properties['substance_that_treats']
        pubmed_id = 'PMID:16785264'
        pubmed_uri = gu.getNode(pubmed_id)

        # consider replacing with make_ctd_chem_disease_assoc_id()
        assoc_id = self.source.make_association_id('ctd', chem_id, rel_id, disease_id, eco, pubmed_id)
        assoc_uri = gu.getNode(assoc_id)

        # One of the expected outputs from query
        expected_output = [assoc_uri, pubmed_uri, disease_uri, chem_uri]

        # Query graph
        sparql_output = test_query.query_graph(sparql_query)

        self.assertTrue(expected_output in sparql_output, "did not find expected association: " + assoc_id +
                        " found: " + pprint.pformat(sparql_output))

        logger.info("Test query data finished.")
Exemple #2
0
class CTDTestCase(unittest.TestCase):
    def setUp(self):
        self.test_util = TestUtils()
        self.source = CTD('rdf_graph', True)
        self.source.graph = RDFGraph(True)
        self.test_row = [
            'Nicotine',
            'D009538',
            '',
            'TOBACCO ADDICTION, SUSCEPTIBILITY TO',
            'OMIM:188890',
            'therapeutic',
            '',
            '',
            '',
            '12345|56789'
        ]
        return

    def tearDown(self):
        self.source = None
        return

    def test_therapeutic_relationship(self):
        # test that graph is empty
        self.assertTrue(len(list(self.source.graph)) == 0)

        self.source._process_interactions(self.test_row)

        triples = """
            :MONARCH_b6c289df47cb72653f79 a OBAN:association ;
                RO:0002558 ECO:0000033 ;
                dc:source PMID:12345, PMID:56789 ;
                OBAN:association_has_object OMIM:188890 ;
                OBAN:association_has_predicate RO:0002606 ;
                OBAN:association_has_subject MESH:D009538 .
            
            MESH:D009538 a owl:Class ;
                rdfs:label "Nicotine" ;
                RO:0002606 OMIM:188890 .
                
            PMID:12345 a IAO:0000013 .
            PMID:56789 a IAO:0000013 .
            
            OMIM:188890 a owl:Class .
        """
        # test exact contents of graph
        self.assertTrue(self.test_util.test_graph_equality(
            triples, self.source.graph))
Exemple #3
0
    def setUp(self):
        self.graph = Graph()

        self.curie_map = curie_map.get()
        self.ctd = CTD()
        self.ctd.graph = Graph()
        self.ctd.g = self.ctd.graph
        row1 = ['06-Paris-LA-66 protocol', 'C046983', 'foo',
                'Precursor Cell Lymphoblastic Leukemia-Lymphoma',
                'MESH:D054198', 'therapeutic', 'bar', 'baz', 'foo', '4519131']
        row2 = ['10,10-bis(4-pyridinylmethyl)-9(10H)-anthracenone',
                'C112297', 'foo', 'Hyperkinesis', 'MESH:D006948',
                'marker/mechanism', 'bar', 'baz', 'foo', '19098162']

        self.ctd._process_interactions(row1)
        self.ctd._process_interactions(row2)
Exemple #4
0
 def setUp(self):
     self.test_util = TestUtils()
     self.source = CTD('rdf_graph', True)
     self.source.graph = RDFGraph(True)
     self.test_row = [
         'Nicotine',
         'D009538',
         '',
         'TOBACCO ADDICTION, SUSCEPTIBILITY TO',
         'OMIM:188890',
         'therapeutic',
         '',
         '',
         '',
         '12345|56789'
     ]
     return
Exemple #5
0
class InteractionsTestCase(unittest.TestCase):

    def setUp(self):
        self.graph = Graph()

        self.curie_map = curie_map.get()
        self.ctd = CTD()
        self.ctd.graph = Graph()
        self.ctd.g = self.ctd.graph
        row1 = ['06-Paris-LA-66 protocol', 'C046983', 'foo',
                'Precursor Cell Lymphoblastic Leukemia-Lymphoma',
                'MESH:D054198', 'therapeutic', 'bar', 'baz', 'foo', '4519131']
        row2 = ['10,10-bis(4-pyridinylmethyl)-9(10H)-anthracenone',
                'C112297', 'foo', 'Hyperkinesis', 'MESH:D006948',
                'marker/mechanism', 'bar', 'baz', 'foo', '19098162']

        self.ctd._process_interactions(row1)
        self.ctd._process_interactions(row2)

    def tearDown(self):
        self.ctd.graph = None
        self.ctd = None

    def test_therapeutic_relationship(self):
        from dipper.utils.TestUtils import TestUtils
        from dipper.utils.GraphUtils import GraphUtils

        # Make testutils object and load bindings
        test_query = TestUtils(self.ctd.graph)
        self.ctd.load_bindings()

        # Expected structure
        sparql_query = """
                       SELECT ?assoc ?pubmed ?disease ?chemical
                       WHERE {
                       ?assoc a Annotation: ;
                           dc:evidence OBO:ECO_0000033 ;
                           dc:source ?pubmed ;
                           :hasObject ?disease ;
                           :hasPredicate OBO:RO_0002606 ;
                           :hasSubject ?chemical .}
                       """

        # SPARQL variables to check
        gu = GraphUtils(curie_map.get())
        chem_id = 'MESH:D009538'
        chem_uri = gu.getNode(chem_id)
        disease_id = 'OMIM:188890'
        disease_uri = gu.getNode(disease_id)
        pubmed_id = 'PMID:16785264'
        pubmed_uri = gu.getNode(pubmed_id)
        rel_id = gu.object_properties['substance_that_treats']
        eco = 'ECO:0000033'

        assoc_id = self.ctd.make_association_id('ctd', chem_id, rel_id, disease_id, eco, pubmed_id)
        assoc_uri = gu.getNode(assoc_id)

        # Expected output from query
        expected_output = [assoc_uri, pubmed_uri, disease_uri, chem_uri]

        # Query graph
        sparql_output = test_query.query_graph(sparql_query)

        self.assertTrue(expected_output in sparql_output)

        logger.info("Test finished.")
Exemple #6
0
 def setUp(self):
     self.source = CTD()
     self.source.settestonly(True)
     self.source.setnobnodes(True)
     self._setDirToSource()
     return
Exemple #7
0
 def setUp(self):
     self.source = CTD('rdf_graph', True)
     self.source.settestonly(True)
     self._setDirToSource()
     return
Exemple #8
0
class CTDTestCase(SourceTestCase):
    def setUp(self):
        self.source = CTD('rdf_graph', True)
        self.source.settestonly(True)
        self._setDirToSource()
        return

    def tearDown(self):
        self.source = None
        return

    def test_therapeutic_relationship(self):
        from dipper.utils.TestUtils import TestUtils
        from dipper.models.Model import Model

        # Make testutils object and load ttl
        test_query = TestUtils(self.source.graph)
        test_query.load_testgraph_from_turtle(self.source)
        graph = self.source.graph
        model = Model(graph)

        # Expected structure
        # TODO can this be unified OBAN and the Annot models
        # to be automatically generated?
        sparql_query = """
                       SELECT ?assoc ?disease ?rel ?chemical
                       WHERE {
                           ?assoc a OBAN:association ;
                           OBAN:association_has_object ?disease ;
                           OBAN:association_has_predicate ?rel ;
                           OBAN:association_has_subject ?chemical .}
                       """

        # SPARQL variables to check
        chem_id = 'MESH:D009538'
        chem_uri = graph._getNode(chem_id)
        disease_id = 'OMIM:188890'
        disease_uri = graph._getNode(disease_id)
        rel_id = model.object_properties['substance_that_treats']
        rel_uri = graph._getNode(rel_id)
        # TODO unused
        # pubmed_id = 'PMID:16785264'
        # pubmed_uri = gu.getNode(pubmed_id)
        # eco = 'ECO:0000033'

        assoc = G2PAssoc(graph, self.source.name, chem_id, disease_id, rel_id)
        assoc_id = assoc.make_g2p_id()
        assoc_uri = self.source.graph._getNode(assoc_id)

        # One of the expected outputs from query
        expected_output = [assoc_uri, disease_uri, rel_uri, chem_uri]

        # Query graph
        sparql_output = test_query.query_graph(sparql_query)

        self.assertTrue(
            expected_output in sparql_output,
            "did not find expected association: " + str(expected_output) +
            " found " +
            str(len(sparql_output)) + " others:\n" + str(sparql_output))

        logger.info("Test query data finished.")