From c182f101630f81b4405b4873b90eafc272286866 Mon Sep 17 00:00:00 2001 From: Ayaan Kakkar Date: Sun, 22 Sep 2024 21:11:51 -0700 Subject: [PATCH] Added the gene info functionality similar to api v1 --- src/graphql/models/snp_model.py | 10 +++++++++- src/graphql/schema.py | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/graphql/models/snp_model.py b/src/graphql/models/snp_model.py index e167f99..1283e15 100644 --- a/src/graphql/models/snp_model.py +++ b/src/graphql/models/snp_model.py @@ -21,4 +21,12 @@ class SnpList: @strawberry.type class ScrollSnp: snps: List[Snp] - scroll_id: Optional[str] = None \ No newline at end of file + scroll_id: Optional[str] = None + + +@strawberry.type +class Gene: + contig: str + start: int + end: int + gene_id: str \ No newline at end of file diff --git a/src/graphql/schema.py b/src/graphql/schema.py index 5c98c5c..70b3ecc 100644 --- a/src/graphql/schema.py +++ b/src/graphql/schema.py @@ -1,7 +1,8 @@ from typing import List, Optional import strawberry from strawberry.types import Info -from src.graphql.models.snp_model import ScrollSnp, Snp, SnpAggs +from src.graphql.gene_pos import get_pos_from_gene_id, map_gene, chromosomal_location_dic +from src.graphql.models.snp_model import Gene, ScrollSnp, Snp, SnpAggs from src.graphql.models.annotation_model import FilterArgs, Histogram, PageArgs, QueryType, QueryTypeOption from src.graphql.resolvers.snp_resolver import get_annotations, scroll_annotations_, search_by_chromosome, search_by_gene, search_by_rsID, search_by_rsIDs, search_by_IDs @@ -182,4 +183,13 @@ async def count_SNPs_by_gene_product(self, gene: str, filter_args: Optional[Filt @strawberry.field async def download_SNPs_by_gene_product(self, gene: str, fields: list[str], page_args: Optional[PageArgs] = None) -> str: - return await search_by_gene(fields, gene, QueryType.DOWNLOAD, page_args) \ No newline at end of file + return await search_by_gene(fields, gene, QueryType.DOWNLOAD, page_args) + + @strawberry.field + async def gene_info(self, gene: str) -> Gene: + gene_id = map_gene(gene) + gene_pos = get_pos_from_gene_id(gene_id, chromosomal_location_dic) + if gene_pos: + return Gene(contig=gene_pos[0], start=gene_pos[1], end=gene_pos[2], gene_id=gene_id) + else: + raise KeyError(f'Gene {gene} not found') \ No newline at end of file