Exemple #1
0
def show_disease_bar(dis_list=None, expand_od=False, selected=None, href="/disease/"):
    ''' Template inclusion tag to render disease bar. '''
    if type(dis_list) is str:
        dis_list = [dis_list]
    (main, other) = Disease.get_site_diseases(dis_list=dis_list)
    return {'dis_main': main, 'dis_other': other, 'text': True, 'selected': selected, 'href': href,
            'expand_od': expand_od}
Exemple #2
0
    def get_context_data(self, **kwargs):
        context = super(StudiesEntryView, self).get_context_data(**kwargs)
        studies = StudyDocument.get_studies(sources=['study_id', 'study_name', 'diseases',
                                                     'principal_paper', 'authors'])
        for doc in studies:
            setattr(doc, 'study_id', getattr(doc, 'study_id').replace('GDXHsS00', ''))
            pmid = getattr(doc, 'principal_paper')
            pubs = PublicationDocument.get_publications(pmid, sources=['date'])
            if len(pubs) > 0:
                setattr(doc, 'date', getattr(pubs[0], 'date'))

        context['studies'] = studies
        (core, other) = Disease.get_site_diseases()
        diseases = list(core)
        diseases.extend(other)
        context['diseases'] = diseases

        for dis in diseases:
            docs = DiseaseLocusDocument.get_disease_loci_docs(getattr(dis, 'code'))
            # get visible/authenticated hits id's
            visible_hits = DiseaseLocusDocument.get_hits([h for r in docs for h in getattr(r, 'hits')],
                                                         sources=['seqid'])
            visible_hits_ids = [h.doc_id() for h in visible_hits]
            regions = 0
            for r in docs:
                hits = getattr(r, 'hits')
                for h in hits:
                    if h in visible_hits_ids:
                        regions += 1
                        break
            # number of visible regions
            setattr(dis, 'count', regions)

        return context
Exemple #3
0
    def get_disease_tags(cls, feature_id, idx=None, idx_type=None):
        ''' function to get the aggregated list of disease_tags for a given feature id, aggregated
            from all criteria_types for a feature type
        @type  feature_id: string
        @keyword feature_id: Id of the feature (gene => gene_id, region=>region_id)
              @type  idx: string
        @param idx: name of the index
        @type  idx_type: string
        @param idx_type: name of the idx type, each criteria is an index type
        '''
        query = ElasticQuery(Query.term("qid", feature_id))
        agg = Agg("criteria_disease_tags", "terms", {"field": "disease_tags", "size": 0})
        aggs = Aggs(agg)

        if idx_type:
            search = Search(query, aggs=aggs, idx=idx, idx_type=idx_type)
        else:
            search = Search(query, aggs=aggs, idx=idx)

        disease_tags = []
        try:
            r_aggs = search.search().aggs
            buckets = r_aggs['criteria_disease_tags'].get_buckets()
            disease_tags = [dis_dict['key'].lower() for dis_dict in buckets]
        except:
            return []

        # get disease docs
        if (len(disease_tags) > 0):
            (core, other) = Disease.get_site_diseases(dis_list=disease_tags)
            diseases = list(core)
            diseases.extend(other)
            return diseases
        else:
            return None
