def test_get_disease_tags_from_results(self):
        config = IniParser().read_ini(MY_INI_FILE)
        feature_id = self.get_random_feature_id()

        criteria_details = GeneCriteria.get_criteria_details(feature_id, config=config)
        dis_codes = GeneCriteria.get_disease_codes_from_results(criteria_details)
        self.assertTrue(len(dis_codes) > 0, 'Got disease codes')
    def test_get_criteria_details(self):
        config = IniParser().read_ini(MY_INI_FILE)
        idx = ElasticSettings.idx('GENE_CRITERIA')
        available_criterias = GeneCriteria.get_available_criterias(config=config)['gene']
        idx_type = ','.join(available_criterias)
        doc_by_idx_type = ElasticUtils.get_rdm_docs(idx, idx_type, size=1)
        self.assertTrue(len(doc_by_idx_type) > 0)
        feature_id = getattr(doc_by_idx_type[0], 'qid')

        criteria_details = GeneCriteria.get_criteria_details(feature_id, config=config)

        hits = criteria_details['hits']
        first_hit = hits[0]
        _type = first_hit['_type']
        _index = first_hit['_index']
        _id = first_hit['_id']
        _source = first_hit['_source']

        disease_tag = _source['disease_tags'][0]
        self.assertTrue(feature_id, _id)
        self.assertIn(_type, idx_type)
        self.assertTrue(idx, _index)
        self.assertIn(disease_tag, list(_source.keys()))

        fdetails = _source[disease_tag][0]
        self.assertIn('fid', fdetails.keys())
        self.assertIn('fname', fdetails.keys())
    def test_gene_in_region(self):
        ''' Test process_gene_in_region. '''
        config = IniParser().read_ini(MY_INI_FILE)

        # pass a region document
        criteria_results = GeneCriteria.gene_in_region(self.region_doc_full, config=config, result_container={})
        expected_dict = {'ENSG00000279625': {'IBD': [{'fid': '1p36.12_008', 'fname': '1p36.12'}],
                                             'UC': [{'fid': '1p36.12_008', 'fname': '1p36.12'}]}}
        self.assertEqual(criteria_results, expected_dict, 'Got regions in gene as expected')

        criteria_results_17q = GeneCriteria.gene_in_region(self.region_doc_17q, config=config,
                                                           result_container={})
        self.assertTrue(len(criteria_results_17q) > 20, "Got back results greater than the default size")
    def test_get_disease_tags_as_codes(self):

        feature_id = 'ENSG00000134242'
        disease_docs = GeneCriteria.get_disease_tags(feature_id)
        disease_codes = GeneCriteria.get_disease_tags_as_codes(feature_id)
        self.assertEqual(len(disease_docs), len(disease_codes), 'Got the same disease code size')

        print(len(disease_docs))
        print(len(disease_codes))

        doc1 = disease_docs[0]
        dis1 = disease_codes[0]

        self.assertTrue(isinstance(doc1, disease.document.DiseaseDocument), 'Got the disease doc')
        self.assertTrue(isinstance(dis1, str), 'Got the disease code')
 def test_available_criterias(self):
     config = IniParser().read_ini(MY_INI_FILE)
     available_criterias = GeneCriteria.get_available_criterias(config=config)
     expected_dict = {'gene': ['cand_gene_in_study', 'gene_in_region', 'is_gene_in_mhc', 'cand_gene_in_region']}
     self.assertIsNotNone(available_criterias, 'Criterias as not none')
     self.assertIn('cand_gene_in_study', available_criterias['gene'])
     self.assertEqual(available_criterias.keys(), expected_dict.keys(), 'Dic keys equal')
    def test_get_disease_tags(self):

        # feature_id = self.get_random_feature_id()
        feature_id = 'ENSG00000134242'
        disease_docs = GeneCriteria.get_disease_tags(feature_id)

        disease_tags = [getattr(disease_doc, 'code') for disease_doc in disease_docs]
        self.assertTrue(len(disease_tags) > 0, 'disease_tags present')
 def get_random_feature_id(self):
     config = IniParser().read_ini(MY_INI_FILE)
     idx = ElasticSettings.idx('GENE_CRITERIA')
     available_criterias = GeneCriteria.get_available_criterias(config=config)['gene']
     idx_type = ','.join(available_criterias)
     doc_by_idx_type = ElasticUtils.get_rdm_docs(idx, idx_type, size=1)
     self.assertTrue(len(doc_by_idx_type) > 0)
     feature_id = getattr(doc_by_idx_type[0], 'qid')
     return feature_id
    def test_tag_feature_to_disease(self):
        ''' Test tag_feature_to_disease. '''
        config = IniParser().read_ini(MY_INI_FILE)
        result1 = GeneCriteria.tag_feature_to_disease(self.region_doc_full, "gene_in_region", config, {})
        # one region tagged to UC and IBD
        expected_result = {'ENSG00000279625': {'IBD': [{'fname': '1p36.12', 'fid': '1p36.12_008'}],
                                               'UC': [{'fname': '1p36.12', 'fid': '1p36.12_008'}]}}
        self.assertEqual(result1, expected_result, 'Got back expected result')

        result2 = GeneCriteria.tag_feature_to_disease(self.study_doc_full, "cand_gene_in_study", config, {})
        expected_result = {'ENSG00000160801': {'RA': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}],
                                               'T1D': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}]},
                           'ENSG00000163599': {'RA': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}],
                                               'T1D': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}]},
                           'ENSG00000110800': {'RA': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}],
                                               'T1D': [{'fname': 'Clatfield XY', 'fid': 'GDXHsS00005'}]}}

        self.assertEqual(result2, expected_result, 'Got back expected result')
    def test_get_all_criteria_disease_tags(self):

        feature_id1 = 'ENSG00000134242'
        feature_id2 = 'ENSG00000227609'
        criteria_disease_tags = GeneCriteria.get_all_criteria_disease_tags([feature_id1,
                                                                            feature_id2])

        self.assertIn(feature_id1, criteria_disease_tags)
        self.assertIn(feature_id2, criteria_disease_tags)
        self.assertIn('all', criteria_disease_tags[feature_id1])
        self.assertIn('all', criteria_disease_tags[feature_id2])
    def test_exonic_index_snp_in_gene(self):
        ''' Test exonic_index_snp_in_gene. '''
        config = IniParser().read_ini(MY_INI_FILE)

        # pass a region document
        criteria_results = GeneCriteria.exonic_index_snp_in_gene(self.region_hit,
                                                                 config=config, result_container={})

        expected_result = {'ENSG00000226167': {'RA': [{'fid': 'rs2476601',
                                                       'fnotes': {'linkname': 'Eyre S', 'linkid': 'GDXHsS00019'},
                                                       'fname': 'rs2476601'}]},
                           'ENSG00000134242': {'RA': [{'fid': 'rs2476601',
                                                       'fnotes': {'linkname': 'Eyre S', 'linkid': 'GDXHsS00019'},
                                                       'fname': 'rs2476601'}]}}
        self.assertEqual(criteria_results, expected_result, 'Got back expected result')
