def correlation_results(request, ids=None): """ Shows the correlation result """ context = { 'phenotype_ids': ids } context.update(base_context(request)) return render(request, 'phenotypedb/correlation_results.html', context)
def upload_file(request): """ View that is displayed for uploading a study/submission """ if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): try: submission = form.save() email = EmailMessage( submission.get_email_subject(), submission.get_email_text(), settings.EMAIL_ADDRESS, [submission.email], [settings.EMAIL_ADDRESS], reply_to=[settings.EMAIL_ADDRESS] ) email.send(True) return HttpResponseRedirect('/submission/%s/' % submission.id) except Accession.DoesNotExist as err: form.add_error(None, 'Unknown accession with ID: %s' % err.args[-1]) except Exception as err: form.add_error(None, str(err)) else: form = UploadFileForm() context = { 'form': form } context.update(base_context(request)) return render(request, 'home/upload.html', context)
def submit_feedback(request): """ View to submit issues and feedback """ if request.method == 'POST': form = SubmitFeedbackForm(request.POST) if form.is_valid(): try: firstname = form.cleaned_data['firstname'] lastname = form.cleaned_data['lastname'] from_email = form.cleaned_data['email'] message = form.cleaned_data['message'] email = EmailMessage( subject=settings.APP_NAME + '-Feedback', from_email=from_email, to=[settings.EMAIL_ADDRESS], body=message, bcc=[settings.EMAIL_ADDRESS], reply_to=[settings.EMAIL_ADDRESS] ) email.send(True) return HttpResponseRedirect('/feedback/success/') except Exception as err: form.add_error(None, str(err)) else: form = SubmitFeedbackForm() context = { 'form': form } context.update(base_context(request)) return render(request, 'home/feedback.html', context)
def list_ontology_sources(request): """ Displays list of ontologies """ context = { 'objects': OntologySource.objects.all() } context.update(base_context(request)) return render(request, 'phenotypedb/ontologysource_list.html', context)
def get_context_data(self, **kwargs): context = super(PhenotypeDetail, self).get_context_data(**kwargs) context['pheno_acc_infos'] = self.object.phenotypevalue_set.select_related('obs_unit__accession') # Determine unique Accessions, total and by country # The following *should* work, but SQLite does not implement the DISTINCT ON tag. # context['geo_chart_data'] = Accession.objects.filter(observationunit__phenotypevalue__phenotype_id=self.object.pk).distinct('id').values('country').annotate(count=Count('country')) # Instead, do it like this accs = Accession.objects.filter(observationunit__phenotypevalue__phenotype_id=self.object.pk) acc_dict = {} count_by_country = {} for acc in accs : if acc.id not in acc_dict : acc_dict[acc.id] = acc if len(acc.country) > 0 : # since unknown countries do not appear on the map, and may have a higher count, # do not include them in count_by_country try : count_by_country[acc.country] = count_by_country[acc.country] + 1 except : count_by_country[acc.country] = 1 context['num_unique_accessions'] = len(acc_dict) context['geo_chart_data'] = count_by_country context['values'] = self.object.phenotypevalue_set.all().values_list("value", flat=True) context['shapiro'] = "%.2e"%shapiro(context['values'])[1] context.update(base_context(self.request)) return context
def get_context_data(self, **kwargs): context = super(SubmissionStudyResult, self).get_context_data(**kwargs) phenotype_table = CurationPhenotypeTable(Phenotype.objects.in_submission().filter(study__id=self.object.id), order_by="name") RequestConfig(self.request, paginate={"per_page":20}).configure(phenotype_table) context['curation_phenotype_table'] = phenotype_table context['submission'] = self.object.submission context.update(base_context(self.request)) return context
def get_context_data(self, **kwargs): context = super(SubmissionPhenotypeResult, self).get_context_data(**kwargs) context['submission'] = self.object.study.submission context['uo_terms'] = OntologyTerm.objects.uo_terms() context['to_terms'] = OntologyTerm.objects.to_terms() context['eo_terms'] = OntologyTerm.objects.eo_terms() context.update(base_context(self.request)) return context
def transformation_results(request, pk): """ SHow transformation result """ phenotype = Phenotype.objects.get(id=pk) data = calculate_phenotype_transformations(phenotype) data['object'] = phenotype data.update(base_context(request)) return render(request, 'phenotypedb/transformation_results.html', data)
def get_context_data(self, **kwargs): context = super(RNASeqDetail, self).get_context_data(**kwargs) context['pheno_acc_infos'] = self.object.rnaseqvalue_set.select_related('obs_unit__accession') context['geo_chart_data'] = Accession.objects.filter(observationunit__rnaseqvalue__rnaseq_id=self.object.pk).values('country').annotate(count=Count('country')) context['values'] = self.object.rnaseqvalue_set.all().values_list("value", flat=True) context['shapiro'] = "%.2e"%shapiro(context['values'])[1] context['is_rnaseq'] = True context.update(base_context(self.request)) return context
def list_rnaseqs(request): """ Displays table of all published RNASeq """ table = RNASeqTable(RNASeq.objects.all(), order_by="name") RequestConfig(request, paginate={"per_page":50}).configure(table) context = { 'rnaseq_table': table, 'is_rnaseq': True } context.update(base_context(request)) return render(request, 'phenotypedb/rnaseq_data_list.html', context)
def list_phenotypes(request): """ Displays table of all published phenotypes """ table = PhenotypeTable(Phenotype.objects.annotate(num_values=Count('phenotypevalue')).published(), order_by="name") RequestConfig(request, paginate={"per_page":20}).configure(table) context = { 'phenotype_table': table } context.update(base_context(request)) return render(request, 'phenotypedb/phenotype_list.html', context)
def rnaseq_transformation_results(request, pk): """ SHow transformation result """ rnaseq = RNASeq.objects.get(id=pk) data = calculate_phenotype_transformations(rnaseq, rnaseq=True) data['object'] = rnaseq data['is_rnaseq'] = True data.update(base_context(request)) return render(request, 'phenotypedb/rnaseq_transformation_results.html', data)
def list_studies(request): """ Displays table of all published studies """ studies = Study.objects.published().annotate(pheno_count=Count('phenotype')).annotate(rna_count=Count('rnaseq')) studies = studies.filter(pheno_count__gt=0).filter(rna_count=0) table = StudyTable(studies, order_by="-update_date") RequestConfig(request, paginate={"per_page":20}).configure(table) context = { 'study_table': table } context.update(base_context(request)) return render(request, 'phenotypedb/study_list.html', context)
def correlation_wizard(request): """ Shows the correlation wizard form """ wizard_form = CorrelationWizardForm() if "phenotype_search" in request.POST: query = request.POST.getlist("phenotype_search") query = ",".join(map(str,query)) return HttpResponseRedirect("/correlation/" + query + "/") context = { 'phenotype_wizard': wizard_form } context.update(base_context(request)) return render(request, 'phenotypedb/correlation_wizard.html', context)
def transformation_wizard(request): """ Shows the transformation wizard form """ wizard_form = TransformationWizardForm() if "phenotype_search" in request.POST: query = request.POST.getlist("phenotype_search") #query = ",".join(map(str,query)) return HttpResponseRedirect("/phenotype/" + str(query[0]) + "/transformation/") context = { 'transformation_wizard': wizard_form } context.update(base_context(request)) return render(request, 'phenotypedb/transformation_wizard.html', context)
def list_rnaseq_studies(request): """ Displays table of all published RNASeq """ # Only keep rnaseq studies # studies = Study.objects.filter(phenotype__count=0) studies = Study.objects.annotate(pheno_count=Count('phenotype')).annotate(rna_count=Count('rnaseq')) studies = studies.filter(pheno_count=0).filter(rna_count__gt=0) table = RNASeqStudyTable(studies, order_by="name") RequestConfig(request, paginate={"per_page":50}).configure(table) context = { 'study_table': table, 'is_rnaseq': True } context.update(base_context(request)) return render(request, 'phenotypedb/rnaseq_study_list.html', context)
def detail_accession(request, pk=None): """ Detailed view of a single accession """ accession = Accession.objects.get(id=pk) phenotype_table = AccessionPhenotypeTable(pk,Phenotype.objects.published().filter(phenotypevalue__obs_unit__accession_id=pk).annotate(num_values=Count('phenotypevalue')), order_by="name") RequestConfig(request, paginate={"per_page":20}).configure(phenotype_table) variable_dict = {} variable_dict["phenotype_table"] = phenotype_table variable_dict["object"] = accession phenotypes = Phenotype.objects.published().filter(phenotypevalue__obs_unit__accession_id=pk) variable_dict['phenotype_count'] = phenotypes.count() variable_dict['to_data'] = phenotypes.values('to_term__name').annotate(count=Count('to_term__name')) variable_dict['eo_data'] = phenotypes.values('eo_term__name').annotate(count=Count('eo_term__name')) variable_dict['uo_data'] = phenotypes.values('uo_term__name').annotate(count=Count('uo_term__name')) variable_dict.update(base_context(request)) return render(request, 'phenotypedb/accession_detail.html', variable_dict)
def list_accessions(request): """ Displays table with all accessions """ filtered_genotypes = set(map(int,request.POST.getlist('genotypes'))) if len(filtered_genotypes) > 0: accessions = Accession.objects.annotate(count_phenotypes=Count('observationunit__phenotypevalue__phenotype', distinct=True)).prefetch_related('genotype_set').filter(genotype__pk__in = filtered_genotypes) else: accessions = Accession.objects.annotate(count_phenotypes=Count('observationunit__phenotypevalue__phenotype', distinct=True)).prefetch_related('genotype_set').all() table = AccessionTable(accessions, order_by="name") genotypes = Genotype.objects.all() for genotype in genotypes: genotype.selected = genotype.pk in filtered_genotypes RequestConfig(request, paginate={"per_page":20}).configure(table) context = { 'accession_table': table, 'genotypes': genotypes, 'filtered_genotypes': list(filtered_genotypes) } context.update(base_context(request)) return render(request, 'phenotypedb/accession_list.html', context)
def detail_ontology_source(request,acronym,term_id=None): """ Detailed view of OntologySource """ variable_dict = {} source = OntologySource.objects.get(acronym=acronym) variable_dict['object'] = source root_nodes = source.ontologyterm_set.filter(parents=None) tree = None if term_id is not None: tree = [] term = OntologyTerm.objects.get(pk=term_id) tree = _get_tree_to_root(term,root_nodes) else: tree = [{'id':term.pk,'text':term.name,'children':True if term.children.count() > 0 else False} for term in root_nodes] variable_dict['tree'] = json.dumps(tree) variable_dict['base_url'] = settings.BASE_URL variable_dict.update(base_context(request)) return render(request, 'phenotypedb/ontologysource_detail.html', variable_dict)
def detail_study(request, pk=None): """ Detailed view of a single study """ study = Study.objects.published().get(id=pk) # Check if RNASeq or Phenotypes: is_rnaseq = False if len(Phenotype.objects.published().filter(study__id=pk)) > 0: phenotype_table = ReducedPhenotypeTable(Phenotype.objects.published().filter(study__id=pk).annotate(num_values=Count('phenotypevalue')), order_by="name") else: phenotype_table = RNASeqTable(RNASeq.objects.filter(study__id=pk), order_by="name") is_rnaseq = True RequestConfig(request, paginate={"per_page":20}).configure(phenotype_table) variable_dict = {} variable_dict["phenotype_table"] = phenotype_table variable_dict["study"] = study variable_dict['to_data'] = study.phenotype_set.values('to_term__name').annotate(count=Count('to_term__name')) variable_dict['eo_data'] = study.phenotype_set.values('eo_term__name').annotate(count=Count('eo_term__name')) variable_dict['uo_data'] = study.phenotype_set.values('uo_term__name').annotate(count=Count('uo_term__name')) variable_dict['is_rnaseq'] = is_rnaseq variable_dict.update(base_context(request)) return render(request, 'phenotypedb/study_detail.html', variable_dict)
def detail_ontology_term(request,pk=None): """ Detailed view of Ontology """ variable_dict = {} phenotypes = [] if pk is not None: term = OntologyTerm.objects.get(pk=pk) variable_dict["object"] = term db_field = _get_db_field_from_source(term.source) + '_id__in' ids = _get_ontology_terms(term) #necessary because sqlite has a limit of 999 SQL variables ids = [ ids[i:i+500] for i in range(0, len(ids), 500) ] for sub in ids: kwargs = {db_field:sub} phenotypes.extend(Phenotype.objects.published().filter(**kwargs)) variable_dict['phenotype_count'] = len(phenotypes) phenotype_table = PhenotypeTable(phenotypes, order_by="name") RequestConfig(request, paginate={"per_page":20}).configure(phenotype_table) variable_dict["phenotype_table"] = phenotype_table variable_dict.update(base_context(request)) return render(request, 'phenotypedb/ontologyterm_detail.html', variable_dict)
def download(request): """ Download data """ return render(request, 'phenotypedb/download.html', base_context(request))
def submit_feedback_success(request): return render(request, 'home/feedback_success.html', base_context(request))
def get_context_data(self, **kwargs): context = super(SubmissionStudyDeleteView, self).get_context_data(**kwargs) context['submission'] = self.object.submission context.update(base_context(self.request)) return context