From dd55e58f899cae5dc50df7888d396d8e0bad429a Mon Sep 17 00:00:00 2001 From: Riley Grant Date: Thu, 17 Oct 2024 10:10:12 -0500 Subject: [PATCH] wip(browser): update frontend types --- browser/src/GenePage/GenePage.tsx | 7 +- browser/src/GenePage/GeneTranscriptsTrack.tsx | 27 +++- .../src/GenePage/TissueExpressionTrack.tsx | 147 +++++++++++------ browser/src/gtex.ts | 152 +++++++++--------- 4 files changed, 199 insertions(+), 134 deletions(-) diff --git a/browser/src/GenePage/GenePage.tsx b/browser/src/GenePage/GenePage.tsx index e686aaecc..2b07cfe6e 100644 --- a/browser/src/GenePage/GenePage.tsx +++ b/browser/src/GenePage/GenePage.tsx @@ -2,7 +2,7 @@ import LeftArrow from '@fortawesome/fontawesome-free/svgs/solid/arrow-circle-left.svg' // @ts-expect-error TS(2307) FIXME: Cannot find module '@fortawesome/fontawesome-free/... Remove this comment to see the full error message import RightArrow from '@fortawesome/fontawesome-free/svgs/solid/arrow-circle-right.svg' -import React, { useState, Dispatch, SetStateAction } from 'react' +import React, { useState, Dispatch, SetStateAction, useEffect } from 'react' import styled from 'styled-components' // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module '@gno... Remove this comment to see the full error message @@ -527,7 +527,6 @@ const GenePage = ({ datasetId, gene, geneId }: Props) => { { {hasCodingExons && gene.chrom !== 'M' && gene.pext && ( & { [key: string]: TissueDetail | undefined }>([]) + // + // useEffect(() => { + // const newGtexTissues = GTEX_TISSUES[getTopLevelDataset(datasetId)] + // setGtexTissues(newGtexTissues) + // }, [datasetId]) + // + // + // + const maxMeanExpression = isTissueExpressionAvailable ? max( (gene.transcripts as TranscriptWithTissueExpression[]).map( @@ -160,6 +175,10 @@ const GeneTranscriptsTrack = ({ circleRadiusMeanContribution + 23.75 * circleRadiusMaxMeanContribution ) + console.log('Hellooo!!!') + console.log('Gtex tissues:', gtexTissues) + console.log('Tissue most expressed in', tissueMostExpressedIn) + return ( { const roundedRegions = expressionRegions.map((region: any) => ({ @@ -189,13 +190,16 @@ const IndividualTissueTrack = ({ const isExpressed = expressionRegions.some( (region: any) => region.tissues.find((tissueObject: ExpressedTissue) => tissueObject.tissue === tissue) - .value !== 0 + ?.value !== 0 ) + console.log('ok in individual tissue track') + console.log('tissue:', tissue) + return ( {gtexTissuesForDataset[tissue].fullName}} + renderLeftPanel={() => {gtexTissues[tissue].fullName}} renderRightPanel={({ width }: any) => width > 36 && ( @@ -224,7 +228,7 @@ const IndividualTissueTrack = ({ transcriptWithMaxExpressionInTissue!.transcript_version })` : // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - `Gene is not expressed in ${gtexTissuesForDataset[tissue].fullName}` + `Gene is not expressed in ${gtexTissues[tissue].fullName}` } > @@ -264,7 +268,7 @@ const IndividualTissueTrack = ({ expressionRegions, (r: any) => r.tissues.find((tissueObject: ExpressedTissue) => tissueObject.tissue === tissue) - .value + ?.value || 0 )} scalePosition={scalePosition} width={width} @@ -330,7 +334,8 @@ export type TranscriptWithTissueExpression = Omit + datasetId: DatasetId + // gtexTissues: Partial exons: { start: number stop: number @@ -351,7 +356,8 @@ type TissueExpressionTrackProps = { } const TissueExpressionTrack = ({ - gtexTissues, + // gtexTissues, + datasetId, exons, expressionRegions, flags, @@ -368,6 +374,16 @@ const TissueExpressionTrack = ({ 'alphabetical' ) + // useEffect(() => { + // console.log("i got called!") + // setIsExpanded(false) + // }, [datasetId]) + + // console.log("what the heck state!") + // console.log(datasetId) + const gtexTissues = GTEX_TISSUES[getTopLevelDataset(datasetId)] + // console.log(Object.keys(gtexTissues).length) + type ExpressionByTissueDetails = { maxTranscriptExpressionInTissue: number meanTranscriptExpressionInTissue: number @@ -378,18 +394,26 @@ const TissueExpressionTrack = ({ } type ExpressionByTissue = Record + // console.log(gtexTissues) const expressionByTissue: ExpressionByTissue = Object.keys(gtexTissues).reduce( (acc, tissueId) => { + // console.log(tissueId) + let maxTranscriptExpressionInTissue = 0 let transcriptWithMaxExpressionInTissue = null transcripts.forEach((transcript) => { const expressionInTissue = transcript.gtex_tissue_expression.find( (tissue) => tissue.tissue === tissueId - )!.value + ) + + // const expressionInTissueValue = expressionInTissue ? expressionInTissue.value : 0 + + // console.log(transcript) + // console.log(expressionInTissue) - if (expressionInTissue > maxTranscriptExpressionInTissue) { - maxTranscriptExpressionInTissue = expressionInTissue! + if (expressionInTissue && expressionInTissue.value > maxTranscriptExpressionInTissue) { + maxTranscriptExpressionInTissue = expressionInTissue.value transcriptWithMaxExpressionInTissue = { transcript_id: transcript.transcript_id, transcript_version: transcript.transcript_version, @@ -398,10 +422,12 @@ const TissueExpressionTrack = ({ }) const meanTranscriptExpressionInTissue = mean( - transcripts.map( - (transcript) => - transcript.gtex_tissue_expression.find((tissue) => tissue.tissue === tissueId)!.value - ) + transcripts + .map( + (transcript) => + transcript.gtex_tissue_expression.find((tissue) => tissue.tissue === tissueId)?.value + ) + .filter((value): value is number => value != undefined) ) return { @@ -420,23 +446,39 @@ const TissueExpressionTrack = ({ Object.values(expressionByTissue).map((v) => v.meanTranscriptExpressionInTissue) )! - let tissues - if (sortTissuesBy === 'mean-expression') { - tissues = Object.entries(gtexTissues) - .sort((t1, t2) => { - const t1Expression = expressionByTissue[t1[0]].meanTranscriptExpressionInTissue - const t2Expression = expressionByTissue[t2[0]].meanTranscriptExpressionInTissue - if (t1Expression === t2Expression) { - return t1[1].fullName.localeCompare(t2[1].fullName) - } - return t2Expression - t1Expression - }) - .map((t: any) => t[0]) - } else { - tissues = Object.entries(gtexTissues) - .sort((t1, t2) => t1[1].fullName.localeCompare(t2[1].fullName)) - .map((t) => t[0]) - } + const tissues = + sortTissuesBy === 'mean-expression' + ? Object.entries(gtexTissues) + .sort((t1, t2) => { + const t1Expression = expressionByTissue[t1[0]].meanTranscriptExpressionInTissue + const t2Expression = expressionByTissue[t2[0]].meanTranscriptExpressionInTissue + if (t1Expression === t2Expression) { + return t1[1].fullName.localeCompare(t2[1].fullName) + } + return t2Expression - t1Expression + }) + .map((t: any) => t[0]) + : Object.entries(gtexTissues) + .sort((t1, t2) => t1[1].fullName.localeCompare(t2[1].fullName)) + .map((t) => t[0]) + + // let tissues + // if (sortTissuesBy === 'mean-expression') { + // tissues = Object.entries(gtexTissues) + // .sort((t1, t2) => { + // const t1Expression = expressionByTissue[t1[0]].meanTranscriptExpressionInTissue + // const t2Expression = expressionByTissue[t2[0]].meanTranscriptExpressionInTissue + // if (t1Expression === t2Expression) { + // return t1[1].fullName.localeCompare(t2[1].fullName) + // } + // return t2Expression - t1Expression + // }) + // .map((t: any) => t[0]) + // } else { + // tissues = Object.entries(gtexTissues) + // .sort((t1, t2) => t1[1].fullName.localeCompare(t2[1].fullName)) + // .map((t) => t[0]) + // } const isExpressed = expressionRegions.some((region: any) => region.mean !== 0) @@ -579,25 +621,28 @@ const TissueExpressionTrack = ({ }} {(tissueFilterText ? tissues.filter(tissuePredicate(tissueFilterText)) : tissues).map( - (tissue: any) => ( - - ) + (tissue: any) => { + console.log(tissue) + return ( + + ) + } )}