def setUp(self):
     """ construct a ICSimilarity object and terms per proband for unit tests
     """
     
     path = os.path.join(os.path.dirname(__file__), "data", "obo.txt")
     self.hpo_graph, _, _ = open_ontology(path)
     
     self.hpo_terms = {
         "person_01": ["HP:0000924"],
         "person_02": ["HP:0000118", "HP:0002011"],
         "person_03": ["HP:0000707", "HP:0002011"]
     }
     
     self.hpo_graph.tally_hpo_terms(self.hpo_terms)
示例#2
0
    def test_get_graph(self):
        """ test that building a graph with get_graph works correctly
        """

        graph, alt_ids, obsolete = open_ontology(self.path)

        # check that all the nodes (aside from the obsolete node) have been
        # included
        self.assertEqual(set(graph.nodes()), \
            set(['HP:0000001', 'HP:0000118', 'HP:0000707', 'HP:0000924', 'HP:0002011',]))

        # check that the graph info is set correctly from the HPO header
        self.assertEqual(graph.graph, HEADER)

        # check that the edges match what is expected foir each node
        self.assertEqual(list(graph.edges('HP:0000001')),
                         [("HP:0000001", "HP:0000118")])
        self.assertEqual(set(graph.edges('HP:0000118')), \
            set([("HP:0000118", "HP:0000707"), ("HP:0000118", "HP:0000924")]))
        self.assertEqual(list(graph.edges('HP:0000924')), [])

        # check that, as part of setting the graph up, we have constructed the
        # correct set of obsolete IDs
        self.assertEqual(obsolete, set(["HP:0000489"]))
示例#3
0
def main():
    
    options = get_options()
    
    # build a graph of HPO terms, so we can trace paths between terms
    graph, alt_ids, obsolete = open_ontology(options.ontology)
    
    # load HPO terms and probands for each gene
    print("loading HPO terms and probands by gene")
    hpo_by_proband = load_participants_hpo_terms(options.phenotypes_path, \
        alt_ids, obsolete)
    probands_by_gene = load_genes(options.genes_path)
    
    if options.permute:
        probands_by_gene = permute_probands(probands_by_gene)
    
    graph.tally_hpo_terms(hpo_by_proband)
    
    print("analysing similarity")
    try:
        analyse_genes(graph, hpo_by_proband, probands_by_gene, \
            options.output, options.iterations, options.score_type)
    except KeyboardInterrupt:
        sys.exit("HPO similarity exited.")