Skip to content

Commit

Permalink
Merge pull request #45 from USCbiostats/add-gene-info-api
Browse files Browse the repository at this point in the history
Added the gene info functionality similar to api v1
  • Loading branch information
AyaanKakkar authored Oct 16, 2024
2 parents 6866d57 + f0ca3bf commit 4cb9354
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/graphql/models/snp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ class SnpList:
@strawberry.type
class ScrollSnp:
snps: List[Snp]
scroll_id: Optional[str] = None
scroll_id: Optional[str] = None


@strawberry.type
class Gene:
contig: str
start: int
end: int
gene_id: str
14 changes: 12 additions & 2 deletions src/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List, Optional
import strawberry
from strawberry.types import Info
from src.graphql.models.snp_model import ScrollSnp, 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, 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_keyword, search_by_rsID, search_by_rsIDs, search_by_IDs
Expand Down Expand Up @@ -189,6 +190,15 @@ async def download_SNPs_by_gene_product(self, gene: str, fields: list[str],
page_args: Optional[PageArgs] = None, filter_args: Optional[FilterArgs] = None) -> str:
return await search_by_gene(fields, gene, QueryType.DOWNLOAD, None, page_args, filter_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')

@strawberry.field
async def get_SNPs_by_keyword(self, info: Info, keyword: str, query_type_option: QueryTypeOption,
page_args: Optional[PageArgs] = None) -> ScrollSnp:
Expand Down Expand Up @@ -216,4 +226,4 @@ async def count_SNPs_by_keyword(self, keyword: str) -> int:
@strawberry.field
async def download_SNPs_by_keyword(self, keyword: str, fields: list[str],
page_args: Optional[PageArgs] = None) -> str:
return await search_by_keyword(fields, keyword, QueryType.DOWNLOAD, None, page_args)
return await search_by_keyword(fields, keyword, QueryType.DOWNLOAD, None, page_args)

0 comments on commit 4cb9354

Please sign in to comment.