Skip to content

Commit

Permalink
merge recent changes + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Aug 15, 2024
1 parent 3b097b5 commit 1ab6269
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from "../../../../../services/ResponseModels";
import React, { useEffect, useState, KeyboardEvent, useContext } from "react";
import {
getTxSegmentElementECT,
getTxSegmentElementGCG,
getTxSegmentElementEC,
getTxSegmentElementGC,
getTxSegmentNomenclature,
} from "../../../../../services/main";
import { GeneAutocomplete } from "../../../../main/shared/GeneAutocomplete/GeneAutocomplete";
Expand All @@ -26,8 +26,8 @@ interface TxSegmentElementInputProps extends StructuralElementInputProps {

export enum InputType {
default = "default",
gcg = "genomic_coords",
ect = "exon_coords_tx",
gc = "genomic_coords",
ec = "exon_coords",
}

const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
Expand Down Expand Up @@ -56,7 +56,6 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
);

const [txChrom, setTxChrom] = useState(element.inputChr || "");
const [txChromText, setTxChromText] = useState("");

const [txStartingGenomic, setTxStartingGenomic] = useState(
element.inputGenomicStart || ""
Expand Down Expand Up @@ -100,12 +99,12 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({

// programming horror
const inputComplete =
(txInputType === InputType.gcg &&
(txInputType === InputType.gc &&
txGene !== "" &&
txChrom !== "" &&
selectedTranscript !== "" &&
(txStartingGenomic !== "" || txEndingGenomic !== "")) ||
(txInputType === InputType.ect &&
(txInputType === InputType.ec &&
txAc !== "" &&
(startingExon !== "" || endingExon !== ""));

Expand Down Expand Up @@ -212,16 +211,18 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
setEndingExonOffsetText("");
};

console.log(pendingResponse);

/**
* Request construction of tx segment element from server and handle response
*/
const buildTranscriptSegmentElement = () => {
setPendingResponse(true);
// fire constructor request
switch (txInputType) {
case InputType.gcg:
case InputType.gc:
clearGenomicCoordWarnings();
getTxSegmentElementGCG(
getTxSegmentElementGC(
txGene,
txChrom,
selectedTranscript,
Expand All @@ -247,8 +248,8 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
}
});
break;
case InputType.ect:
getTxSegmentElementECT(
case InputType.ec:
getTxSegmentElementEC(
txAc,
startingExon as string,
endingExon as string,
Expand Down Expand Up @@ -407,7 +408,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({

const renderTxOptions = () => {
switch (txInputType) {
case InputType.gcg:
case InputType.gc:
return (
<Box>
<Box className="mid-inputs" minWidth="325px">
Expand Down Expand Up @@ -444,7 +445,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
{genomicCoordinateInfo}
</Box>
);
case InputType.ect:
case InputType.ec:
return (
<Box>
{txInputField}
Expand Down Expand Up @@ -583,7 +584,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
*/
const selectInputType = (selection: InputType) => {
if (txInputType !== "default") {
if (selection === "exon_coords_tx") {
if (selection === "exon_coords") {
clearGenomicCoordWarnings();
} else {
clearExonWarnings();
Expand Down Expand Up @@ -624,7 +625,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
Select input data
</MenuItem>
<MenuItem value="genomic_coords">Genomic coordinates</MenuItem>
<MenuItem value="exon_coords_tx">
<MenuItem value="exon_coords">
Exon coordinates, transcript
</MenuItem>
</Select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const GetCoordinates: React.FC = () => {
gene !== "" &&
chromosome !== "" &&
(start !== "" || end !== "")) ||
(inputType === "exon_coords_tx" &&
(inputType === "exon_coords" &&
txAc !== "" &&
(exonStart !== "" || exonEnd !== ""));

Expand Down Expand Up @@ -191,7 +191,7 @@ const GetCoordinates: React.FC = () => {

const fetchResults = () => {
setIsLoading(true);
if (inputType == "exon_coords_tx") {
if (inputType == "exon_coords") {
getGenomicCoords(
gene,
txAc,
Expand Down Expand Up @@ -347,7 +347,7 @@ const GetCoordinates: React.FC = () => {
</Box>
</>
);
case "exon_coords_tx":
case "exon_coords":
return (
<>
<Box>
Expand Down Expand Up @@ -410,7 +410,7 @@ const GetCoordinates: React.FC = () => {
Select input data
</MenuItem>
<MenuItem value="genomic_coords">Genomic coordinates</MenuItem>
<MenuItem value="exon_coords_tx">Exon coordinates</MenuItem>
<MenuItem value="exon_coords">Exon coordinates</MenuItem>
</Select>
</Box>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion client/src/services/ResponseModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export interface ClientTranscriptSegmentElement {
gene: Gene;
elementGenomicStart?: SequenceLocation | null;
elementGenomicEnd?: SequenceLocation | null;
inputType: "genomic_coords_gene" | "genomic_coords_tx" | "exon_coords_tx";
inputType: "genomic_coords_gene" | "genomic_coords_tx" | "exon_coords";
inputTx?: string | null;
inputStrand?: Strand | null;
inputGene?: string | null;
Expand Down
8 changes: 4 additions & 4 deletions client/src/services/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const getTemplatedSequenceElement = async (
return responseJson;
};

export const getTxSegmentElementECT = async (
export const getTxSegmentElementEC = async (
transcript: string,
exonStart: string,
exonEnd: string,
Expand All @@ -153,13 +153,13 @@ export const getTxSegmentElementECT = async (
params.push(`exon_end_offset=${exonEndOffset}`);
}
const url =
"api/construct/structural_element/tx_segment_ect?" + params.join("&");
"api/construct/structural_element/tx_segment_ec?" + params.join("&");
const response = await fetch(url);
const responseJson = await response.json();
return responseJson;
};

export const getTxSegmentElementGCG = async (
export const getTxSegmentElementGC = async (
gene: string,
chromosome: string,
transcript: string,
Expand All @@ -176,7 +176,7 @@ export const getTxSegmentElementGCG = async (
if (start !== "") params.push(`start=${start}`);
if (end !== "") params.push(`end=${end}`);
const url =
"api/construct/structural_element/tx_segment_gcg?" + params.join("&");
"api/construct/structural_element/tx_segment_gc?" + params.join("&");
const response = await fetch(url);
const responseJson = await response.json();
return responseJson;
Expand Down
12 changes: 6 additions & 6 deletions server/src/curfu/routers/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def build_gene_element(request: Request, term: str = Query("")) -> GeneElementRe


@router.get(
"/api/construct/structural_element/tx_segment_ect",
"/api/construct/structural_element/tx_segment_ec",
operation_id="buildTranscriptSegmentElementECT",
response_model=TxSegmentElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
async def build_tx_segment_ect(
async def build_tx_segment_ec(
request: Request,
transcript: str,
exon_start: int | None = Query(None),
Expand Down Expand Up @@ -81,21 +81,21 @@ async def build_tx_segment_ect(


@router.get(
"/api/construct/structural_element/tx_segment_gcg",
operation_id="buildTranscriptSegmentElementGCG",
"/api/construct/structural_element/tx_segment_gc",
operation_id="buildTranscriptSegmentElementGC",
response_model=TxSegmentElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
async def build_tx_segment_gcg(
async def build_tx_segment_gc(
request: Request,
gene: str,
chromosome: str,
transcript: str,
start: int | None = Query(None),
end: int | None = Query(None),
) -> TxSegmentElementResponse:
"""Construct Transcript Segment element by providing gene and genomic
"""Construct Transcript Segment element by providing gene and/or transcript and genomic
coordinates (chromosome, start, end positions).
\f
:param request: the HTTP request context, supplied by FastAPI. Use to access
Expand Down
2 changes: 1 addition & 1 deletion server/src/curfu/routers/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def clientify_structural_element(
if element.type == StructuralElementType.TRANSCRIPT_SEGMENT_ELEMENT:
nm = tx_segment_nomenclature(element)
element_args["nomenclature"] = nm
element_args["inputType"] = "exon_coords_tx"
element_args["inputType"] = "exon_coords"
element_args["inputTx"] = element.transcript.split(":")[1]
element_args["inputExonStart"] = str(element.exonStart)
element_args["inputExonStartOffset"] = str(element.exonStartOffset)
Expand Down
32 changes: 31 additions & 1 deletion server/src/curfu/routers/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from fastapi import APIRouter, Query, Request

from curfu import LookupServiceError
from curfu.schemas import NormalizeGeneResponse, ResponseDict, RouteTag
from curfu.schemas import (
GetGeneTranscriptsResponse,
NormalizeGeneResponse,
ResponseDict,
RouteTag,
)

router = APIRouter()

Expand Down Expand Up @@ -37,3 +42,28 @@ def normalize_gene(request: Request, term: str = Query("")) -> NormalizeGeneResp
response["symbol"] = None
response["cased"] = None
return NormalizeGeneResponse(**response)


@router.get(
"/api/utilities/get_transcripts_for_gene",
operation_id="getTranscriptsFromGene",
response_model=GetGeneTranscriptsResponse,
response_model_exclude_none=True,
)
async def get_transcripts_for_gene(request: Request, gene: str) -> dict:
"""Get all transcripts for gene term.
\f
:param Request request: the HTTP request context, supplied by FastAPI. Use to access
FUSOR and UTA-associated tools.
:param str gene: gene term provided by user
:return: Dict containing transcripts if lookup succeeds, or warnings upon failure
"""
normalized = request.app.state.fusor.gene_normalizer.normalize(gene)
symbol = normalized.gene.label
transcripts = await request.app.state.fusor.cool_seq_tool.uta_db.get_transcripts(
gene=symbol
)
tx_for_gene = list(transcripts.rows_by_key("tx_ac"))
if transcripts.is_empty():
return {"warnings": [f"No matching transcripts: {gene}"], "transcripts": []}
return {"transcripts": tx_for_gene}
26 changes: 0 additions & 26 deletions server/src/curfu/routers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from curfu import logger
from curfu.schemas import (
CoordsUtilsResponse,
GetGeneTranscriptsResponse,
GetTranscriptsResponse,
RouteTag,
SequenceIDResponse,
Expand Down Expand Up @@ -50,31 +49,6 @@ def get_mane_transcripts(request: Request, term: str) -> dict:
return {"transcripts": transcripts}


@router.get(
"/api/utilities/get_transcripts_for_gene",
operation_id="getTranscriptsFromGene",
response_model=GetGeneTranscriptsResponse,
response_model_exclude_none=True,
)
async def get_transcripts_for_gene(request: Request, gene: str) -> dict:
"""Get all transcripts for gene term.
\f
:param Request request: the HTTP request context, supplied by FastAPI. Use to access
FUSOR and UTA-associated tools.
:param str gene: gene term provided by user
:return: Dict containing transcripts if lookup succeeds, or warnings upon failure
"""
normalized = request.app.state.fusor.gene_normalizer.normalize(gene)
symbol = normalized.gene.label
transcripts = await request.app.state.fusor.cool_seq_tool.uta_db.get_transcripts(
gene=symbol
)
tx_for_gene = list(transcripts.rows_by_key("tx_ac"))
if transcripts.is_empty():
return {"warnings": [f"No matching transcripts: {gene}"], "transcripts": []}
return {"transcripts": tx_for_gene}


@router.get(
"/api/utilities/get_genomic",
operation_id="getGenomicCoords",
Expand Down
2 changes: 1 addition & 1 deletion server/src/curfu/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ClientTranscriptSegmentElement(TranscriptSegmentElement, ClientStructuralE
inputType: (
Literal["genomic_coords_gene"]
| Literal["genomic_coords_tx"]
| Literal["exon_coords_tx"]
| Literal["exon_coords"]
)
inputTx: str | None = None
inputStrand: Strand | None = None
Expand Down
12 changes: 6 additions & 6 deletions server/tests/integration/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,28 @@ def check_temp_seq_response(response: dict, expected_response: dict):


@pytest.mark.asyncio()
async def test_build_tx_segment_ect(
async def test_build_tx_segment_ec(
check_response, check_tx_element_response, ntrk1_tx_element_start
):
"""Test correct functioning of transcript segment element construction using exon
coordinates and transcript.
"""
await check_response(
"/api/construct/structural_element/tx_segment_ect?transcript=NM_002529.3&exon_start=2&exon_start_offset=1",
"/api/construct/structural_element/tx_segment_ec?transcript=NM_002529.3&exon_start=2&exon_start_offset=1",
{"element": ntrk1_tx_element_start},
check_tx_element_response,
)

# test require exonStart or exonEnd
await check_response(
"/api/construct/structural_element/tx_segment_ect?transcript=NM_002529.3",
"/api/construct/structural_element/tx_segment_ec?transcript=NM_002529.3",
{"warnings": ["Must provide either `exon_start` or `exon_end`"]},
check_tx_element_response,
)

# test handle invalid transcript
await check_response(
"/api/construct/structural_element/tx_segment_ect?transcript=NM_0012529.3&exon_start=3",
"/api/construct/structural_element/tx_segment_ec?transcript=NM_0012529.3&exon_start=3",
{"warnings": ["Unable to get exons for NM_0012529.3"]},
check_tx_element_response,
)
Expand All @@ -171,14 +171,14 @@ async def test_build_segment_gct(


@pytest.mark.asyncio()
async def test_build_segment_gcg(
async def test_build_segment_gc(
check_response, check_tx_element_response, tpm3_tx_g_element
):
"""Test correct functioning of transcript segment element construction using
genomic coordinates and gene name.
"""
await check_response(
"/api/construct/structural_element/tx_segment_gcg?gene=TPM3&chromosome=NC_000001.11&start=154171416&end=154171417",
"/api/construct/structural_element/tx_segment_gc?gene=TPM3&chromosome=NC_000001.11&start=154171416&end=154171417",
{"element": tpm3_tx_g_element},
check_tx_element_response,
)
Expand Down

0 comments on commit 1ab6269

Please sign in to comment.