def classification_auto_populate_fields( classification: Classification, genome_build: GenomeBuild, refseq_transcript_accession: str = None, ensembl_transcript_accession: str = None, leave_existing_values: bool = True, annotation_version: str = None, save: bool = True): """ Applies annotation data to the classification """ auto_data = generate_auto_populate_data( variant=classification.variant, genome_build=genome_build, refseq_transcript_accession=refseq_transcript_accession, ensembl_transcript_accession=ensembl_transcript_accession, sample=classification.sample, annotation_version=annotation_version) classification.annotation_version = auto_data.annotation_version classification.patch_value(auto_data.data, user=classification.user, source=SubmissionSource.VARIANT_GRID, leave_existing_values=leave_existing_values, save=save)
def classify_index(request, token_str): token = get_object_or_404(Token, token=token_str) if request.method == 'POST': chosen_category_id = int(request.POST.get('category')) paper_id = request.POST.get('paper') paper = get_object_or_404(Paper, pk=paper_id) category = None sub_category = None if chosen_category_id != -1: category = get_object_or_404(Category, pk=chosen_category_id) classification = Classification(token=token, paper=paper, category=category, sub_category=sub_category) classification.save() classifications_done = Classification.objects.filter(token=token) done = classifications_done.count() paper_query = Paper.objects.exclude(pk__in=classifications_done.values("paper__pk")) left = paper_query.count() paper = None if left > 0: # idx = randint(0, left - 1) paper = paper_query.first() categories = Category.objects.all() return render(request, "classification/index.html", {'token': token, 'paper': paper, 'categories': categories, 'done': done, 'total': left + done})
def create_classification(request): """ Create a new classification with a label in the current language. """ parameters = request.data language = translation.get_language() if not Language.objects.filter(code=language).exists(): raise SuspiciousOperation(_("The language is not supported")) if Classification.objects.filter(name=parameters['name']).exists(): raise SuspiciousOperation(_("A classification already exists with this name")) classification = Classification() classification.name = parameters['name'] classification.set_label(language, parameters['label']) classification.description = parameters['description'] classification.save() response = { 'id': classification.pk, 'name': classification.name, 'can_modify': classification.can_modify, 'can_delete': classification.can_delete, 'label': classification.get_label(), 'description': classification.description, 'num_classification_ranks': 0 } return HttpResponseRest(request, response)
def get_extra_filters_q(user: User, genome_build: GenomeBuild, extra_filters): if extra_filters == BuiltInFilters.CLINVAR: q = Q(clinvar__highest_pathogenicity__gte=4) elif extra_filters == BuiltInFilters.OMIM: q = Q( variantannotation__gene__geneannotation__omim_terms__isnull=False) elif extra_filters in [ BuiltInFilters.CLASSIFIED, BuiltInFilters.CLASSIFIED_PATHOGENIC ]: clinical_significance_list = None if extra_filters == BuiltInFilters.CLASSIFIED_PATHOGENIC: clinical_significance_list = [ ClinicalSignificance.LIKELY_PATHOGENIC, ClinicalSignificance.PATHOGENIC ] q = Classification.get_variant_q(user, genome_build, clinical_significance_list) elif extra_filters == BuiltInFilters.IMPACT_HIGH_OR_MODERATE: q = Q(variantannotation__impact__in=(PathogenicityImpact.HIGH, PathogenicityImpact.MODERATE)) elif extra_filters == BuiltInFilters.COSMIC: q = Q(variantannotation__cosmic_id__isnull=False) else: logging.warning("get_extra_filters_q, unknown filter '%s'", extra_filters) q = Q(pk__isnull=False) # No op return q
def _get_variant_q(self, genome_build: GenomeBuild): q_variant = None if self.uses_classifications: vc_qs = self.get_classification_qs() q_variant = Classification.get_variant_q_from_classification_qs( vc_qs, genome_build) return q_variant
def create_classification_for_sample_and_variant_objects( user: User, sample: Sample, variant: Variant, genome_build: GenomeBuild, refseq_transcript_accession: str = None, ensembl_transcript_accession: str = None, annotation_version: str = None): """ Create internally from existing variant - not used by API which may need to create variants """ user_settings = UserSettings.get_for_user(user) # TODO - if you have > 1 labs then redirect to pick page. lab = user_settings.get_lab() vc_import = ClassificationImport.objects.create(user=user, genome_build=genome_build) kwargs = { "user": user, "lab": lab, "variant": variant, "sample": sample, "classification_import": vc_import, "populate_with_defaults": True } classification = Classification.create(**kwargs) classification_auto_populate_fields( classification, genome_build, refseq_transcript_accession=refseq_transcript_accession, ensembl_transcript_accession=ensembl_transcript_accession, annotation_version=annotation_version) classification.set_variant( variant ) # have to re-do this because we didn't have the transcript the first time around liftover_classification_import(vc_import, ImportSource.WEB) return classification
def _get_gene_value_counts(cls, cohort_gene_counts, gene_values, variant_annotation_version, update_gene_id): # There are way less Classifications, and each has a sample, so handle this per-sample # As it's classified for this sample, we know the builds are the same (hence can use variant not allele) vc_qs = cohort_gene_counts.gene_count_type.get_classification_qs() if update_gene_id: gene = Gene.objects.get(pk=update_gene_id) vc_qs = vc_qs.filter(Classification.get_q_for_gene(gene)) sample_gene_value_counts = defaultdict(lambda: defaultdict(Counter)) cohort = cohort_gene_counts.cohort for sample in cohort.get_samples(): for classification in vc_qs.filter(sample=sample): ensembl_gene_id = classification.get("ensembl_gene_id") gene_id = None if ensembl_gene_id: gene_id, _ = GeneVersion.get_gene_id_and_version( ensembl_gene_id) else: variant_annotation = classification.get_variant_annotation( variant_annotation_version) if variant_annotation: gene_id = variant_annotation.gene_id if gene_id: g_value_counts = sample_gene_value_counts[ sample.pk][gene_id] has_category = False for molecular_consequence in classification.get( "molecular_consequence", []): category = MolecularConsequenceColors.CONSEQUENCE_LOOKUPS.get( molecular_consequence) if category: gvc = gene_values[category] g_value_counts[gvc] += 1 has_category = True if not has_category: ot = gene_values[MolecularConsequenceColors.OTHER] g_value_counts[ot] += 1 return sample_gene_value_counts
def __init__(self, vc: Classification): self.ref_length = vc.update_cached_c_hgvs() self.vc_id = vc.id self.chgvs = vc.get(SpecialEKeys.C_HGVS) vc.save()