Exemplo n.º 1
0
def _get_gene_and_transcript_stats(genome_build: GenomeBuild,
                                   annotation_consortium):
    genes_and_transcripts = {}
    gene_counts = GeneVersion.objects.filter(
        gene__annotation_consortium=annotation_consortium,
        genome_build=genome_build).count()
    transcripts_qs = TranscriptVersion.objects.filter(
        transcript__annotation_consortium=annotation_consortium,
        genome_build=genome_build)
    transcript_counts = transcripts_qs.count()
    if gene_counts and transcript_counts:
        genes_and_transcripts = {
            "genes": gene_counts,
            "transcripts": transcript_counts
        }
        field_counts = get_field_counts(transcripts_qs, "import_source")
        import_sources = {}
        for import_source in GeneAnnotationImport.objects.filter(
                pk__in=field_counts).order_by("created"):
            num_transcripts = field_counts[import_source.pk]
            name = os.path.basename(import_source.filename)
            import_sources[name] = {
                "transcripts": num_transcripts,
                "created": import_source.created
            }
        genes_and_transcripts["import_sources"] = import_sources

    return genes_and_transcripts
Exemplo n.º 2
0
def view_analysis_issues(request):
    all_nodes = AnalysisNode.objects.all()
    field_counts = get_field_counts(all_nodes, "status")
    summary_data = Counter()
    for status, count in field_counts.items():
        summary = NodeStatus.get_summary_state(status)
        summary_data[summary] += count

    field_counts = {NodeStatus(k).label: v for k, v in field_counts.items()}
    context = {
        "nodes_status_summary": summary_data,
        "field_counts": field_counts
    }
    return render(request, 'analysis/view_analysis_issues.html', context)
Exemplo n.º 3
0
def get_classification_counts(user: User, show_unclassified=True) -> Dict[str, int]:
    qs = get_visible_classifications_qs(user)
    field_counts = get_field_counts(qs, "clinical_significance")

    # Add all entries as empty so colors are in the right order in graph.
    classification_counts = {}
    for cs, label in ClinicalSignificance.LABELS.items():
        if cs or show_unclassified:
            classification_counts[label] = 0

    for clinical_significance, clinical_significance_count in field_counts.items():
        clinical_significance_label = ClinicalSignificance.LABELS[clinical_significance]
        classification_counts[clinical_significance_label] = clinical_significance_count
    return classification_counts
Exemplo n.º 4
0
def tag_counts_filter(context,
                      genome_build: GenomeBuild,
                      click_func=None,
                      show_all_func=None,
                      gene_symbol=None,
                      any_tag_button=True):
    tag_kwargs = {}
    if gene_symbol:
        gene_variant_qs = get_variant_queryset_for_gene_symbol(
            gene_symbol=gene_symbol,
            genome_build=genome_build,
            traverse_aliases=True)
        tag_kwargs["variant_qs"] = gene_variant_qs
    variant_tags_qs = VariantTag.get_for_build(genome_build=genome_build,
                                               **tag_kwargs)
    tag_counts = sorted(get_field_counts(variant_tags_qs, "tag").items())
    return {
        "any_tag_button": any_tag_button,
        "tag_counts": tag_counts,
        "click_func": click_func,
        "show_all_func": show_all_func,
    }
