def _vectors_to_choice(vectors): "it returns the given vectors but prepared to use as choices in a select" for_vectors = vectors.filter(prefix=UT_SUFFIX, suffix=UT_PREFIX) rev_vectors = vectors.filter(prefix=Seq(UT_PREFIX).reverse_complement(), suffix=Seq(UT_SUFFIX).reverse_complement()) for_vector_choices = features_to_choices(for_vectors, blank_line=False) rev_vector_choices = features_to_choices(rev_vectors, blank_line=False) vector_choices = (('', ''), ('Forward vectors', for_vector_choices), ('Reverse vectors', rev_vector_choices)) return vector_choices
def get_part1_choice(user): _bi_parts = Feature.objects.filter(type__name__in=BIPARTITE_ALLOWED_PARTS) _parts = _bi_parts.filter(prefix=SITE_A, suffix=SITE_C) _parts = filter_feature_by_user_perms(_parts, user) parts_forw = _parts.filter(vector__prefix=SITE_B, vector__suffix=SITE_A) parts_rev = _parts.filter(vector__prefix=Seq(SITE_A).reverse_complement(), vector__suffix=Seq(SITE_B).reverse_complement()) part_forw_choices = features_to_choices(parts_forw, blank_line=False) part_rev_choices = features_to_choices(parts_rev, blank_line=False) part_choices = (('', ''), ('Forward parts', part_forw_choices), ('Reverse parts', part_rev_choices)) return part_choices
def get_multipartite_form(multi_type, user): 'It returns a form for the given multipartite' form_fields = OrderedDict() part_defs = PARTS_TO_ASSEMBLE[multi_type] for parts in part_defs: features = Feature.objects.filter(type__name=parts[0], prefix=parts[1], suffix=parts[2]) features = filter_feature_by_user_perms(features, user) choices = features_to_choices(features) name = parts[0] form_fields[name] = forms.CharField(max_length=100, widget=Select(choices=choices)) # last we need to add the vector to the form vector_choices = get_vector_choices(user) form_fields[VECTOR_TYPE_NAME] = forms.CharField(max_length=100, widget=Select(choices=vector_choices)) form = type('MultiPartiteForm', (forms.BaseForm,), {'base_fields': form_fields}) for field_name in form_fields.keys(): setattr(form, 'clean_{0}'.format(field_name), create_feature_validator(field_name)) return form