示例#1
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:
        # pick any curation_site_instance object for this curation
        try:
            curation_site_instance = models.Curation_SiteInstance.objects.filter(curation=c).all()[:1].get()
            #form.fields['is_motif_associated'].initial = curation_site_instance.is_motif_associated
            form.fields['site_type'].initial = curation_site_instance.site_type
        except:
            pass
        # Delete session data, if user change any field and then come back,
        # Store users last entered data, instead of populated data.
        session_utils.put(wiz.request.session, "previously_curated_paper", None)

    # 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
示例#2
0
def site_annotation_process(wiz, form):
    """In this form, each individual sites (only matched ones) are further
    annotated. For each site, TF-function (activator, repressor, etc.),
    quantitative value (if any) and experimental techniques used to identify
    site are requested from the curator."""
    sites = session_utils.get(wiz.request.session, 'sites')
    techniques = session_utils.get(wiz.request.session, 'techniques')
    has_qdata = session_utils.get(wiz.request.session, 'has_quantitative_data')
    cd = form.cleaned_data
    for site in sites:
        i = site.key

        if not site.is_matched():
            continue

        # Make sure all matched sites are  in the annotation form
        assert '%d_site' % i in cd, "Inconsistent site annotation form"

        # Quantitative value
        if has_qdata:
            q = cd['%d_qval' % i]
            site.set_qval(float(q) if q else None)
        # TF function
        site.set_TF_function(cd['%d_TF_function' % i])
        # TF_type
        site.set_TF_type(cd['%d_TF_type' % i])
        # Experimental techniques
        site.clear_techniques()
        for j, t in enumerate(techniques):
            # Add technique to the site if it is checked.
            if cd['%d_technique_%d' % (i, j)]:
                site.add_technique(t)
    # Save sites again
    session_utils.put(wiz.request.session, 'sites', sites)
示例#3
0
def gene_regulation_get_form(wiz, form):
    """For each site, show nearby genes for regulation input. For each nearby
    gene close to a site, curator manually checks if site regulates the gene or
    not (i.e. if there is any experimental support for regulation)."""
    # If publication is marked as not having expression data, disable the form
    # after building it.
    pid = session_utils.get(wiz.request.session, 'publication')
    publication = models.Publication.objects.get(pk=pid)
    # Get all site matches
    sites = session_utils.get(wiz.request.session, 'sites')
    for site in sites:
        if site.is_matched():
            i = site.key
            choices = [(g.gene_id,
                        "%s (%s): %s" % (g.locus_tag, g.name, g.description))
                       for g in site.get_match().nearby_genes]
            form.fields[i] = forms.MultipleChoiceField(
                label=site.seq,
                choices=choices,
                required=False,
                widget=forms.CheckboxSelectMultiple(),
                help_text=site.get_match().match_diagram)
            if not publication.contains_expression_data:
                form.fields[i].widget.attrs['disabled'] = 'disabled'

    return form
示例#4
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:
        # pick any curation_site_instance object for this curation
        try:
            curation_site_instance = models.Curation_SiteInstance.objects.filter(
                curation=c).all()[:1].get()
            #form.fields['is_motif_associated'].initial = curation_site_instance.is_motif_associated
            form.fields['site_type'].initial = curation_site_instance.site_type
        except:
            pass
        # Delete session data, if user change any field and then come back,
        # Store users last entered data, instead of populated data.
        session_utils.put(wiz.request.session, "previously_curated_paper",
                          None)

    # 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
示例#5
0
def site_annotation_get_form(wiz, form):
    """Annotation step for site instances."""
    sites = session_utils.get(wiz.request.session, 'sites')
    techniques = session_utils.get(wiz.request.session, 'techniques')
    for site in sites:
        if site.is_matched():
            i = site.key
            # create dummy field for the label
            label = site.get_match().pprint()
            form.fields['%d_site' % i] = forms.BooleanField(label=label,
                                                            required=False)
            # create quantitative value field
            if session_utils.get(wiz.request.session, 'has_quantitative_data'):
                form.fields['%d_qval' % i] = forms.FloatField(
                    label='Q-val', required=False, initial=site.qval)
            # create TF type selection field
            form.fields['%d_TF_type' % i] = forms.ChoiceField(
                label='TF type', choices=models.Curation_SiteInstance.TF_TYPE)
            # create TF function selection field
            form.fields['%d_TF_function' % i] = forms.ChoiceField(
                label='TF function',
                choices=models.Curation_SiteInstance.TF_FUNCTION)
            # create techniques fields (one checkbox for each technique)
            for j, t in enumerate(techniques):
                form.fields['%d_technique_%d' % (i, j)] = forms.BooleanField(
                    label="", required=False)

    return form
