Exemplo n.º 1
0
 def aligned_sites(self):
     """Aligns all binding sites using LASAGNA."""
     site_instances = [
         meta_site.delegate.site_instance for meta_site in self.meta_sites
         if meta_site.site_type == 'motif_associated'
     ]
     return lasagna.lasagna(site_instances)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def export_PSFM(meta_sites, **kwargs):
    """Exports Position-Specific-Frequency-Matrix"""
    format = kwargs['format']
    rows = export_base(meta_sites)
    aligned = lasagna.lasagna([m.delegate_site_instance for m in meta_sites])
    motif = bioutils.build_motif(aligned)
    consensus = motif.degenerate_consensus

    TF_name= ','.join(set(row['TF_name'] for row in rows))
    sp = ','.join(set('_'.join(row['organism'].split()) for row in rows))
    lines = []
    if format == 'JASPAR':
        lines.append('> CollecTF_%s_%s' % (TF_name, sp))
        lines.append('A [ %s ]' % (' '.join(map(str, motif.counts['A']))))
        lines.append('C [ %s ]' % (' '.join(map(str, motif.counts['C']))))
        lines.append('G [ %s ]' % (' '.join(map(str, motif.counts['G']))))
        lines.append('T [ %s ]' % (' '.join(map(str, motif.counts['T']))))
    elif format == 'TRANSFAC':
        lines.append('ID %s' % TF_name)
        lines.append('BF %s' % sp)
        lines.append('PO\tA\tC\tG\tT')
        lines.extend('%02d\t%d\t%d\t%d\t%d\t%s' % (po+1, motif.counts['A'][po],
                                                   motif.counts['C'][po],
                                                   motif.counts['G'][po],
                                                   motif.counts['T'][po],
                                                   consensus[po])
                     for po in range(motif.length))
        lines.append('XX')
    elif format == 'raw_fasta':
        lines.append('>CollecTF_%s_%s' % (TF_name, sp))
        lines.extend('%d\t%d\t%d\t%d' % (motif.counts['A'][po],
                                         motif.counts['C'][po],
                                         motif.counts['G'][po],
                                         motif.counts['T'][po])
                     for po in range(motif.length))

    return '\n'.join(lines)
Exemplo n.º 5
0
 def aligned_sites(self):
     """Aligns all binding sites using LASAGNA."""
     site_instances = [meta_site.delegate.site_instance
                       for meta_site in self.meta_sites
                       if meta_site.site_type == 'motif_associated']
     return lasagna.lasagna(site_instances)