Skip to content

Commit

Permalink
feat!: update tx segment element with updated cool-seq-tool structure…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
katiestahl committed Aug 12, 2024
1 parent 8c1fc23 commit fa8c93c
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
txAc,
txChrom,
txStartingGenomic,
txEndingGenomic,
txStrand
txEndingGenomic
).then((txSegmentResponse) => {
if (
txSegmentResponse.warnings &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ const GetCoordinates: React.FC = () => {
exonEndOffset
).then((coordsResponse) => handleResponse(coordsResponse));
} else if (inputType == "genomic_coords_gene") {
getExonCoords(chromosome, start, end, strand, gene).then(
(coordsResponse) => handleResponse(coordsResponse)
getExonCoords(chromosome, start, end, gene).then((coordsResponse) =>
handleResponse(coordsResponse)
);
} else if (inputType == "genomic_coords_tx") {
getExonCoords(chromosome, start, end, strand, "", txAc).then(
(coordsResponse) => handleResponse(coordsResponse)
getExonCoords(chromosome, start, end, "", txAc).then((coordsResponse) =>
handleResponse(coordsResponse)
);
}
};
Expand Down Expand Up @@ -250,10 +250,7 @@ const GetCoordinates: React.FC = () => {
const genomicCoordinateInfo = (
<>
<Box display="flex" justifyContent="space-between" width="100%">
<ChromosomeField
fieldValue={chromosome}
errorText={chromosomeText}
/>
<ChromosomeField fieldValue={chromosome} errorText={chromosomeText} />
<Box mt="18px">
<Box className={classes.strand} width="125px">
<StrandSwitch
Expand Down
35 changes: 17 additions & 18 deletions client/src/services/ResponseModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,22 +630,19 @@ export interface ClientStructuralElement {
*/
export interface CoordsUtilsResponse {
warnings?: string[] | null;
coordinates_data: GenomicData | null;
coordinates_data: GenomicTxData | null;
}
/**
* Model containing genomic and transcript exon data.
* Represent aligned genomic/transcript exon data
*/
export interface GenomicData {
export interface GenomicTxData {
gene: string;
chr: string;
start?: number | null;
end?: number | null;
exon_start?: number | null;
exon_start_offset?: number | null;
exon_end?: number | null;
exon_end_offset?: number | null;
transcript: string;
strand: Strand;
tx_pos_range: [unknown, unknown];
alt_pos_range: [unknown, unknown];
alt_aln_method: string;
tx_exon_id: number;
alt_exon_id: number;
}
/**
* Response model for demo fusion object retrieval endpoints.
Expand All @@ -672,12 +669,13 @@ export interface ExonCoordsRequest {
*/
export interface FormattedAssayedFusion {
fusion_type?: AssayedFusion & string;
structure:
structure: (
| TranscriptSegmentElement
| GeneElement
| TemplatedSequenceElement
| LinkerElement
| UnknownGeneElement;
| UnknownGeneElement
)[];
causative_event?: CausativeEvent | null;
assay?: Assay | null;
regulatory_element?: RegulatoryElement | null;
Expand All @@ -690,12 +688,13 @@ export interface FormattedAssayedFusion {
*/
export interface FormattedCategoricalFusion {
fusion_type?: CategoricalFusion & string;
structure:
structure: (
| TranscriptSegmentElement
| GeneElement
| TemplatedSequenceElement
| LinkerElement
| MultiplePossibleGenesElement;
| MultiplePossibleGenesElement
)[];
regulatory_element?: RegulatoryElement | null;
critical_functional_domains?: FunctionalDomain[] | null;
reading_frame_preserved?: boolean | null;
Expand Down Expand Up @@ -776,9 +775,9 @@ export interface Response {
export interface SequenceIDResponse {
warnings?: string[] | null;
sequence: string;
refseq_id: string | null;
ga4gh_id: string | null;
aliases: string[] | null;
refseq_id?: string | null;
ga4gh_id?: string | null;
aliases?: string[] | null;
}
/**
* Response model for service_info endpoint.
Expand Down
6 changes: 1 addition & 5 deletions client/src/services/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@ export const getTxSegmentElementGCT = async (
transcript: string,
chromosome: string,
start: string,
end: string,
strand: string
end: string
): Promise<TxSegmentElementResponse> => {
const params: Array<string> = [
`transcript=${transcript}`,
`chromosome=${chromosome}`,
`strand=${strand === "+" ? "%2B" : "-"}`,
];
if (start !== "") params.push(`start=${start}`);
if (end !== "") params.push(`end=${end}`);
Expand Down Expand Up @@ -251,13 +249,11 @@ export const getExonCoords = async (
chromosome: string,
start: string,
end: string,
strand: string,
gene?: string,
txAc?: string
): Promise<CoordsUtilsResponse> => {
const argsArray = [
`chromosome=${chromosome}`,
`strand=${strand === "+" ? "%2B" : "-"}`,
gene && gene !== "" ? `gene=${gene}` : "",
txAc && txAc !== "" ? `transcript=${txAc}` : "",
start && start !== "" ? `start=${start}` : "",
Expand Down
34 changes: 5 additions & 29 deletions server/src/curfu/routers/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
TemplatedSequenceElementResponse,
TxSegmentElementResponse,
)
from curfu.sequence_services import InvalidInputError, get_strand
from curfu.sequence_services import get_strand

router = APIRouter()

Expand Down Expand Up @@ -93,7 +93,6 @@ async def build_tx_segment_gct(
chromosome: str,
start: int | None = Query(None),
end: int | None = Query(None),
strand: str | None = Query(None),
) -> TxSegmentElementResponse:
"""Construct Transcript Segment element by providing transcript and genomic
coordinates (chromosome, start, end positions).
Expand All @@ -107,23 +106,12 @@ async def build_tx_segment_gct(
:return: Pydantic class with TranscriptSegment element if successful, and
warnings otherwise.
"""
if strand is not None:
try:
strand_validated = get_strand(strand)
except InvalidInputError:
warning = f"Received invalid strand value: {strand}"
logger.warning(warning)
return TxSegmentElementResponse(warnings=[warning], element=None)
else:
strand_validated = strand
tx_segment, warnings = await request.app.state.fusor.transcript_segment_element(
tx_to_genomic_coords=False,
transcript=parse_identifier(transcript),
chromosome=parse_identifier(chromosome),
start=start,
end=end,
strand=strand_validated,
residue_mode="inter-residue",
genomic_start=start,
genomic_end=end,
)
return TxSegmentElementResponse(element=tx_segment, warnings=warnings)

Expand All @@ -141,7 +129,6 @@ async def build_tx_segment_gcg(
chromosome: str,
start: int | None = Query(None),
end: int | None = Query(None),
strand: str | None = Query(None),
) -> TxSegmentElementResponse:
"""Construct Transcript Segment element by providing gene and genomic
coordinates (chromosome, start, end positions).
Expand All @@ -155,23 +142,12 @@ async def build_tx_segment_gcg(
:return: Pydantic class with TranscriptSegment element if successful, and
warnings otherwise.
"""
if strand is not None:
try:
strand_validated = get_strand(strand)
except InvalidInputError:
warning = f"Received invalid strand value: {strand}"
logger.warning(warning)
return TxSegmentElementResponse(warnings=[warning], element=None)
else:
strand_validated = strand
tx_segment, warnings = await request.app.state.fusor.transcript_segment_element(
tx_to_genomic_coords=False,
gene=gene,
chromosome=parse_identifier(chromosome),
strand=strand_validated,
start=start,
end=end,
residue_mode="inter-residue",
genomic_start=start,
genomic_end=end,
)
return TxSegmentElementResponse(element=tx_segment, warnings=warnings)

Expand Down
21 changes: 5 additions & 16 deletions server/src/curfu/routers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
RouteTag,
SequenceIDResponse,
)
from curfu.sequence_services import InvalidInputError, get_strand

router = APIRouter()

Expand Down Expand Up @@ -107,7 +106,7 @@ async def get_genome_coords(
if exon_end is not None and exon_end_offset is None:
exon_end_offset = 0

response = await request.app.state.fusor.cool_seq_tool.ex_g_coords_mapper.transcript_to_genomic_coordinates(
response = await request.app.state.fusor.cool_seq_tool.ex_g_coords_mapper.tx_segment_to_genomic(
transcript=transcript,
gene=gene,
exon_start=exon_start,
Expand All @@ -134,7 +133,6 @@ async def get_exon_coords(
chromosome: str,
start: int | None = None,
end: int | None = None,
strand: str | None = None,
gene: str | None = None,
transcript: str | None = None,
) -> CoordsUtilsResponse:
Expand All @@ -145,7 +143,6 @@ async def get_exon_coords(
:param chromosome: chromosome, either as a number/X/Y or as an accession
:param start: genomic start position
:param end: genomic end position
:param strand: strand of genomic position
:param gene: gene symbol or ID
:param transcript: transcript accession ID
:return: response with exon coordinates if successful, or warnings if failed
Expand All @@ -155,23 +152,15 @@ async def get_exon_coords(
warnings.append("Must provide start and/or end coordinates")
if transcript is None and gene is None:
warnings.append("Must provide gene and/or transcript")
if strand is not None:
try:
strand_validated = get_strand(strand)
except InvalidInputError:
warnings.append(f"Received invalid strand value: {strand}")
else:
strand_validated = strand
if warnings:
for warning in warnings:
logger.warning(warning)
return CoordsUtilsResponse(warnings=warnings, coordinates_data=None)

response = await request.app.state.fusor.cool_seq_tool.ex_g_coords_mapper.genomic_to_transcript_exon_coordinates(
alt_ac=chromosome,
start=start,
end=end,
strand=strand_validated,
response = await request.app.state.fusor.cool_seq_tool.ex_g_coords_mapper.genomic_to_tx_segment(
genomic_ac=chromosome,
genomic_start=start,
genomic_end=end,
transcript=transcript,
gene=gene,
)
Expand Down
12 changes: 6 additions & 6 deletions server/src/curfu/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from enum import Enum
from typing import Literal

from cool_seq_tool.schemas import GenomicData
from cool_seq_tool.schemas import GenomicTxData
from fusor.models import (
Assay,
AssayedFusion,
AssayedFusionElements,
AssayedFusionElement,
CategoricalFusion,
CategoricalFusionElements,
CategoricalFusionElement,
CausativeEvent,
FunctionalDomain,
Fusion,
Expand Down Expand Up @@ -213,7 +213,7 @@ def validate_number(cls, v) -> int:
class CoordsUtilsResponse(Response):
"""Response model for genomic coordinates retrieval"""

coordinates_data: GenomicData | None
coordinates_data: GenomicTxData | None


class SequenceIDResponse(Response):
Expand Down Expand Up @@ -301,7 +301,7 @@ class FormattedAssayedFusion(BaseModel):
"""

fusion_type: FusionType.ASSAYED_FUSION = FusionType.ASSAYED_FUSION
structure: AssayedFusionElements
structure: list[AssayedFusionElement]
causative_event: CausativeEvent | None = None
assay: Assay | None = None
regulatory_element: RegulatoryElement | None = None
Expand All @@ -315,7 +315,7 @@ class FormattedCategoricalFusion(BaseModel):
"""

fusion_type: FusionType.CATEGORICAL_FUSION = FusionType.CATEGORICAL_FUSION
structure: CategoricalFusionElements
structure: list[CategoricalFusionElement]
regulatory_element: RegulatoryElement | None = None
critical_functional_domains: list[FunctionalDomain] | None = None
reading_frame_preserved: bool | None = None
Expand Down
6 changes: 3 additions & 3 deletions server/tests/integration/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ async def test_build_segment_gct(
genomic coordinates and transcript.
"""
await check_response(
"/api/construct/structural_element/tx_segment_gct?transcript=NM_152263.4&chromosome=NC_000001.11&start=154171416&end=154171417&strand=-",
"/api/construct/structural_element/tx_segment_gct?transcript=NM_152263.4&chromosome=NC_000001.11&start=154171416&end=154171417",
{"element": tpm3_tx_t_element},
check_tx_element_response,
)
await check_response(
"/api/construct/structural_element/tx_segment_gct?transcript=refseq%3ANM_152263.4&chromosome=NC_000001.11&start=154171416&end=154171417&strand=-",
"/api/construct/structural_element/tx_segment_gct?transcript=refseq%3ANM_152263.4&chromosome=NC_000001.11&start=154171416&end=154171417",
{"element": tpm3_tx_t_element},
check_tx_element_response,
)
Expand All @@ -178,7 +178,7 @@ async def test_build_segment_gcg(
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&strand=-",
"/api/construct/structural_element/tx_segment_gcg?gene=TPM3&chromosome=NC_000001.11&start=154171416&end=154171417",
{"element": tpm3_tx_g_element},
check_tx_element_response,
)
Expand Down
3 changes: 1 addition & 2 deletions server/tests/integration/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def check_coords_response(response: dict, expected_response: dict):
assert response["coordinates_data"] == expected_response["coordinates_data"]

await check_response(
"/api/utilities/get_exon?chromosome=1&transcript=NM_152263.3&start=154192135&strand=-",
"/api/utilities/get_exon?chromosome=1&transcript=NM_152263.3&start=154192135",
{
"coordinates_data": {
"gene": "TPM3",
Expand All @@ -145,7 +145,6 @@ def check_coords_response(response: dict, expected_response: dict):
"exon_start": 1,
"exon_start_offset": 1,
"transcript": "NM_152263.3",
"strand": -1,
}
},
check_coords_response,
Expand Down

0 comments on commit fa8c93c

Please sign in to comment.