def site_annotation_process(wiz, form):
    """In this form, each individual sites (only matched ones) are further
    annotated. For each site, TF-function (activator, repressor, etc.),
    quantitative value (if any) and experimental techniques used to identify
    site are requested from the curator."""
    sites = session_utils.get(wiz.request.session, 'sites')
    techniques = session_utils.get(wiz.request.session, 'techniques')
    has_qdata = session_utils.get(wiz.request.session, 'has_quantitative_data')
    cd = form.cleaned_data
    for site in sites:
        i = site.key

        if not site.is_matched():
            continue

        # Make sure all matched sites are  in the annotation form
        assert '%d_site'%i in cd, "Inconsistent site annotation form"

        # Quantitative value
        if has_qdata:
            q = cd['%d_qval'%i]
            site.set_qval(float(q) if q else None)
        # TF function
        site.set_TF_function(cd['%d_TF_function'%i])
        # TF_type
        site.set_TF_type(cd['%d_TF_type' %i])
        # Experimental techniques
        site.clear_techniques()
        for j,t in enumerate(techniques):
            # Add technique to the site if it is checked.
            if cd['%d_technique_%d' % (i,j)]:
                site.add_technique(t)
    # Save sites again
    session_utils.put(wiz.request.session, 'sites', sites)
示例#7
0
def site_annotation_get_form(wiz, form):
    """Annotation step for site instances."""
    sites = session_utils.get(wiz.request.session, 'sites')
    techniques = session_utils.get(wiz.request.session, 'techniques')
    for site in sites:
        if site.is_matched():
            i = site.key
            # create dummy field for the label
            form.fields['%d_site' % i] = forms.BooleanField(label=site.get_match().pprint(), required=False)
            # create quantitative value field
            if session_utils.get(wiz.request.session, 'has_quantitative_data'):
                form.fields['%d_qval' % i] = forms.FloatField(label='Q-val',
                                                              required=False,
                                                              initial=site.qval)
            # create TF type selection field
            form.fields['%d_TF_type' % i] = forms.ChoiceField(label='TF type',
                                                              choices=models.Curation_SiteInstance.TF_TYPE)
            # create TF function selection field
            form.fields['%d_TF_function' % i] = forms.ChoiceField(label='TF function',
                                                                  choices=models.Curation_SiteInstance.TF_FUNCTION)
            # create techniques fields (one checkbox for each technique)
            for j,t in enumerate(techniques):
                form.fields['%d_technique_%d' % (i,j)] = forms.BooleanField(label="", required=False)
            
    return 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 in ['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_annotation_context_data(wiz):
    sites = session_utils.get(wiz.request.session, "sites")
    techniques = session_utils.get(wiz.request.session, "techniques")
    has_qdat = session_utils.get(wiz.request.session, 'has_quantitative_data')
    return {"sites": [site for site in sites if site.is_matched()],
            "techniques": techniques,
            "has_quantitative_data": has_qdat,
            }
示例#10
0
def site_annotation_context_data(wiz):
    sites = session_utils.get(wiz.request.session, "sites")
    techniques = session_utils.get(wiz.request.session, "techniques")
    has_qdat = session_utils.get(wiz.request.session, 'has_quantitative_data')
    return {
        "sites": [site for site in sites if site.is_matched()],
        "techniques": techniques,
        "has_quantitative_data": has_qdat,
    }
示例#11
0
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 in ['motif_associated', 'var_motif_associated'
                     ] and len(sites) > 1:
        d['weblogo_img'] = bioutils.weblogo_uri([site.seq for site in sites])
    return d
示例#12
0
def create_site_instances(wiz, curation, site_type):
    """Save Curation_SiteInstance objects."""
    # Get sites from the session data.
    sites = session_utils.get(wiz.request.session, 'sites')
    matched_sites = [site for site in sites if site.is_matched()]
    non_matched_sites = [site for site in sites if not site.is_matched()]
    # Create matched Curation_SiteInstances
    create_matched_site_instances(wiz, curation, matched_sites, site_type)
    # Create non-matched sites
    create_non_matched_site_instances(wiz, curation, non_matched_sites, site_type)
    # If there is any peak data, save them as non-motif-associated
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        create_peak_site_instances(wiz, curation, peaks)
示例#13
0
def create_site_instances(wiz, curation, site_type):
    """Save Curation_SiteInstance objects."""
    # Get sites from the session data.
    sites = session_utils.get(wiz.request.session, 'sites')
    matched_sites = [site for site in sites if site.is_matched()]
    non_matched_sites = [site for site in sites if not site.is_matched()]
    # Create matched Curation_SiteInstances
    create_matched_site_instances(wiz, curation, matched_sites, site_type)
    # Create non-matched sites
    create_non_matched_site_instances(wiz, curation, non_matched_sites,
                                      site_type)
    # If there is any peak data, save them as non-motif-associated
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        create_peak_site_instances(wiz, curation, peaks)
def genome_process(wiz, form):
    """Post-process genome and TF selection step."""
    genome_accession = form.cleaned_data['genome_accession']
    # in form validation genome is searched in db, and if not found,
    # it is inserted into db. So, at this point, it is guaranteed that
    # genome with id <genome_accession> should be in db.
    genomes = [models.Genome.objects.get(genome_accession=genome_accession)]
    # Extra genome accession numbers (if any)
    for i in xrange(1, settings.NUMBER_OF_GENOME_ACCESSION_FIELDS):
        g = form.cleaned_data.get('genome_accession_%d' % i, None)
        if g: genomes.append(models.Genome.objects.get(genome_accession=g))

    # store genome in session data
    session_utils.put(wiz.request.session, 'genomes', genomes)

    # store site species in session data
    session_utils.put(wiz.request.session, 'site_species', form.cleaned_data['site_species'])
    session_utils.put(wiz.request.session, 'TF_species', form.cleaned_data['TF_species'])

    # Set manuscript-related fields (contains_experimental_data and
    # contains_promoter_data). Actually, these fields are defined during adding
    # publication process, but the user is given a chance to edit these fields
    # during the curation process.
    pubid = session_utils.get(wiz.request.session, 'publication')
    p = models.Publication.objects.get(publication_id=pubid)
    p.contains_promoter_data = form.cleaned_data["contains_promoter_data"]
    p.contains_expression_data = form.cleaned_data["contains_expression_data"]
    p.save()
示例#15
0
def create_curation(wiz, genome_dict, techniques_dict, curation_review_dict):
    """Create curation object and save it to the database."""
    # Find the curator
    curator = models.Curator.objects.get(user=wiz.request.user)
    # Get publication information
    publication = publication_done(wiz)
    # Create curation
    curation = models.Curation(
        publication=publication,
        TF_species=genome_dict['TF_species'],
        site_species=genome_dict['site_species'],
        TF=genome_dict['TF'],
        experimental_process=techniques_dict['experimental_process'],
        forms_complex=techniques_dict['forms_complex'],
        complex_notes=techniques_dict['complex_notes'],
        requires_revision=curation_review_dict['requires_revision'],
        notes=curation_review_dict['notes'],
        confidence=curation_review_dict['confidence'],
        NCBI_submission_ready=curation_review_dict['NCBI_submission_ready'],
        curator=curator)
    curation.save()

    # If the curation has an associated quantitative data format, add it
    qformat = session_utils.get(wiz.request.session,
                                'quantitative_data_format')
    curation.quantitative_data_format = qformat
    curation.save()

    # Add TF instances
    for TF_instance in genome_dict['TF_instances']:
        curation.TF_instances.add(TF_instance)
    curation.save()

    return curation
示例#16
0
def inexact_match_form_condition(wizard):
    """Check if inexact match form is necessary. If not (i.e. all sites have
    been matched exactly, hide this step.)"""
    sites = session_utils.get(wizard.request.session, 'sites')
    if sites and all(site.is_matched() and site.get_match().is_exact() for site in sites):
        return False
    return True
示例#17
0
    def render(self, form=None, **kwargs):
        """
        This method gets called after the GET or POST request has been handled.

        The only reason to override this method is to check "no data" button in
        publication selection form step. If the curator selects a publication
        and checks the button "This paper contains no data.", the proper action
        is to terminate curation process as ther is no data to be curated. The
        problem is to process that information and redirect to the home
        page. This is achieved by overloading render method. Before this
        function is called, publication object is modified as having no
        data. Afterwards, this function is called and it redirects to the
        homepage with the message about the action that was performed.
        """
        
        form = form or self.get_form()
        context = self.get_context_data(form=form, **kwargs)

        if (session_utils.has(self.request.session, "paper_contains_no_data") and
            session_utils.get(self.request.session, "paper_contains_no_data")):
            msg = "The publication was marked as having no data."
            messages.info(self.request, msg)
            # clear session data
            session_utils.clear(self.request.session)
            return HttpResponseRedirect(reverse(base.views.home))
        
        return self.render_to_response(context)
示例#18
0
def genome_process(wiz, form):
    """Post-process genome and TF selection step."""
    genome_accession = form.cleaned_data['genome_accession']
    # in form validation genome is searched in db, and if not found,
    # it is inserted into db. So, at this point, it is guaranteed that
    # genome with id <genome_accession> should be in db.
    genomes = [models.Genome.objects.get(genome_accession=genome_accession)]
    # Extra genome accession numbers (if any)
    for i in xrange(1, settings.NUMBER_OF_GENOME_ACCESSION_FIELDS):
        g = form.cleaned_data.get('genome_accession_%d' % i, None)
        if g: genomes.append(models.Genome.objects.get(genome_accession=g))

    # store genome in session data
    session_utils.put(wiz.request.session, 'genomes', genomes)

    # store site species in session data
    session_utils.put(wiz.request.session, 'site_species',
                      form.cleaned_data['site_species'])
    session_utils.put(wiz.request.session, 'TF_species',
                      form.cleaned_data['TF_species'])

    # Set manuscript-related fields (contains_experimental_data and
    # contains_promoter_data). Actually, these fields are defined during adding
    # publication process, but the user is given a chance to edit these fields
    # during the curation process.
    pubid = session_utils.get(wiz.request.session, 'publication')
    p = models.Publication.objects.get(publication_id=pubid)
    p.contains_promoter_data = form.cleaned_data["contains_promoter_data"]
    p.contains_expression_data = form.cleaned_data["contains_expression_data"]
    p.save()
示例#19
0
def master_done(wiz, form_list, **kwargs):
    """Done function which calls step-specific done functions and put everything
    together."""
    # Check if it is an edit_curation wizard
    form_list = edit_curation_check(wiz, form_list)
    # Get data across forms
    
    genome_dict = genome_done(wiz, form_list) # Genome-step data
    techniques_dict = techniques_done(wiz, form_list) # Techniques-step data
    site_entry_dict = site_entry_done(wiz, form_list)    # Site-report-step data
    curation_review_dict = curation_review_done(wiz, form_list) # Curation-review-step data
    
    # Create curation object
    curation = create_curation(wiz, genome_dict, techniques_dict, curation_review_dict)
    # Add external db (if any)
    add_external_db(techniques_dict, curation)
    # If it is high-throughput submission add ChIP-info notes
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        add_high_throughput_notes(site_entry_dict, curation)
    # Create matched and non-matched site instances and their related regulation objects
    create_site_instances(wiz, curation, site_entry_dict['site_type'])
    # Mark the paper as complete if so
    paper_complete(wiz, curation_review_dict)
    # clear session
    session_utils.clear(wiz.request.session)
    # Return success message
    messages.success(wiz.request, "Curation was successfully submitted.")
    return HttpResponseRedirect(reverse(browse.view_curation.view_curation, kwargs={'cid': curation.pk}))
示例#20
0
def create_curation(wiz, genome_dict, techniques_dict, curation_review_dict):
    """Create curation object and save it to the database."""
    # Find the curator
    curator = models.Curator.objects.get(user=wiz.request.user)
    # Get publication information
    publication = publication_done(wiz)
    # Create curation
    curation = models.Curation(publication=          publication,
                               TF_species=           genome_dict['TF_species'],
                               site_species=         genome_dict['site_species'],
                               TF=                   genome_dict['TF'],
                               experimental_process= techniques_dict['experimental_process'],
                               forms_complex=        techniques_dict['forms_complex'],
                               complex_notes=        techniques_dict['complex_notes'],
                               requires_revision=    curation_review_dict['requires_revision'],
                               notes=                curation_review_dict['notes'],
                               confidence=           curation_review_dict['confidence'],
                               NCBI_submission_ready=curation_review_dict['NCBI_submission_ready'],
                               curator=              curator)
    curation.save()

    # If the curation has an associated quantitative data format, add it
    qformat = session_utils.get(wiz.request.session, 'quantitative_data_format')
    curation.quantitative_data_format = qformat
    curation.save()
    
    # Add TF instances
    for TF_instance in genome_dict['TF_instances']:
        curation.TF_instances.add(TF_instance)
    curation.save()
    
    return curation
示例#21
0
    def render(self, form=None, **kwargs):
        """
        This method gets called after the GET or POST request has been handled.

        The only reason to override this method is to check "no data" button in
        publication selection form step. If the curator selects a publication
        and checks the button "This paper contains no data.", the proper action
        is to terminate curation process as ther is no data to be curated. The
        problem is to process that information and redirect to the home
        page. This is achieved by overloading render method. Before this
        function is called, publication object is modified as having no
        data. Afterwards, this function is called and it redirects to the
        homepage with the message about the action that was performed.
        """

        form = form or self.get_form()
        context = self.get_context_data(form=form, **kwargs)

        if (session_utils.has(self.request.session, "paper_contains_no_data")
                and session_utils.get(self.request.session,
                                      "paper_contains_no_data")):
            msg = "The publication was marked as having no data."
            messages.info(self.request, msg)
            # clear session data
            session_utils.clear(self.request.session)
            return HttpResponseRedirect(reverse(base.views.home))

        return self.render_to_response(context)
示例#22
0
def master_done(wiz, form_list, **kwargs):
    """Done function which calls step-specific done functions and put everything
    together."""
    # Check if it is an edit_curation wizard
    form_list = edit_curation_check(wiz, form_list)
    # Get data across forms

    genome_dict = genome_done(wiz, form_list)  # Genome-step data
    techniques_dict = techniques_done(wiz, form_list)  # Techniques-step data
    site_entry_dict = site_entry_done(wiz, form_list)  # Site-report-step data
    curation_review_dict = curation_review_done(
        wiz, form_list)  # Curation-review-step data

    # Create curation object
    curation = create_curation(wiz, genome_dict, techniques_dict,
                               curation_review_dict)
    # Add external db (if any)
    add_external_db(techniques_dict, curation)
    # If it is high-throughput submission add ChIP-info notes
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        add_high_throughput_notes(site_entry_dict, curation)
    # Create matched and non-matched site instances and their related regulation objects
    create_site_instances(wiz, curation, site_entry_dict['site_type'])
    # Mark the paper as complete if so
    paper_complete(wiz, curation_review_dict)
    # clear session
    session_utils.clear(wiz.request.session)
    # Return success message
    messages.success(wiz.request, "Curation was successfully submitted.")
    return HttpResponseRedirect(
        reverse(browse.view_curation.view_curation,
                kwargs={'cid': curation.pk}))
示例#23
0
def techniques_get_form(wiz, form):
    """Construct the form for experiemental techniques step."""
    c = session_utils.get(wiz.request.session, 'previously_curated_paper')
    # if selected paper is previously curated, prepopulate experimental techniques
    if c:
        # get all techniques used in this curation
        cur_site_insts = models.Curation_SiteInstance.objects.filter(
            curation=c)
        techniques = list(
            set(t.technique_id for csi in cur_site_insts
                for t in csi.experimental_techniques.all()))
        form.fields['techniques'].initial = techniques

        form.fields['experimental_process'].initial = c.experimental_process
        try:
            external_dbs = models.Curation_ExternalDatabase.objects.filter(
                curation=c)
            for i, external_db in enumerate(external_dbs):
                form.fields[
                    'external_db_type_%d' %
                    i].initial = external_db.external_database.ext_database_id
                form.fields['external_db_accession_%d' %
                            i].initial = external_db.accession_number
        except models.Curation_ExternalDatabase.DoesNotExist:
            pass
        form.fields['forms_complex'].initial = c.forms_complex
        form.fields['complex_notes'].initial = c.complex_notes
    return form
示例#24
0
def genome_get_form(wiz, form):
    """Construct the form for genome and TF selection step."""
    c = session_utils.get(wiz.request.session, "previously_curated_paper")
    # If selected publication is the one most recently curated, the related
    # curation should be in object c. Otherwise, c = None.  If so, populate
    # "Genome and TF information" form fields from the previously submitted
    # curation to make things easier for curator.
    if c:
        form.initial["TF"] = c.TF
        if c.site_instances.all():
            genomes = list(
                set(site.genome.genome_accession
                    for site in c.site_instances.all()))
            form.initial["genome_accession"] = c.site_instances.all(
            )[0].genome.genome_accession
            for i, g in zip(
                    xrange(1, settings.NUMBER_OF_GENOME_ACCESSION_FIELDS),
                    genomes[1:]):
                form.initial['genome_accession_%d' % i] = g

        # Enter TF accession numbers
        form.initial["TF_accession"] = c.TF_instances.all(
        )[0].protein_accession
        for i, TF_instance in zip(
                xrange(1, settings.NUMBER_OF_TF_ACCESSION_FIELDS),
                c.TF_instances.all()[1:]):
            form.initial["TF_accession_%d" % i] = TF_instance.protein_accession

        form.initial["TF_species"] = c.TF_species
        form.initial["site_species"] = c.site_species

        msg = """
        <h4>Warning!</h4> It seems that the paper you selected is previously
        curated. For convenience, fields in this form are automatically filled based on
        the previous curation of the paper. They may differ in this curation, so it is
        best to check that they are correct before proceeding to the next step."""
        messages.warning(wiz.request, mark_safe(msg))

    # In addition populate two fields on whether the manuscript contains
    # experimental data and promoter information
    pid = session_utils.get(wiz.request.session, 'publication')
    pub = models.Publication.objects.get(publication_id=pid)
    form.fields["contains_promoter_data"].initial = pub.contains_promoter_data
    form.fields[
        "contains_expression_data"].initial = pub.contains_expression_data

    return form
示例#25
0
def inexact_match_form_condition(wizard):
    """Check if inexact match form is necessary. If not (i.e. all sites have
    been matched exactly, hide this step.)"""
    sites = session_utils.get(wizard.request.session, 'sites')
    if sites and all(site.is_matched() and site.get_match().is_exact()
                     for site in sites):
        return False
    return True
示例#26
0
def site_soft_match_context_data(wiz):
    d = {}
    # If no soft match, put something to the context data, so that client-side
    # knows that there is nothing in this page and skip it accordingly.
    sites = session_utils.get(wiz.request.session, 'sites')
    if not any(site.is_matched() and not site.get_match().is_exact()
               for site in sites):
        d['no_soft_match'] = True
    return d
def site_soft_match_context_data(wiz):
    d = {}
    # If no soft match, put something to the context data, so that client-side
    # knows that there is nothing in this page and skip it accordingly.
    sites = session_utils.get(wiz.request.session, 'sites')
    if not any(site.is_matched() and not site.get_match().is_exact()
               for site in sites):
        d['no_soft_match'] = True
    return d
def site_soft_match_process(wiz, form):
    """In this form, soft-search results are processed, user matched all of
    sites to any appropriate sequence found in the genome. Some sites might be
    unmatched if there is no any good candidate in search results."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site_id, match_id in form.cleaned_data.items():
        site = [site for site in sites if site.key==site_id][0]
        if match_id != "None": # means this site is matched
            site.set_soft_match(match_id)

    # If high-throughput submission, try to match quantitative values in peak data to sites
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        for site in sites:
            site.match_peak_data(peaks)
            
    # save the list of sites
    session_utils.put(wiz.request.session, "sites", sites)
示例#29
0
def site_entry_done(wiz, form_list):
    form = head([f for f in form_list if type(f) == SiteEntryForm])
    d = dict(site_type=form.cleaned_data['site_type'], )
    # If the curation is high-throughput, capture assay conditions and method notes
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        d['method_notes'] = form.cleaned_data['method_notes']
        d['assay_conditions'] = form.cleaned_data['assay_conditions']
        d['peak_techniques'] = form.cleaned_data['peak_techniques']

    return d
示例#30
0
def site_soft_match_process(wiz, form):
    """In this form, soft-search results are processed, user matched all of
    sites to any appropriate sequence found in the genome. Some sites might be
    unmatched if there is no any good candidate in search results."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site_id, match_id in form.cleaned_data.items():
        site = [site for site in sites if site.key == site_id][0]
        if match_id != "None":  # means this site is matched
            site.set_soft_match(match_id)

    # If high-throughput submission, try to match quantitative values in peak
    # data to sites
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        for site in sites:
            site.match_peak_data(peaks)

    # save the list of sites
    session_utils.put(wiz.request.session, "sites", sites)
示例#31
0
def site_entry_process(wiz, form):
    """Post process site entry step"""
    genomes = session_utils.get(wiz.request.session, "genomes")
    sites = site_entry.parse_input(form.cleaned_data["sites"].strip())

    # find exact matches
    for site in sites:
        site.search_exact_match(genomes)

    # If any site has quantitative data, mark the curation
    has_qdata = any(site.qval for site in sites)

    # If high-throughput get peak data to save them as non-motif-associated data
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = site_entry.parse_input(form.cleaned_data['peaks'].strip())
        techniques = models.ExperimentalTechnique.objects.filter(
            pk__in=form.cleaned_data['peak_techniques'])
        for peak in peaks:
            peak.search_exact_match(genomes)
            # if there is any match, select the first one by default
            if peak.get_exact_matches():
                peak.set_exact_match(0)
            # for each peak add the technique
            peak.clear_techniques()
            for t in techniques:
                peak.add_technique(t)

        if any(peak.qval for peak in peaks):
            has_qdata = True

        session_utils.put(wiz.request.session, 'peaks', peaks)

    # save the list of sites
    session_utils.put(wiz.request.session, 'sites', sites)
    # save the type of lists
    session_utils.put(wiz.request.session, 'site_type',
                      form.cleaned_data['site_type'])
    # save whether curation has quantitative data
    session_utils.put(wiz.request.session, 'has_quantitative_data', has_qdata)
    # If any quantitative data format save it
    qval = form.cleaned_data.get('quantitative_data_format', None)
    session_utils.put(wiz.request.session, 'quantitative_data_format', qval)
def site_entry_process(wiz, form):
    """Post process site entry step"""
    genomes = session_utils.get(wiz.request.session, "genomes")
    sites = site_entry.parse_input(form.cleaned_data["sites"].strip())

    # find exact matches
    for site in sites:
        site.search_exact_match(genomes)

    # If any site has quantitative data, mark the curation
    has_qdata = any(site.qval for site in sites)

    # If high-throughput get peak data to save them as non-motif-associated data
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = site_entry.parse_input(form.cleaned_data['peaks'].strip())
        techniques = models.ExperimentalTechnique.objects.filter(pk__in=form.cleaned_data['peak_techniques'])
        for peak in peaks:
            peak.search_exact_match(genomes)
            # if there is any match, select the first one by default
            if peak.get_exact_matches():
                peak.set_exact_match(0)
            # for each peak add the technique
            peak.clear_techniques()
            for t in techniques:
                peak.add_technique(t)

        if any(peak.qval for peak in peaks):
            has_qdata = True

        session_utils.put(wiz.request.session, 'peaks', peaks)


    # save the list of sites
    session_utils.put(wiz.request.session, 'sites', sites)
    # save the type of lists
    session_utils.put(wiz.request.session, 'site_type', form.cleaned_data['site_type'])
    # save whether curation has quantitative data
    session_utils.put(wiz.request.session, 'has_quantitative_data', has_qdata)
    # If any quantitative data format save it
    qval = form.cleaned_data.get('quantitative_data_format', None)
    session_utils.put(wiz.request.session, 'quantitative_data_format', qval)
示例#33
0
def site_entry_done(wiz, form_list):
    form = head([f for f in form_list if type(f) == SiteEntryForm])
    d = dict(
        site_type = form.cleaned_data['site_type'],
    )
    # If the curation is high-throughput, capture assay conditions and method notes
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        d['method_notes'] = form.cleaned_data['method_notes']
        d['assay_conditions'] = form.cleaned_data['assay_conditions']
        d['peak_techniques'] = form.cleaned_data['peak_techniques']

    return d
示例#34
0
def site_soft_match_get_form(wiz, form):
    """For sites that are not matched in the previous step (exact match step),
    show soft-search results."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site in sites:
        # Render all site that are not exactly matched in the previous step
        if not (site.is_matched() and site.get_match().is_exact()):
            label = site.seq
            choices = site.populate_match_choices(True, 'inexact_only')
            form.fields[site.key] = forms.ChoiceField(label=label, choices=choices,
                                                      widget=forms.RadioSelect())
            form.fields[site.key].initial = str(choices[0][0])
    return form
示例#35
0
def site_soft_match_get_form(wiz, form):
    """For sites that are not matched in the previous step (exact match step),
    show soft-search results."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site in sites:
        # Render all site that are not exactly matched in the previous step
        if not (site.is_matched() and site.get_match().is_exact()):
            label = site.seq
            choices = site.populate_match_choices(True, 'inexact_only')
            form.fields[site.key] = forms.ChoiceField(
                label=label, choices=choices, widget=forms.RadioSelect())
            form.fields[site.key].initial = str(choices[0][0])
    return form
def site_exact_match_process(wiz, form):
    """Post process for site exact match step. Identify the sites that are
    matched by one of their possible matches and for the rest, perform a soft
    search which allows some substitutions when searching the sequence in the
    genome"""
    genomes = session_utils.get(wiz.request.session, "genomes")
    sites = session_utils.get(wiz.request.session, "sites")
    for site_id, match_id in form.cleaned_data.items():
        site = [site for site in sites if site.key==site_id][0]
        if match_id != "None": # means this site is matched
            site.set_exact_match(match_id)
        else: # not matched, perform soft search
            site.search_soft_match(genomes)

    # If high-throughput submission, try to match quantitative values in peak data to sites
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        for site in sites:
            site.match_peak_data(peaks)
            
    # save the list of sites
    session_utils.put(wiz.request.session, "sites", sites)
示例#37
0
def genome_get_form(wiz, form):
    """Construct the form for genome and TF selection step."""
    c = session_utils.get(wiz.request.session, "previously_curated_paper")
    # If selected publication is the one most recently curated, the related curation
    # should be in object c. Otherwise, c = None.  If so, populate "Genome and TF
    # information" form fields from the previously submitted curation to make things
    # easier for curator.
    if c:
        form.initial["TF"] = c.TF
        if c.site_instances.all():
            genomes = list(set(site.genome.genome_accession for site in c.site_instances.all()))
            form.initial["genome_accession"] = c.site_instances.all()[0].genome.genome_accession
            for i, g in zip(xrange(1, settings.NUMBER_OF_GENOME_ACCESSION_FIELDS), genomes[1:]):
                form.initial['genome_accession_%d' % i] = g

        # Enter TF accession numbers
        form.initial["TF_accession"] = c.TF_instances.all()[0].protein_accession
        for i, TF_instance in zip(xrange(1, settings.NUMBER_OF_TF_ACCESSION_FIELDS), c.TF_instances.all()[1:]):
            form.initial["TF_accession_%d" % i] = TF_instance.protein_accession
        
        form.initial["TF_species"] = c.TF_species
        form.initial["site_species"] = c.site_species

        msg = """
        <h4>Warning!</h4> It seems that the paper you selected is previously
        curated. For convenience, fields in this form are automatically filled based on
        the previous curation of the paper. They may differ in this curation, so it is
        best to check that they are correct before proceeding to the next step."""
        messages.warning(wiz.request, mark_safe(msg))
    
    # In addition populate two fields on whether the manuscript contains
    # experimental data and promoter information
    pid = session_utils.get(wiz.request.session, 'publication')
    pub = models.Publication.objects.get(publication_id=pid)
    form.fields["contains_promoter_data"].initial = pub.contains_promoter_data
    form.fields["contains_expression_data"].initial = pub.contains_expression_data

    return form
示例#38
0
def gene_regulation_get_form(wiz, form):
    """For each site, show nearby genes for regulation input. For each nearby
    gene close to a site, curator manually checks if site regulates the gene or
    not (i.e. if there is any experimental support for regulation)."""
    # If publication is marked as not having expression data, disable the form
    # after building it.
    pid = session_utils.get(wiz.request.session, 'publication')
    publication = models.Publication.objects.get(pk=pid)
    # Get all site matches
    sites = session_utils.get(wiz.request.session, 'sites')
    for site in sites:
        if site.is_matched():
            i = site.key
            choices = [(g.gene_id, "%s (%s): %s" % (g.locus_tag, g.name, g.description))
                       for g in site.get_match().nearby_genes]
            form.fields[i] = forms.MultipleChoiceField(label=site.seq, choices=choices,
                                                       required=False,
                                                       widget=forms.CheckboxSelectMultiple(),
                                                       help_text = site.get_match().match_diagram)
            if not publication.contains_expression_data:
                form.fields[i].widget.attrs['disabled'] = 'disabled'
                
    return form
示例#39
0
def site_exact_match_get_form(wiz, form):
    """Show the list of sites and their exact matches in this form.  Each
    reported site and its exact match results are represented as a field. The
    form is generated dynamically as the number of exact matches is not
    fixed."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site in sites:
        label = site.seq
        choices = site.populate_match_choices(True, 'exact_only')
        form.fields[site.key] = forms.ChoiceField(label=label, choices=choices,
                                                  widget=forms.RadioSelect())
        form.fields[site.key].initial = str(choices[0][0])
            
    return form
示例#40
0
def site_exact_match_process(wiz, form):
    """Post process for site exact match step. Identify the sites that are
    matched by one of their possible matches and for the rest, perform a soft
    search which allows some substitutions when searching the sequence in the
    genome"""
    genomes = session_utils.get(wiz.request.session, "genomes")
    sites = session_utils.get(wiz.request.session, "sites")
    for site_id, match_id in form.cleaned_data.items():
        site = [site for site in sites if site.key == site_id][0]
        if match_id != "None":  # means this site is matched
            site.set_exact_match(match_id)
        else:  # not matched, perform soft search
            site.search_soft_match(genomes)

    # If high-throughput submission, try to match quantitative values in peak
    # data to sites
    if session_utils.get(wiz.request.session, 'high_throughput_curation'):
        peaks = session_utils.get(wiz.request.session, 'peaks')
        for site in sites:
            site.match_peak_data(peaks)

    # save the list of sites
    session_utils.put(wiz.request.session, "sites", sites)
示例#41
0
def site_exact_match_get_form(wiz, form):
    """Show the list of sites and their exact matches in this form.  Each
    reported site and its exact match results are represented as a field. The
    form is generated dynamically as the number of exact matches is not
    fixed."""
    sites = session_utils.get(wiz.request.session, "sites")
    for site in sites:
        label = site.seq
        choices = site.populate_match_choices(True, 'exact_only')
        form.fields[site.key] = forms.ChoiceField(label=label,
                                                  choices=choices,
                                                  widget=forms.RadioSelect())
        form.fields[site.key].initial = str(choices[0][0])

    return form
def gene_regulation_process(wiz, form):
    """Prior to this form all matches sites are processed to identify nearby
    genes. In this step, nearby genes are displayed and asked to the curator to
    select genes that have experimental evidence of regulation in the curated
    paper."""
    cd = form.cleaned_data
    sites = session_utils.get(wiz.request.session, 'sites')
    for site in sites:
        i = site.key
        if not site.is_matched():
            continue

        # Make sure this site is in annotation form
        assert i in cd, "Inconsistent gene regulation form."
        match = site.get_match()
        match.set_regulated_genes(models.Gene.objects.filter(pk__in=cd[i]))
示例#43
0
def gene_regulation_process(wiz, form):
    """Prior to this form all matches sites are processed to identify nearby
    genes. In this step, nearby genes are displayed and asked to the curator to
    select genes that have experimental evidence of regulation in the curated
    paper."""
    cd = form.cleaned_data
    sites = session_utils.get(wiz.request.session, 'sites')
    for site in sites:
        i = site.key
        if not site.is_matched():
            continue

        # Make sure this site is in annotation form
        assert i in cd, "Inconsistent gene regulation form."
        match = site.get_match()
        match.set_regulated_genes(models.Gene.objects.filter(pk__in=cd[i]))
示例#44
0
    def done(self, request, cleaned_data):
        """Add object to the database and return the appropriate message to the user."""
        msg = "The paper was successfully submitted to be curated later."
        p = session_utils.get(request.session, "publication")
        if "assignment" in request.POST: # if assigned to the curator
            curator,_ = Curator.objects.get_or_create(user=request.user)
            p.assigned_to = curator

        if "contains_no_data" in request.POST: # if the paper has no TFBS data
            note = " \nPaper has no TF-binding site data."
            p.submission_notes += note
            p.curation_complete = True
            msg = """The paper was marked as complete, since it does not have data."""

        p.save()  # insert into database
        messages.success(request, msg)
        return HttpResponseRedirect(reverse(base.views.home))
示例#45
0
def techniques_get_form(wiz, form):
    """Construct the form for experiemental techniques step."""
    c = session_utils.get(wiz.request.session, 'previously_curated_paper')
    # if selected paper is previously curated, prepopulate experimental techniques
    if c:
        # get all techniques used in this curation
        cur_site_insts = models.Curation_SiteInstance.objects.filter(curation=c)
        techniques = list(set(t.technique_id for csi in cur_site_insts
                              for t in csi.experimental_techniques.all()))
        form.fields['techniques'].initial = techniques
        
        form.fields['experimental_process'].initial = c.experimental_process
        try:
            external_dbs = models.Curation_ExternalDatabase.objects.filter(curation=c)
            for i,external_db in enumerate(external_dbs):
                form.fields['external_db_type_%d'%i].initial = external_db.external_database.ext_database_id
                form.fields['external_db_accession_%d'%i].initial = external_db.accession_number
        except models.Curation_ExternalDatabase.DoesNotExist:
            pass
        form.fields['forms_complex'].initial = c.forms_complex
        form.fields['complex_notes'].initial = c.complex_notes
    return form
示例#46
0
def publication_done(wiz):
    """The first step is fairly simple. All the curator does in this step is to
    select the paper to be curated."""
    pid = session_utils.get(wiz.request.session, 'publication')
    publication = models.Publication.objects.get(pk=pid)
    return publication
示例#47
0
def publication_done(wiz):
    """The first step is fairly simple. All the curator does in this step is to
    select the paper to be curated."""
    pid = session_utils.get(wiz.request.session, 'publication')
    publication = models.Publication.objects.get(pk=pid)
    return publication