Skip to content

Commit

Permalink
wip: updating models
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Jul 30, 2024
1 parent 0f390da commit c20a6f8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const RegulatoryElementInput: React.FC<RegulatoryElementInputProps> = ({
}
const newRegElement: ClientRegulatoryElement = {
...reResponse.regulatoryElement,
display_class: regulatoryClassItems[elementClass][1],
displayClass: regulatoryClassItems[elementClass][1],
nomenclature: nomenclatureResponse.nomenclature,
};
setRegElement(newRegElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ interface TemplatedSequenceElementInputProps
const TemplatedSequenceElementInput: React.FC<
TemplatedSequenceElementInputProps
> = ({ element, index, handleSave, handleDelete, icon }) => {

const [chromosome, setChromosome] = useState<string>(
element.input_chromosome || ""
element.inputChromosome || ""
);
const [strand, setStrand] = useState<string>(element.strand || "+");
const [startPosition, setStartPosition] = useState<string>(
element.input_start || ""
element.inputStart || ""
);
const [endPosition, setEndPosition] = useState<string>(
element.input_end || ""
element.inputEnd || ""
);
const [inputError, setInputError] = useState<string>("");

Expand Down Expand Up @@ -67,7 +66,7 @@ const TemplatedSequenceElementInput: React.FC<
) {
// TODO visible error handling
setInputError("element validation unsuccessful");
setPendingResponse(false)
setPendingResponse(false);
return;
} else if (templatedSequenceResponse.element) {
setInputError("");
Expand All @@ -79,15 +78,15 @@ const TemplatedSequenceElementInput: React.FC<
...templatedSequenceResponse.element,
element_id: element.element_id,
nomenclature: nomenclatureResponse.nomenclature,
input_chromosome: chromosome,
inputChromosome: chromosome,
input_start: startPosition,
input_end: endPosition,
};
handleSave(index, templatedSequenceElement);
}
});
}
setPendingResponse(false)
setPendingResponse(false);
});
};

Expand Down Expand Up @@ -167,7 +166,7 @@ const TemplatedSequenceElementInput: React.FC<
inputElements,
validated,
icon,
pendingResponse
pendingResponse,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
const { fusion } = useContext(FusionContext);

const [txInputType, setTxInputType] = useState<InputType>(
(element.input_type as InputType) || InputType.default
(element.inputType as InputType) || InputType.default
);

// "Text" variables refer to helper or warning text to set under input fields
// TODO: this needs refactored so badly
const [txAc, setTxAc] = useState(element.input_tx || "");
const [txAc, setTxAc] = useState(element.inputTx || "");
const [txAcText, setTxAcText] = useState("");

