Beispiel #1
0
def mme_details(request):
    submissions = MatchmakerSubmission.objects.filter(
        deleted_date__isnull=True)

    hpo_terms_by_id, genes_by_id, gene_symbols_to_ids = get_mme_genes_phenotypes_for_submissions(
        submissions)

    submission_json = get_json_for_matchmaker_submissions(
        submissions, additional_model_fields=['label'], all_parent_guids=True)
    submissions_by_guid = {s['submissionGuid']: s for s in submission_json}

    for submission in submissions:
        gene_variants = parse_mme_gene_variants(submission.genomic_features,
                                                gene_symbols_to_ids)
        submissions_by_guid[submission.guid].update({
            'phenotypes':
            parse_mme_features(submission.features, hpo_terms_by_id),
            'geneVariants':
            gene_variants,
            'geneSymbols':
            ','.join({
                genes_by_id.get(gv['geneId'], {}).get('geneSymbol')
                for gv in gene_variants
            })
        })

    return create_json_response({
        'metrics': get_mme_metrics(),
        'submissions': submissions_by_guid.values(),
        'genesById': genes_by_id,
    })
Beispiel #2
0
def _parse_mme_results(submission, saved_results, user, additional_genes=None, response_json=None):
    results = []
    contact_institutions = set()
    prefetch_related_objects(saved_results, 'originating_submission__individual__family__project')
    for result_model in saved_results:
        result = result_model.result_data
        result['matchStatus'] = _get_json_for_model(result_model)
        if result_model.originating_submission:
            originating_family = result_model.originating_submission.individual.family
            if has_project_permissions(originating_family.project, user):
                result['originatingSubmission'] = {
                    'originatingSubmissionGuid': result_model.originating_submission.guid,
                    'familyGuid': originating_family.guid,
                    'projectGuid': originating_family.project.guid,
                }
        results.append(result)
        contact_institutions.add(result['patient']['contact'].get('institution', '').strip().lower())

    additional_hpo_ids = {feature['id'] for feature in (submission.features or []) if feature.get('id')}
    if not additional_genes:
        additional_genes = set()
    additional_genes.update({gene_feature['gene']['id'] for gene_feature in (submission.genomic_features or [])})

    hpo_terms_by_id, genes_by_id, gene_symbols_to_ids = get_mme_genes_phenotypes_for_results(
        results, additional_genes=additional_genes, additional_hpo_ids=additional_hpo_ids)

    parsed_results = [_parse_mme_result(res, hpo_terms_by_id, gene_symbols_to_ids, submission.guid) for res in results]
    parsed_results_gy_guid = {result['matchStatus']['matchmakerResultGuid']: result for result in parsed_results}

    contact_notes = {note.institution: _get_json_for_model(note, user=user)
                     for note in MatchmakerContactNotes.objects.filter(institution__in=contact_institutions)}

    submission_json = get_json_for_matchmaker_submission(
        submission, individual_guid=submission.individual.guid,
        additional_model_fields=['contact_name', 'contact_href', 'submission_id']
    )
    submission_json.update({
        'mmeResultGuids': list(parsed_results_gy_guid.keys()),
        'phenotypes': parse_mme_features(submission.features, hpo_terms_by_id),
        'geneVariants': parse_mme_gene_variants(submission.genomic_features, gene_symbols_to_ids),
    })

    response = {
        'mmeResultsByGuid': parsed_results_gy_guid,
        'mmeContactNotes': contact_notes,
        'mmeSubmissionsByGuid': {submission.guid: submission_json},
        'individualsByGuid': {submission.individual.guid: {'mmeSubmissionGuid': submission.guid}},
        'genesById': genes_by_id,
    }
    if response_json:
        response.update(response_json)
    return create_json_response(response)