Exemplo n.º 5
0
def annotation(request):
    # Set Variables to None for uninstalled components, the template will show installation instructions
    ensembl_biomart_transcript_genes = None
    diagnostic_gene_list = None

    build_contigs = get_build_contigs()
    genome_build_annotations = {}

    builds_ok = []
    for genome_build in GenomeBuild.builds_with_annotation():
        annotation_details = _get_build_annotation_details(
            build_contigs, genome_build)
        genome_build_annotations[genome_build.name] = annotation_details

        builds_ok.append(annotation_details.get("ok", False))

    gene_symbol_alias_counts = get_field_counts(GeneSymbolAlias.objects.all(),
                                                "source")
    if gene_symbol_alias_counts:
        gene_symbol_alias_counts = {
            GeneSymbolAliasSource(k).label: v
            for k, v in gene_symbol_alias_counts.items()
        }

    all_ontologies_accounted_for = True
    ontology_counts = list()
    for service in [
            OntologyService.MONDO, OntologyService.OMIM, OntologyService.HPO,
            OntologyService.HGNC
    ]:
        # don't report HGNC as it's just there as a stub for other items to relate to
        count = OntologyTerm.objects.filter(ontology_service=service).count()
        ontology_counts.append({"service": service, "count": count})

    ontology_services = [
        OntologyService.MONDO, OntologyService.OMIM, OntologyService.HPO,
        OntologyService.HGNC
    ]
    ontology_relationship_counts = dict()
    for first_index, first_service in enumerate(ontology_services):
        for second_service in ontology_services[first_index:]:
            join_count = OntologyTermRelation.objects.filter(
                source_term__ontology_service=first_service,
                dest_term__ontology_service=second_service).count()
            if first_service != second_service:
                reverse_count = OntologyTermRelation.objects.filter(
                    source_term__ontology_service=second_service,
                    dest_term__ontology_service=first_service).count()
                join_count += reverse_count
            ontology_relationship_counts[
                f"{first_service}{second_service}"] = join_count
            ontology_relationship_counts[
                f"{second_service}{first_service}"] = join_count

    ontology_imports = list()
    for context in [
            "mondo_file", "gencc_file", "hpo_file", "omim_file",
            "biomart_omim_aliases", "phenotype_to_genes"
    ]:
        last_import = OntologyImport.objects.filter(
            context=context).order_by('-created').first()
        if not last_import and context != "omim_file":  # don't complain about omim_file not being imported as not available to environments without license
            all_ontologies_accounted_for = False
        ontology_imports.append({
            "context": context,
            "last_import": last_import
        })

    diagnostic = GeneListCategory.objects.get(name='Diagnostic')
    diagnostic_gene_list_count = diagnostic.genelist_set.all().count()
    if diagnostic_gene_list_count:
        diagnostic_gene_list = f"{diagnostic_gene_list_count} diagnostic gene lists"

    clinvar_citations = ClinVarCitation.objects.count()
    if clinvar_citations:
        num_cached_clinvar_citations = CachedCitation.objects.count()
        clinvar_citations = f"{clinvar_citations} ClinVar citations ({num_cached_clinvar_citations} cached)"

    hpa_version = HumanProteinAtlasAnnotationVersion.objects.order_by(
        "-annotation_date").first()
    hpa_counts = HumanProteinAtlasAnnotation.objects.filter(
        version=hpa_version).count()

    somalier = None
    if somalier_enabled := settings.SOMALIER.get("enabled"):
        somalier = _verify_somalier_config()
Exemplo n.º 6
0
                message = f"{genome_build} - set {num_errored} annotation runs to Error"
            elif f"retry-annotation-runs-{genome_build.name}" in request.POST:
                num_retrying = 0
                for annotation_run in annotation_runs.filter(
                        status=AnnotationStatus.ERROR):
                    annotation_run_retry(annotation_run)
                    num_retrying += 1
                message = f"{genome_build} - retrying {num_retrying} annotation runs."

            if message:
                messages.add_message(request, messages.INFO, message)

    for genome_build in GenomeBuild.builds_with_annotation():
        qs = AnnotationRun.objects.filter(
            annotation_range_lock__version__genome_build=genome_build)
        field_counts = get_field_counts(qs, "status")
        summary_data = Counter()
        for field, count in field_counts.items():
            summary = AnnotationStatus.get_summary_state(field)
            summary_data[summary] += count

        genome_build_summary[genome_build.pk] = summary_data
        genome_build_field_counts[genome_build.pk] = {
            as_display[k]: v
            for k, v in field_counts.items()
        }
    context = {
        "genome_build_summary": genome_build_summary,
        "genome_build_field_counts": genome_build_field_counts,
        "datatable_config": AnnotationRunColumns(request)
    }