Skip to content

Commit

Permalink
GenomicInterpretations hook
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rocheleau committed Oct 18, 2023
1 parent 0a8b281 commit 0a1afed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/components/explorer/IndividualVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<div className="variantDescriptions">
Expand Down
42 changes: 42 additions & 0 deletions src/components/explorer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0a1afed

Please sign in to comment.