Exemple #4
0
    def get_regions(cls, request, dis, context):
        # is_authenticated = False
        elastic_url = ElasticSettings.url()

        (core, other) = Disease.get_site_diseases(dis_list=dis.upper().split(','))
        if len(core) == 0 and len(other) == 0:
            messages.error(request, 'Disease '+dis+' not found.')
            raise Http404()

        disease = core[0] if len(core) > 0 else other[0]
        context['title'] = getattr(disease, "name")+" Regions"

        docs = DiseaseLocusDocument.get_disease_loci_docs(dis)
        if len(docs) == 0:
            messages.error(request, 'No regions found for '+dis+'.')
            raise Http404()

        visible_hits = DiseaseLocusDocument.get_hits([h for r in docs for h in getattr(r, 'hits')])
        meta_response = Search.elastic_request(elastic_url, ElasticSettings.idx("IC_STATS") + '/_mapping',
                                               is_post=False)
        regions = []
        ens_all_cand_genes = []
        all_markers = []
        for r in docs:
            region = r.get_disease_region(visible_hits)
            if region is not None:
                ens_all_cand_genes.extend(region['ens_cand_genes'])
                all_markers.extend(region['markers'])
                region['hits'] = StudyHitDocument.process_hits(r.hit_docs, region['all_diseases'])

                (all_coding, all_non_coding) = get_genes_for_region(getattr(r, "seqid"),
                                                                    region['rstart']-500000, region['rstop']+500000)
                (region_coding, coding_up, coding_down) = _region_up_down(all_coding, region['rstart'], region['rstop'])
                (region_non_coding, non_coding_up, non_coding_down) = \
                    _region_up_down(all_non_coding, region['rstart'], region['rstop'])
                region['genes'] = {
                    'upstream': {'coding': coding_up, 'non_coding': non_coding_up},
                    'region': {'coding': region_coding, 'non_coding': region_non_coding},
                    'downstream': {'coding': coding_down, 'non_coding': non_coding_down},
                }
                regions.append(region)

        # look for pleiotropy by looking for diseases for the markers in IC_STATS and other study hits
        stats_query = ElasticQuery.filtered(Query.terms("marker", all_markers),
                                            Filter(RangeQuery("p_value", lte=5E-08)))
        stats_docs = Search(stats_query, idx=ElasticSettings.idx("IC_STATS"), size=len(all_markers)).search().docs

        # get ensembl to gene symbol mapping for all candidate genes
        all_cand_genes = gene.utils.get_gene_docs_by_ensembl_id(ens_all_cand_genes)
        for region in regions:
            region['cand_genes'] = {cg: all_cand_genes[cg] for cg in region.pop("ens_cand_genes", None)}
            (study_ids, region['marker_stats']) = _process_stats(stats_docs, region['markers'], meta_response)

            # add diseases from IC/GWAS stats
            region['all_diseases'].extend([getattr(mstat, 'disease') for mstat in region['marker_stats']])

            other_hits_query = ElasticQuery(
                        BoolQuery(must_arr=[RangeQuery("tier", lte=2), Query.terms("marker", region['markers'])],
                                  must_not_arr=[Query.terms("dil_study_id", study_ids)]))
            other_hits = Search(other_hits_query, idx=ElasticSettings.idx('REGION', 'STUDY_HITS'), size=100).search()
            region['extra_markers'] = StudyHitDocument.process_hits(other_hits.docs, region['all_diseases'])

        context['regions'] = regions
        context['disease_code'] = [dis]
        context['disease'] = getattr(disease, "name")
        return context
Exemple #5
0
def show_small_disease_bar(dis_list=None, href="/disease/"):
    ''' Template inclusion tag to render disease bar. '''
    (main, other) = Disease.get_site_diseases(dis_list=dis_list)
    if len(other) > 0:
        main.append(Document({"_source": {"code": "OD", "colour": "grey", "name": "Other Diseases"}}))
    return {'dis_main': main, 'text': False, 'href': href}
Exemple #6
0
def show_disease_bar():
    ''' Template inclusion tag to render disease bar. '''
    (main, other) = Disease.get_site_diseases()
    return {'dis_main': main, 'dis_other': other}
Exemple #7
0
 def test_site_disease_codes(self):
     ''' Test getting all diseases on the site '''
     from disease.utils import Disease
     (main, other) = Disease.get_site_disease_codes()
     self.assertEqual(12, len(main), "12 main diseases found ")
     self.assertEqual(7, len(other), "7 other diseases found when searching for other diseases")
Exemple #8
0
 def test_main_diseases(self):
     ''' Test getting all diseases on the site '''
     from disease.utils import Disease
     (main, other) = Disease.get_site_diseases(tier=0)
     self.assertEqual(12, len(main), "12 main diseases found when searching for main diseases")
     self.assertEqual(0, len(other), "0 other diseases found when searching for main diseases")