def saved_variants(request, tag): tag_type = VariantTagType.objects.get(name=tag, project__isnull=True) saved_variant_models = SavedVariant.objects.filter(varianttag__variant_tag_type=tag_type, family__isnull=False) saved_variants = get_json_for_saved_variants(saved_variant_models, add_tags=True, add_details=True, user=request.user) project_models_by_guid = {variant.project.guid: variant.project for variant in saved_variant_models} families = {variant.family for variant in saved_variant_models} individuals = Individual.objects.filter(family__in=families) genes = _saved_variant_genes(saved_variants) locus_list_guids = _add_locus_lists(project_models_by_guid.values(), saved_variants, genes) projects_json = get_json_for_projects(project_models_by_guid.values(), user=request.user, add_project_category_guids_field=False) functional_tag_types = get_json_for_variant_functional_data_tag_types() for project_json in projects_json: project_json.update({ 'locusListGuids': locus_list_guids, 'variantTagTypes': get_project_variant_tag_types(project_models_by_guid[project_json['projectGuid']]), 'variantFunctionalTagTypes': functional_tag_types, }) families_json = _get_json_for_families(list(families), user=request.user, add_individual_guids_field=True) individuals_json = _get_json_for_individuals(individuals, user=request.user) locus_lists_by_guid = {locus_list['locusListGuid']: locus_list for locus_list in get_json_for_locus_lists(LocusList.objects.filter(guid__in=locus_list_guids), request.user)} return create_json_response({ 'savedVariantsByGuid': {variant['variantGuid']: variant for variant in saved_variants}, 'genesById': genes, 'projectsByGuid': {project['projectGuid']: project for project in projects_json}, 'familiesByGuid': {family['familyGuid']: family for family in families_json}, 'individualsByGuid': {indiv['individualGuid']: indiv for indiv in individuals_json}, 'locusListsByGuid': locus_lists_by_guid, })
def _process_variants(variants, families): genes = _saved_variant_genes(variants) # TODO add locus lists on the client side (?) # TODO handle multiple projects _add_locus_lists(families.first().project, variants, genes) saved_variants_by_guid = _get_saved_variants(variants) return { 'searchedVariants': variants, 'savedVariantsByGuid': saved_variants_by_guid, 'genesById': genes, }
def _process_variants(variants, families): prefetch_related_objects(families, 'project') genes = _saved_variant_genes(variants) # TODO add locus lists on the client side (?) projects = {family.project for family in families} _add_locus_lists(projects, variants, genes) saved_variants_by_guid = _get_saved_variants(variants) return { 'searchedVariants': variants, 'savedVariantsByGuid': saved_variants_by_guid, 'genesById': genes, }
def _process_variants(variants, families, user): prefetch_related_objects(families, 'project') genes = _saved_variant_genes(variants) # TODO add locus lists on the client side (?) projects = {family.project for family in families} _add_locus_lists(projects, variants, genes) response_json, _ = _get_saved_variants( variants, families, include_discovery_tags=user.is_staff) response_json.update({ 'searchedVariants': variants, 'genesById': genes, }) return response_json
def _process_variants(variants, families, user): if not variants: return {'searchedVariants': variants} prefetch_related_objects(families, 'project') genes = _saved_variant_genes(variants) projects = {family.project for family in families} locus_lists_by_guid = _add_locus_lists(projects, genes) response_json, _ = _get_saved_variants(variants, families, include_discovery_tags=user.is_staff) response_json.update({ 'searchedVariants': variants, 'genesById': genes, 'locusListsByGuid': locus_lists_by_guid, }) return response_json
def saved_variants_page(request, tag): gene = request.GET.get('gene') tag_type = VariantTagType.objects.get(name=tag, project__isnull=True) saved_variant_models = SavedVariant.objects.filter( varianttag__variant_tag_type=tag_type) if gene: saved_variant_models = saved_variant_models.filter( saved_variant_json__transcripts__has_key=gene) if saved_variant_models.count() > 10000 and not gene: return create_json_response( {'message': 'Select a gene to filter variants'}, status=400) prefetch_related_objects(saved_variant_models, 'family__project') response_json = get_json_for_saved_variants_with_tags( saved_variant_models, add_details=True, include_missing_variants=True) project_models_by_guid = { variant.family.project.guid: variant.family.project for variant in saved_variant_models } families = {variant.family for variant in saved_variant_models} individuals = Individual.objects.filter(family__in=families) saved_variants = response_json['savedVariantsByGuid'].values() genes = _saved_variant_genes(saved_variants) locus_list_guids = _add_locus_lists(project_models_by_guid.values(), saved_variants, genes) projects_json = get_json_for_projects( project_models_by_guid.values(), user=request.user, add_project_category_guids_field=False) functional_tag_types = get_json_for_variant_functional_data_tag_types() variant_tag_types = VariantTagType.objects.filter( Q(project__in=project_models_by_guid.values()) | Q(project__isnull=True)) prefetch_related_objects(variant_tag_types, 'project') variant_tags_json = _get_json_for_models(variant_tag_types) tag_projects = { vt.guid: vt.project.guid for vt in variant_tag_types if vt.project } for project_json in projects_json: project_guid = project_json['projectGuid'] project_variant_tags = [ vt for vt in variant_tags_json if tag_projects.get( vt['variantTagTypeGuid'], project_guid) == project_guid ] project_json.update({ 'locusListGuids': locus_list_guids, 'variantTagTypes': sorted(project_variant_tags, key=lambda variant_tag_type: variant_tag_type['order']), 'variantFunctionalTagTypes': functional_tag_types, }) families_json = _get_json_for_families(list(families), user=request.user, add_individual_guids_field=True) individuals_json = _get_json_for_individuals(individuals, user=request.user) locus_lists_by_guid = { locus_list['locusListGuid']: locus_list for locus_list in get_json_for_locus_lists( LocusList.objects.filter(guid__in=locus_list_guids), request.user) } response_json.update({ 'genesById': genes, 'projectsByGuid': {project['projectGuid']: project for project in projects_json}, 'familiesByGuid': {family['familyGuid']: family for family in families_json}, 'individualsByGuid': {indiv['individualGuid']: indiv for indiv in individuals_json}, 'locusListsByGuid': locus_lists_by_guid, }) return create_json_response(response_json)