const [txGene, setTxGene] = useState(element.input_gene || "");
Expand Down Expand Up @@ -248,7 +248,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
CheckGenomicCoordWarning(txSegmentResponse.warnings);
} else {
const inputParams = {
input_type: txInputType,
inputType: txInputType,
input_strand: txStrand,
input_gene: txGene,
input_chr: txChrom,
Expand Down Expand Up @@ -277,8 +277,8 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
CheckGenomicCoordWarning(txSegmentResponse.warnings);
} else {
const inputParams = {
input_type: txInputType,
input_tx: txAc,
inputType: txInputType,
inputTx: txAc,
input_strand: txStrand,
input_chr: txChrom,
input_genomic_start: txStartingGenomic,
Expand Down Expand Up @@ -323,8 +323,8 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
setStartingExonText("");
setEndingExonText("");
const inputParams = {
input_type: txInputType,
input_tx: txAc,
inputType: txInputType,
inputTx: txAc,
};
handleTxElementResponse(txSegmentResponse, inputParams);
}
Expand Down Expand Up @@ -437,10 +437,7 @@ const TxSegmentCompInput: React.FC<TxSegmentElementInputProps> = ({
const genomicCoordinateInfo = (
<>
<Box className="mid-inputs">
<ChromosomeField
fieldValue={txChrom}
errorText={txChromText}
/>
<ChromosomeField fieldValue={txChrom} errorText={txChromText} />
<Box mt="18px" width="125px">
<StrandSwitch setStrand={setTxStrand} selectedStrand={txStrand} />
</Box>
Expand Down
61 changes: 32 additions & 29 deletions client/src/components/Pages/Summary/Main/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { FusionContext } from "../../../../global/contexts/FusionContext";
import React, { useContext, useEffect, useState } from "react";

import {
AssayedFusionElements,
CategoricalFusionElements,
ClientElementUnion,
ElementUnion,
validateFusion,
} from "../../../../services/main";
import {
AssayedFusion,
CategoricalFusion,
FunctionalDomain,
FormattedAssayedFusion,
FormattedCategoricalFusion,
GeneElement,
LinkerElement,
MultiplePossibleGenesElement,
Expand All @@ -33,6 +36,9 @@ export const Summary: React.FC<Props> = ({ setVisibleTab }) => {
const [validatedFusion, setValidatedFusion] = useState<
AssayedFusion | CategoricalFusion | null
>(null);
const [formattedFusion, setFormattedFusion] = useState<
FormattedAssayedFusion | FormattedCategoricalFusion | null
>(null);
const [validationErrors, setValidationErrors] = useState<string[]>([]);
const { fusion } = useContext(FusionContext);

Expand All @@ -54,7 +60,7 @@ export const Summary: React.FC<Props> = ({ setVisibleTab }) => {
case "LinkerSequenceElement":
const linkerElement: LinkerElement = {
type: element.type,
linker_sequence: element.linker_sequence,
linkerSequence: element.linkerSequence,
};
return linkerElement;
case "TemplatedSequenceElement":
Expand All @@ -68,13 +74,13 @@ export const Summary: React.FC<Props> = ({ setVisibleTab }) => {
const txSegmentElement: TranscriptSegmentElement = {
type: element.type,
transcript: element.transcript,
exon_start: element.exon_start,
exon_start_offset: element.exon_start_offset,
exon_end: element.exon_end,
exon_end_offset: element.exon_end_offset,
exonStart: element.exonStart,
exonStartOffset: element.exonStartOffset,
exonEnd: element.exonEnd,
exonEndOffset: element.exonEndOffset,
gene: element.gene,
element_genomic_start: element.element_genomic_start,
element_genomic_end: element.element_genomic_end,
elementGenomicStart: element.elementGenomicStart,
elementGenomicEnd: element.elementGenomicEnd,
};
return txSegmentElement;
case "MultiplePossibleGenesElement":
Expand All @@ -93,7 +99,7 @@ export const Summary: React.FC<Props> = ({ setVisibleTab }) => {
* @param formattedFusion fusion with client-oriented properties dropped
*/
const requestValidatedFusion = (
formattedFusion: AssayedFusion | CategoricalFusion
formattedFusion: FormattedAssayedFusion | FormattedCategoricalFusion
) => {
// make request
validateFusion(formattedFusion).then((response) => {
Expand All @@ -107,52 +113,49 @@ export const Summary: React.FC<Props> = ({ setVisibleTab }) => {
}
} else {
setValidationErrors([]);
console.log(response.fusion);
setValidatedFusion(
response.fusion as CategoricalFusion | AssayedFusion
);
setFormattedFusion(formattedFusion);
}
});
};

/**
* On component render, restructure fusion to drop properties used for client state purposes,
* fix expected casing for fusor fusion constructors,
* transmit to validation endpoint, and update local copy.
*/
useEffect(() => {
const structuralElements: ElementUnion[] = fusion.structure?.map(
const structure: ElementUnion[] = fusion.structure?.map(
(element: ClientElementUnion) => fusorifyStructuralElement(element)
);
let regulatoryElement: RegulatoryElement | null = null;
if (fusion.regulatoryElement) {
regulatoryElement = {
type: fusion.regulatoryElement.type,
associated_gene: fusion.regulatoryElement.associated_gene,
regulatory_class: fusion.regulatoryElement.regulatory_class,
associatedGene: fusion.regulatoryElement.associatedGene,
regulatoryClass: fusion.regulatoryElement.regulatoryClass,
featureId: fusion.regulatoryElement.featureId,
feature_location: fusion.regulatoryElement.feature_location,
featureLocation: fusion.regulatoryElement.featureLocation,
};
}
let formattedFusion: AssayedFusion | CategoricalFusion;
let formattedFusion: FormattedAssayedFusion | FormattedCategoricalFusion;
if (fusion.type === "AssayedFusion") {
formattedFusion = {
...fusion,
structure: structuralElements,
regulatoryElement: regulatoryElement,
structure: structure as AssayedFusionElements[],
causative_event: fusion.causativeEvent,
assay: fusion.assay,
regulatory_element: regulatoryElement,
reading_frame_preserved: fusion.readingFramePreserved,
};
} else {
const criticalDomains: FunctionalDomain[] =
fusion.criticalFunctionalDomains?.map((domain: FunctionalDomain) => ({
_id: domain._id,
label: domain.label,
status: domain.status,
associated_gene: domain.associated_gene,
sequence_location: domain.sequence_location,
}));
formattedFusion = {
...fusion,
structure: structuralElements,
regulatoryElement: regulatoryElement,
criticalFunctionalDomains: criticalDomains,
structure: structure as CategoricalFusionElements[],
regulatory_element: regulatoryElement,
critical_functional_domains: fusion.criticalFunctionalDomains,
reading_frame_preserved: fusion.readingFramePreserved,
};
}
requestValidatedFusion(formattedFusion);
Expand Down
38 changes: 19 additions & 19 deletions client/src/services/ResponseModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/

/**
* Form of evidence supporting identification of the fusion.
*/
export type Evidence = "observed" | "inferred";
/**
* Define possible classes of Regulatory Elements. Options are the possible values
* for /regulatory_class value property in the INSDC controlled vocabulary:
Expand Down Expand Up @@ -71,15 +75,21 @@ export type Strand = 1 | -1;
* assayed fusion.
*/
export type EventType = "rearrangement" | "read-through" | "trans-splicing";
/**
* Form of evidence supporting identification of the fusion.
*/
export type Evidence = "observed" | "inferred";
/**
* Define possible statuses of functional domains.
*/
export type DomainStatus = "lost" | "preserved";

/**
* Information pertaining to the assay used in identifying the fusion.
*/
export interface Assay {
type?: "Assay";
assayName?: string | null;
assayId?: string | null;
methodUri?: string | null;
fusionDetection?: Evidence | null;
}
/**
* Assayed gene fusions from biological specimens are directly detected using
* RNA-based gene fusion assays, or alternatively may be inferred from genomic
Expand Down Expand Up @@ -413,22 +423,12 @@ export interface CausativeEvent {
eventType: EventType;
eventDescription?: string | null;
}
/**
* Information pertaining to the assay used in identifying the fusion.
*/
export interface Assay {
type?: "Assay";
assayName?: string | null;
assayId?: string | null;
methodUri?: string | null;
fusionDetection?: Evidence | null;
}
/**
* Response model for domain ID autocomplete suggestion endpoint.
*/
export interface AssociatedDomainResponse {
warnings?: string[] | null;
geneId: string;
gene_id: string;
suggestions: DomainParams[] | null;
}
/**
Expand Down Expand Up @@ -717,7 +717,7 @@ export interface NomenclatureResponse {
export interface NormalizeGeneResponse {
warnings?: string[] | null;
term: string;
conceptId: string | null;
concept_id: string | null;
symbol: string | null;
cased: string | null;
}
Expand All @@ -726,7 +726,7 @@ export interface NormalizeGeneResponse {
*/
export interface RegulatoryElementResponse {
warnings?: string[] | null;
regulatoryElement: RegulatoryElement;
regulatory_element: RegulatoryElement;
}
/**
* Abstract Response class for defining API response structures.
Expand All @@ -740,8 +740,8 @@ export interface Response {
export interface SequenceIDResponse {
warnings?: string[] | null;
sequence: string;
refseqId: string | null;
ga4ghId: string | null;
refseq_id: string | null;
ga4gh_id: string | null;
aliases: string[] | null;
}
/**
Expand Down
Loading

0 comments on commit c20a6f8

Please sign in to comment.