From 0a1afed675fcc5b326a29b78ce2ab4942bf4224f Mon Sep 17 00:00:00 2001 From: v-rocheleau Date: Wed, 18 Oct 2023 09:36:02 -0400 Subject: [PATCH] GenomicInterpretations hook --- src/components/explorer/IndividualVariants.js | 34 ++++++++++----- src/components/explorer/utils.js | 42 +++++++++++++++++++ 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/components/explorer/IndividualVariants.js b/src/components/explorer/IndividualVariants.js index 5e7b26764..704059292 100644 --- a/src/components/explorer/IndividualVariants.js +++ b/src/components/explorer/IndividualVariants.js @@ -7,7 +7,7 @@ import { Button, Descriptions, Empty } from "antd"; import { individualPropTypesShape } from "../../propTypes"; import { setIgvPosition } from "../../modules/explorer/actions"; -import { useDeduplicatedIndividualBiosamples } from "./utils"; +import { useDeduplicatedIndividualBiosamples, useIndividualInterpretations, useIndividualVariantInterpretations } from "./utils"; import "./explorer.css"; // TODO: Only show variants from the relevant dataset, if specified; @@ -62,19 +62,31 @@ SampleVariants.propTypes = { }; const IndividualVariants = ({individual, tracksUrl}) => { - const biosamples = useDeduplicatedIndividualBiosamples(individual); + // const biosamples = useDeduplicatedIndividualBiosamples(individual); + const interpretations = useIndividualVariantInterpretations(individual); const variantsMapped = useMemo( - () => Object.fromEntries(biosamples.map((biosample) => [ - biosample.id, - (biosample.variants ?? []).map((v) => ({ - id: v.hgvsAllele?.id, - hgvs: v.hgvsAllele?.hgvs, - geneContext: v.extra_properties?.gene_context ?? "", - })), - ])), - [biosamples], + () => Object.fromEntries( + interpretations.map(i => i.diagnosis) + .flatMap(d => d.genomic_interpretations) + .filter(gi => gi.hasOwnProperty("variant_interpretation")) + .map(gi => [gi.subject_or_biosample_id, gi]) + ), + [interpretations] ); + console.log(variantsMapped); + + // const variantsMapped = useMemo( + // () => Object.fromEntries(biosamples.map((biosample) => [ + // biosample.id, + // (biosample.variants ?? []).map((v) => ({ + // id: v.hgvsAllele?.id, + // hgvs: v.hgvsAllele?.hgvs, + // geneContext: v.extra_properties?.gene_context ?? "", + // })), + // ])), + // [biosamples], + // ); return (
diff --git a/src/components/explorer/utils.js b/src/components/explorer/utils.js index e0b165a7a..096af3fd6 100644 --- a/src/components/explorer/utils.js +++ b/src/components/explorer/utils.js @@ -14,6 +14,48 @@ export const useDeduplicatedIndividualBiosamples = (individual) => [individual], ); +export const useIndividualInterpretations = (individual, withDiagnosis = false) => + useMemo( + () => Object.values( + Object.fromEntries( + (individual?.phenopackets ?? []) + .flatMap(p => p.interpretations) + .filter(i => withDiagnosis ? i.hasOwnProperty("diagnosis") : true) + .map(i => [i.id, i]), + ), + ), + [individual], + ); + +/** + * Returns the Interpretations that contain the call + * @param {array} interpretations Array of Phenopacket Interpretation + * @param {string} call "gene_descriptor" or "variant_interpretation" + * @returns Interpretations with call + */ +export const useGenomicInterpretations = (interpretations, call) => + useMemo( + () => Object.values( + Object.fromEntries( + interpretations + .filter(interp => interp.hasOwnProperty("diagnosis")) + .filter(interp => interp.diagnosis.hasOwnProperty("genomic_interpretations") + && interp.diagnosis.genomic_interpretations.length) + .filter(interp => interp.diagnosis.genomic_interpretations.some(i => i.hasOwnProperty(call))) + .map(interp => [interp.id, interp]), + ), + ), + ); + +export const useIndividualVariantInterpretations = (individual) => { + const interpretations = useIndividualInterpretations(individual); + return useGenomicInterpretations(interpretations, "variant_interpretation"); +}; + +export const useIndividualGeneInterpretations = (individual) => { + const interpretations = useIndividualInterpretations(individual); + return useGenomicInterpretations(interpretations, "gene_descriptor"); +} export const useDatasetResources = (datasetIDOrDatasetIDs) => { const dispatch = useDispatch();