Example #11
0
 def criteria_disease_tags(cls, request, qids):
     ''' Get criteria disease tags for a given ensembl ID for all criterias. '''
     criteria_disease_tags = GeneCriteria.get_all_criteria_disease_tags(qids)
     return criteria_disease_tags
Example #12
0
def criteria_details(request):
    ''' Get criteria details for a given ensembl ID. '''
    ens_id = request.POST.get('feature_id')
    criteria_details = GeneCriteria.get_criteria_details(ens_id)
    return JsonResponse(criteria_details)
    def test_cand_gene_in_study(self):
        config = IniParser().read_ini(MY_INI_FILE)

        input_doc = {'_source': {'diseases': ['T1D', 'MS'],
                     'genes': ['ENSG00000110848', 'ENSG00000160791', 'ENSG00000163599'],
                     'study_id': 'GDXHsS00004', 'authors': ['Barrett', 'Type 1 Diabetes Genetics Consortium'],
                     'authors': [
                            {
                             'name': "Barrett",
                             'initials': "JC"
                            },
                            {
                             'name': "Type 1 Diabetes Genetics Consortium",
                             'initials': ""
                            }
                            ]},
                     '_type': 'studies',
                     '_index': 'studies_latest', '_id': 'GDXHsS00004', '_score': 0.0}

        expected_doc = {'ENSG00000110848': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]},
                        'ENSG00000160791': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]},
                        'ENSG00000163599': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]}}

        result_doc = GeneCriteria.cand_gene_in_study(input_doc, config=config, result_container={})

        self.assertEqual(expected_doc, result_doc, 'dicts are equal and as expected')

        input_doc = {'_source': {'diseases': ['RA', 'T1D'],
                     'genes': ['ENSG00000110800', 'ENSG00000160801', 'ENSG00000163599'],
                     'study_id': 'GDXHsS00005',
                     'authors': [
                            {
                             'name': "Clatfield",
                             'initials': "XY"
                            },
                            {
                             'name': "Type 1 Diabetes Genetics Consortium",
                             'initials': ""
                            }
                            ]},
                     '_type': 'studies',
                     '_index': 'studies_latest', '_id': 'GDXHsS00005', '_score': 0.0}

        expected_doc = {'ENSG00000160801': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'T1D': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000163599': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'MS': [{'fid': 'GDXHsS00004', 'fname': 'Barrett JC'}],
                                            'T1D': [{'fid': 'GDXHsS00004', 'fname': 'Barrett JC'},
                                                    {'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000160791': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]},
                        'ENSG00000110800': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'T1D': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000110848': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]}}

        updated_doc = GeneCriteria.cand_gene_in_study(input_doc, config=config, result_container=result_doc)
        self.assertEqual(expected_doc, updated_doc, 'dicts are equal and as expected')

        input_doc = {'_source': {'diseases': ['AA'],
                     'genes': ['ENSG00000110900'],
                     'study_id': 'GDXHsS00006', 'authors': [{'name': 'AaTestAuthor', 'initials': 'TT'}]},
                     '_type': 'studies',
                     '_index': 'studies_latest', '_id': 'GDXHsS00006', '_score': 0.0}

        expected_doc = {'ENSG00000160801': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'T1D': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000163599': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'MS': [{'fid': 'GDXHsS00004', 'fname': 'Barrett JC'}],
                                            'T1D': [{'fid': 'GDXHsS00004', 'fname': 'Barrett JC'},
                                                    {'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000160791': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]},
                        'ENSG00000110800': {'RA': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}],
                                            'T1D': [{'fid': 'GDXHsS00005', 'fname': 'Clatfield XY'}]},
                        'ENSG00000110900': {'AA': [{'fid': 'GDXHsS00006', 'fname': 'AaTestAuthor TT'}]},
                        'ENSG00000110848': {'T1D': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}],
                                            'MS': [{'fname': 'Barrett JC', 'fid': 'GDXHsS00004'}]}}

        updated_doc = GeneCriteria.cand_gene_in_study(input_doc, config=config, result_container=result_doc)
        self.assertEqual(expected_doc, updated_doc, 'dicts are equal and as expected')