def motif_comparison_post(request, step): """Process motif comparison forms.""" try: cur_site_insts = search.search_post_helper(request) except: message = "Please select at least one TF, species and experimental technique to search database." messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect( reverse(eval('motif_comparison_step%d' % step))) if not cur_site_insts.filter(site_type='motif_associated'): # If there is no motif-associated site, raise error message = "No results found for selected TF and species" messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect( reverse(eval('motif_comparison_step%d' % step))) # store search results request.session['compare_step_%s' % step] = cur_site_insts request.session.modified = True if step == 1: return HttpResponseRedirect(reverse(motif_comparison_step2)) else: # step2 # Render results # Get motif_associated and non-motif_associated curation site instances cur_site_insts_a = request.session['compare_step_1'] cur_site_insts_b = request.session['compare_step_2'] motif_a_reports = [ report.generate_view_reports_dict() for report in motif_report.make_reports(cur_site_insts_a) ] motif_a_ensemble_report = \ motif_report.make_ensemble_report(cur_site_insts_a).generate_view_reports_dict() motif_b_reports = [ report.generate_view_reports_dict() for report in motif_report.make_reports(cur_site_insts_b) ] motif_b_ensemble_report = \ motif_report.make_ensemble_report(cur_site_insts_b).generate_view_reports_dict() # clean session data from possible previous requests # ??? request.session['permute_motif_a'] = None request.session['permute_motif_b'] = None request.session.modified = True return render_to_response( "motif_compare_results.html", { 'form_title': FORM_TITLES[2], 'form_description': FORM_DESCRIPTIONS[2], 'motif_a_reports': motif_a_reports, 'motif_b_reports': motif_b_reports, 'motif_a_ensemble_report': motif_a_ensemble_report, 'motif_b_ensemble_report': motif_b_ensemble_report, }, context_instance=RequestContext(request))
def motif_comparison_post(request, step): """Process motif comparison forms.""" try: cur_site_insts = search.search_post_helper(request) except: message = "Please select at least one TF, species and experimental technique to search database." messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect(reverse(eval('motif_comparison_step%d' % step))) if not cur_site_insts.filter(site_type='motif_associated'): # If there is no motif-associated site, raise error message = "No results found for selected TF and species" messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect(reverse(eval('motif_comparison_step%d' % step))) # store search results request.session['compare_step_%s' % step] = cur_site_insts request.session.modified = True if step == 1: return HttpResponseRedirect(reverse(motif_comparison_step2)) else: # step2 # Render results # Get motif_associated and non-motif_associated curation site instances cur_site_insts_a = request.session['compare_step_1'] cur_site_insts_b = request.session['compare_step_2'] motif_a_reports = [report.generate_view_reports_dict() for report in motif_report.make_reports(cur_site_insts_a)] motif_a_ensemble_report = \ motif_report.make_ensemble_report(cur_site_insts_a).generate_view_reports_dict() motif_b_reports = [report.generate_view_reports_dict() for report in motif_report.make_reports(cur_site_insts_b)] motif_b_ensemble_report = \ motif_report.make_ensemble_report(cur_site_insts_b).generate_view_reports_dict() # clean session data from possible previous requests # ??? request.session['permute_motif_a'] = None request.session['permute_motif_b'] = None request.session.modified = True return render_to_response("motif_compare_results.html", {'form_title': FORM_TITLES[2], 'form_description': FORM_DESCRIPTIONS[2], 'motif_a_reports': motif_a_reports, 'motif_b_reports': motif_b_reports, 'motif_a_ensemble_report': motif_a_ensemble_report, 'motif_b_ensemble_report': motif_b_ensemble_report,}, context_instance=RequestContext(request))
def search_post(request): """Handler for database search request.""" def raise_validation_error(msg): """Check if all three steps have been submitted.""" messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect(reverse(search)) try: cur_site_insts = search_post_helper(request) # make reports reports = motif_report.make_reports(cur_site_insts) # make ensemble reports ensemble_report = motif_report.make_ensemble_report(cur_site_insts) if not reports: # If no results found, go back to the search page. message = "No search results that match your search criteria." return raise_validation_error(message) return render_to_response("search_results.html", { 'title': "", 'description': """Search results can be seen as individual reports (one report per TF/species) or as ensemble reports (multiple TF/species). """, 'all_cur_site_insts': [pk for report in reports for pk in report.get_all_cur_site_insts_ids()], 'reports': [report.generate_browse_result_dict() for report in reports], }, context_instance = RequestContext(request)) except: message = "Please select at least one TF, species and experimental technique to search database." return raise_validation_error(message)
def get_results_TF(request, type_, id): """GIven the type (TF or TF family) and the id of the object, return query results and list TF/species that have binding site data for the selected TF or TF family.""" if type_ == 'TF': TFs = [models.TF.objects.get(TF_id=id)] name = TFs[0].name desc = TFs[0].description elif type_ == 'TF_family': # Get all TFs under that family TF_family = models.TFFamily.objects.get(TF_family_id=id) TFs = models.TF.objects.filter(family=TF_family).all() name = TF_family.name desc = TF_family.description # get all curation-site-instance objects for browsed TFs assert TFs cur_site_insts = models.Curation_SiteInstance.objects.filter( curation__TF__in=TFs) # generate all reports reports = motif_report.make_reports(cur_site_insts) return render_to_response("browse_results.html", {'title': name, 'description': desc, 'all_cur_site_insts': [pk for report in reports for pk in report.get_all_cur_site_insts_ids()], 'reports': [report.generate_browse_result_dict() for report in reports],}, context_instance=RequestContext(request))
def get_results_tech(request, type_, id): """Given a technique category and an id describing that category object, retrieve all curation-site-instance objects that have a technique with the specified category.""" techniques = None if type_ in ['binding', 'expression']: techniques = models.ExperimentalTechnique.objects.filter( preset_function=type_) if type_ == 'binding': title = 'Detection of binding' desc = '' else: title = 'Assessment of expression' desc = '' elif type_ == 'binding_category': category = models.ExperimentalTechniqueCategory.objects.get( category_id=id) techniques = models.ExperimentalTechnique.objects.filter( categories=category, preset_function='binding') title = category.name desc = category.description elif type_ == 'expression_category': category = models.ExperimentalTechniqueCategory.objects.get( category_id=id) techniques = models.ExperimentalTechnique.objects.filter( categories=category, preset_function='expression') title = category.name desc = category.description elif type_ == 'technique': techniques = models.ExperimentalTechnique.objects.filter( technique_id=id) # make sure the technique id is valid assert techniques.count() > 0 title = techniques.all()[:1].get().name desc = techniques.all()[:1].get().description cur_site_insts = models.Curation_SiteInstance.objects.filter( experimental_techniques=techniques) # generate all reports reports = motif_report.make_reports(cur_site_insts) return render_to_response( "browse_results.html", { 'title': title, 'description': desc, 'reports': [report.generate_browse_result_dict() for report in reports] }, context_instance=RequestContext(request))
def view_reports(request): """Handler for the post request, performed on browse by TF/species/technique page. Given the list of motif-associated and non-motif-associated curation-site-instance ids, they are grouped by TF and species, and rendered""" # make sure that it is a POST request if not request.POST: return HttpResponseRedirect(reverse(base.views.home)) cur_site_inst_ids = request.POST["csi_list"].strip().split(',') # get all curation-site-instances cur_site_insts = models.Curation_SiteInstance.objects.filter(pk__in=cur_site_inst_ids) # integrate non-motif: if True, the experimental evidence and regulation # information from non-motif associated sites are integrated into the report integrate_non_motif = bool("integrate_non_motif" in request.POST) # Check if non-motif site integration is requested if integrate_non_motif: reports = motif_report.make_reports(cur_site_insts) else: # if not, exclude non-motif-associated sites before generating reports reports = motif_report.make_reports(cur_site_insts.exclude(site_type='non_motif_associated')) # combine reports into ensemble report ensemble_report = motif_report.merge_reports(reports) #ensemble_report = motif_report.make_ensemble_report(cur_site_insts) return render_to_response("view_reports.html", { "reports": [report.generate_view_reports_dict() for report in reports], "ensemble_report": ensemble_report.generate_view_reports_dict(), "cur_site_insts": ','.join(map(lambda x: str(x.pk), cur_site_insts)), "integrate_non_motif": integrate_non_motif, }, context_instance=RequestContext(request))
def get_results_taxonomy(request, taxid): """Given a taxonomy id, find all species under that taxon, and return results for those species""" def get_all_sp(taxid): """Given a taxon t, return all species (leaves) of the phylogeny where t is the root of the tree.""" all_sp = [] Q = Queue.Queue() Q.put(models.Taxonomy.objects.get(pk=taxid)) while not Q.empty(): node = Q.get() children = node.taxonomy_set.all() if children: for c in children: Q.put(c) else: all_sp.append(node) return all_sp # get all species all_species = get_all_sp(taxid) # get all curation-site-instance objects for browsed taxon cur_site_insts = models.Curation_SiteInstance.objects.filter( site_instance__genome__taxonomy__in=all_species) # generate all reports reports = motif_report.make_reports(cur_site_insts) return render_to_response("browse_results.html", { 'title': models.Taxonomy.objects.get(pk=taxid).name, 'description': '', 'all_cur_site_insts': [ pk for report in reports for pk in report.get_all_cur_site_insts_ids() ], 'reports': [report.generate_browse_result_dict() for report in reports], }, context_instance=RequestContext(request))
def search_post(request): """Handler for database search request.""" def raise_validation_error(msg): """Check if all three steps have been submitted.""" messages.add_message(request, messages.ERROR, message) return HttpResponseRedirect(reverse(search)) try: cur_site_insts = search_post_helper(request) # make reports reports = motif_report.make_reports(cur_site_insts) # make ensemble reports ensemble_report = motif_report.make_ensemble_report(cur_site_insts) if not reports: # If no results found, go back to the search page. message = "No search results that match your search criteria." return raise_validation_error(message) return render_to_response("search_results.html", { 'title': "", 'description': """Search results can be seen as individual reports (one report per TF/species) or as ensemble reports (multiple TF/species). """, 'all_cur_site_insts': [ pk for report in reports for pk in report.get_all_cur_site_insts_ids() ], 'reports': [report.generate_browse_result_dict() for report in reports], }, context_instance=RequestContext(request)) except: message = "Please select at least one TF, species and experimental technique to search database." return raise_validation_error(message)