def pssm_search(request): """Scans the genome with the given motif.""" if request.method == 'POST': form = BindingSiteSearchForm(request.POST) if form.is_valid(): genome = form.cleaned_data['genome'] motif = bioutils.build_motif(form.cleaned_data['sites']) # Find a threshold dist = motif.pssm.distribution(precision=10**4) threshold = dist.threshold_patser() hits = bioutils.pssm_search( motif.pssm, genome.seq, threshold=threshold) matches = [] for pos, strand, score in hits: seq = genome.seq[pos:pos+motif.length] if strand == -1: seq = bioutils.reverse_complement(seq) matches.append({ 'start': pos, 'end': pos + motif.length, 'strand': strand, 'seq': seq, 'score': score}) return render( request, 'pssm_search_results.html', {'matches': matches, 'weblogo': bioutils.weblogo_uri(form.cleaned_data['sites']), 'threshold': threshold}) else: form = BindingSiteSearchForm() return render(request, 'pssm_search.html', {'form': form})
def site_exact_match_context_data(wiz): # Generate the weblogo of the entered sites sites = session_utils.get(wiz.request.session, 'sites') site_type = session_utils.get(wiz.request.session, 'site_type') d = {} if (site_type not in ['non_motif_associated', 'var_motif_associated'] and (len(sites) > 1)): d['weblogo_img'] = bioutils.weblogo_uri([site.seq for site in sites]) return d
def site_entry_get_form(wiz, form): """Construct the form for site entry step.""" c = session_utils.get(wiz.request.session, 'previously_curated_paper') # if paper is previously curated, prepopulate fields if c: # Delete session data, if user change any field and then come back, # Store users last entered data, instead of populated data. session_utils.remove(wiz.request.session, 'previously_curated_paper') # populate motifs for the curator to map sites to one of them. genomes = session_utils.get(wiz.request.session, 'genomes') TF_instances = session_utils.get(wiz.request.session, 'TF_instances') csis = models.Curation_SiteInstance.objects.filter( site_type='motif_associated', site_instance__genome__in=genomes, curation__TF_instances__in=TF_instances) # Add motifs as site_type choices site_type_choices = [] motif_ids = csis.values_list('motif_id', flat=True).distinct() for motif_id in motif_ids: sites = [csi.site_instance for csi in csis.filter(motif_id=motif_id)] weblogo = mark_safe("<img src='%s'" % bioutils.weblogo_uri(lasagna.lasagna(sites))) site_type_choices.append((motif_id, weblogo)) # Add non-motif-associated and variable-motif-associated site_type_choices.append((max(motif_ids)+1 if motif_ids else 0, 'motif-associated (new motif)')) site_type_choices.append(('var_motif_associated', 'variable motif associated')) site_type_choices.append(('non_motif_associated', 'non-motif associated')) form.fields['site_type'].choices = site_type_choices # if not high-throughput mode, delete related fields if not session_utils.get(wiz.request.session, 'high_throughput_curation'): del form.fields['peaks'] del form.fields['assay_conditions'] del form.fields['method_notes'] del form.fields['peak_techniques'] else: # high-throughput mode # Populate peak techniques techniques = session_utils.get(wiz.request.session, 'techniques') choices = [(t.technique_id, t.name) for t in techniques] form.fields['peak_techniques'].choices = choices return form
def site_entry_get_form(wiz, form): """Construct the form for site entry step.""" c = session_utils.get(wiz.request.session, 'previously_curated_paper') # if paper is previously curated, prepopulate fields if c: # Delete session data, if user change any field and then come back, # Store users last entered data, instead of populated data. session_utils.remove(wiz.request.session, 'previously_curated_paper') # populate motifs for the curator to map sites to one of them. genomes = session_utils.get(wiz.request.session, 'genomes') TF_instances = session_utils.get(wiz.request.session, 'TF_instances') csis = models.Curation_SiteInstance.objects.filter( site_type='motif_associated', site_instance__genome__in=genomes, curation__TF_instances__in=TF_instances) # Add motifs as site_type choices site_type_choices = [] motif_ids = csis.values_list('motif_id', flat=True).distinct() for motif_id in motif_ids: sites = [csi.site_instance for csi in csis.filter(motif_id=motif_id)] weblogo = mark_safe("<img src='%s'" % bioutils.weblogo_uri(lasagna.lasagna(sites))) site_type_choices.append((motif_id, weblogo)) # Add non-motif-associated and variable-motif-associated site_type_choices.append((max(motif_ids) + 1 if motif_ids else 0, 'motif-associated (new motif)')) site_type_choices.append( ('var_motif_associated', 'variable motif associated')) site_type_choices.append(('non_motif_associated', 'non-motif associated')) form.fields['site_type'].choices = site_type_choices # if not high-throughput mode, delete related fields if not session_utils.get(wiz.request.session, 'high_throughput_curation'): del form.fields['peaks'] del form.fields['assay_conditions'] del form.fields['method_notes'] del form.fields['peak_techniques'] else: # high-throughput mode # Populate peak techniques techniques = session_utils.get(wiz.request.session, 'techniques') choices = [(t.technique_id, t.name) for t in techniques] form.fields['peak_techniques'].choices = choices return form
def pssm_search(request): """Scans the genome with the given motif.""" if request.method == 'POST': form = BindingSiteSearchForm(request.POST) if form.is_valid(): genome = form.cleaned_data['genome'] motif = bioutils.build_motif(form.cleaned_data['sites']) # Find a threshold dist = motif.pssm.distribution(precision=10**4) threshold = dist.threshold_patser() hits = bioutils.pssm_search(motif.pssm, genome.seq, threshold=threshold) matches = [] for pos, strand, score in hits: seq = genome.seq[pos:pos + motif.length] if strand == -1: seq = bioutils.reverse_complement(seq) matches.append({ 'start': pos, 'end': pos + motif.length, 'strand': strand, 'seq': seq, 'score': score }) return render( request, 'pssm_search_results.html', { 'matches': matches, 'weblogo': bioutils.weblogo_uri( form.cleaned_data['sites']), 'threshold': threshold }) else: form = BindingSiteSearchForm() return render(request, 'pssm_search.html', {'form': form})
def weblogo(self): """Returns the weblogo URI for its sites.""" return bioutils.weblogo_uri(self.aligned_sites)
return redirect(motif_comparison_search_second_motif) else: # Step 2 # Render results first_sites = request.session['motif_comparison_step_1'] second_sites = request.session['motif_comparison_step_2'] first_motif_reports = build_motif_reports(first_sites) second_motif_reports = build_motif_reports(second_sites) first_ensemble_report = build_ensemble_report(first_sites) second_ensemble_report = build_ensemble_report(second_sites) # Align two motifs (using dynamic prgramming) alignment = motif_alignment(first_ensemble_report.aligned_sites, second_ensemble_report.aligned_sites) aligned_weblogos = (bioutils.weblogo_uri(alignment[0]), bioutils.weblogo_uri(alignment[1])) # Clear session data from previous requests request.session['permuted_motifs'] = None request.session.modified = True return render( request, 'compare_motifs_results.html', {'form_title': "Step 3 of 3: Motif comparison results", 'first_motif_reports': first_motif_reports, 'first_ensemble_report': first_ensemble_report, 'second_motif_reports': second_motif_reports, 'second_ensemble_report': second_ensemble_report, 'aligned_weblogos': aligned_weblogos})
return redirect(motif_comparison_search_second_motif) else: # Step 2 # Render results first_sites = request.session['motif_comparison_step_1'] second_sites = request.session['motif_comparison_step_2'] first_motif_reports = build_motif_reports(first_sites) second_motif_reports = build_motif_reports(second_sites) first_ensemble_report = build_ensemble_report(first_sites) second_ensemble_report = build_ensemble_report(second_sites) # Align two motifs (using dynamic prgramming) alignment = motif_alignment(first_ensemble_report.aligned_sites, second_ensemble_report.aligned_sites) aligned_weblogos = (bioutils.weblogo_uri(alignment[0]), bioutils.weblogo_uri(alignment[1])) # Clear session data from previous requests request.session['permuted_motifs'] = None request.session.modified = True return render( request, 'compare_motifs_results.html', { 'form_title': "Step 3 of 3: Motif comparison results", 'first_motif_reports': first_motif_reports, 'first_ensemble_report': first_ensemble_report, 'second_motif_reports': second_motif_reports, 'second_ensemble_report': second_ensemble_report, 'aligned_weblogos': aligned_weblogos })