Skip to content

Commit

Permalink
wip(browser): update frontend types
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed Oct 17, 2024
1 parent 5bdd9c4 commit dd55e58
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 134 deletions.
7 changes: 4 additions & 3 deletions browser/src/GenePage/GenePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 5 in browser/src/GenePage/GenePage.tsx

View workflow job for this annotation

GitHub Actions / Checks

'useEffect' is defined but never used. Allowed unused vars must match /^_/u
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
Expand Down Expand Up @@ -527,7 +527,6 @@ const GenePage = ({ datasetId, gene, geneId }: Props) => {
<GeneTranscriptsTrack

Check failure on line 527 in browser/src/GenePage/GenePage.tsx

View workflow job for this annotation

GitHub Actions / Checks

Property 'gtexTissues' is missing in type '{ datasetId: "exac" | "gnomad_r2_1" | "gnomad_r2_1_controls" | "gnomad_r2_1_non_cancer" | "gnomad_r2_1_non_neuro" | "gnomad_r2_1_non_topmed" | "gnomad_r3" | "gnomad_r3_controls_and_biobanks" | ... 10 more ... | "gnomad_r4_non_ukb"; ... 5 more ...; preferredTranscriptDescription: string | ... 1 more ... | null; }' but required in type 'Pick<GeneTranscriptsTrack, "datasetId" | "gene" | "includeUTRs" | "gtexTissues" | "includeNonCodingTranscripts" | "isTissueExpressionAvailable">'.
datasetId={datasetId}
isTissueExpressionAvailable={!!gene.pext}
gtexTissues={GTEX_TISSUES[getTopLevelDataset(datasetId)]}
gene={gene}
includeNonCodingTranscripts={includeNonCodingTranscripts}
includeUTRs={includeUTRs}
Expand All @@ -539,7 +538,9 @@ const GenePage = ({ datasetId, gene, geneId }: Props) => {

{hasCodingExons && gene.chrom !== 'M' && gene.pext && (
<TissueExpressionTrack
gtexTissues={GTEX_TISSUES[getTopLevelDataset(datasetId)]}
datasetId={datasetId}
// gtexTissues={GTEX_TISSUES[getTopLevelDataset(datasetId)]}
// gtexTissues={GTEX_TISSUES[getTopLevelDataset(datasetId)]}
exons={cdsCompositeExons}
expressionRegions={gene.pext.regions}
flags={gene.pext.flags}
Expand Down
27 changes: 23 additions & 4 deletions browser/src/GenePage/GeneTranscriptsTrack.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { max, mean } from 'd3-array'
import React, { useRef, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'

Check failure on line 2 in browser/src/GenePage/GeneTranscriptsTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

'useEffect' is defined but never used. Allowed unused vars must match /^_/u
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
Expand All @@ -8,13 +8,17 @@ import { Track } from '@gnomad/region-viewer'
import TranscriptsTrack from '@gnomad/track-transcripts'
import { Button, Modal, TooltipAnchor } from '@gnomad/ui'

import { AllGtexTissues, TissueDetail } from '../gtex'
import { AllGtexTissues, GTEX_TISSUES, TissueDetail } from '../gtex'
import InfoButton from '../help/InfoButton'
import Link from '../Link'
import sortedTranscripts from './sortedTranscripts'
import TranscriptsTissueExpression from './TranscriptsTissueExpression'
import { Gene } from './GenePage'
import { DatasetId, hasStructuralVariants } from '../../../dataset-metadata/metadata'
import {
DatasetId,
getTopLevelDataset,
hasStructuralVariants,
} from '../../../dataset-metadata/metadata'
import { TranscriptWithTissueExpression } from './TissueExpressionTrack'

const TranscriptsInfoWrapper = styled.div`
Expand Down Expand Up @@ -49,7 +53,6 @@ type GeneTranscriptsTrack = {
const GeneTranscriptsTrack = ({
datasetId,
isTissueExpressionAvailable,
gtexTissues,
gene,
includeNonCodingTranscripts,
includeUTRs,
Expand All @@ -59,6 +62,18 @@ const GeneTranscriptsTrack = ({
const transcriptsTrack = useRef(null)
const [showTissueExpressionModal, setShowTissueExpressionModal] = useState(false)

const gtexTissues = GTEX_TISSUES[getTopLevelDataset(datasetId)]

// const [gtexTissues, setGtexTissues] = useState<Partial<AllGtexTissues> & { [key: string]: TissueDetail | undefined }>([])
//
// useEffect(() => {
// const newGtexTissues = GTEX_TISSUES[getTopLevelDataset(datasetId)]
// setGtexTissues(newGtexTissues)
// }, [datasetId])
//
//
//

const maxMeanExpression = isTissueExpressionAvailable
? max(
(gene.transcripts as TranscriptWithTissueExpression[]).map(
Expand Down Expand Up @@ -160,6 +175,10 @@ const GeneTranscriptsTrack = ({
circleRadiusMeanContribution + 23.75 * circleRadiusMaxMeanContribution
)

console.log('Hellooo!!!')

Check warning on line 178 in browser/src/GenePage/GeneTranscriptsTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement
console.log('Gtex tissues:', gtexTissues)

Check warning on line 179 in browser/src/GenePage/GeneTranscriptsTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement
console.log('Tissue most expressed in', tissueMostExpressedIn)

Check warning on line 180 in browser/src/GenePage/GeneTranscriptsTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement

return (
<svg width={width} height={10}>
<TooltipAnchor
Expand Down
147 changes: 96 additions & 51 deletions browser/src/GenePage/TissueExpressionTrack.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { max, mean } from 'd3-array'
import { scaleLinear } from 'd3-scale'
import React, { useRef, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'

Check failure on line 3 in browser/src/GenePage/TissueExpressionTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

'useEffect' is defined but never used. Allowed unused vars must match /^_/u
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
Expand All @@ -9,13 +9,14 @@ import { Track } from '@gnomad/region-viewer'
import { RegionsPlot } from '@gnomad/track-regions'
import { Badge, Button, Modal, SearchInput, Select, TooltipAnchor } from '@gnomad/ui'

import { AllGtexTissues } from '../gtex'
import { AllGtexTissues, GTEX_TISSUES } from '../gtex'
import InfoButton from '../help/InfoButton'

import { logButtonClick } from '../analytics'

import TranscriptsTissueExpression, { GtexTissueExpression } from './TranscriptsTissueExpression'
import { GeneTranscript } from './GenePage'
import { DatasetId, getTopLevelDataset } from '@gnomad/dataset-metadata/metadata'

const getPlotRegions = (expressionRegions: any, getValueForRegion: any) => {
const roundedRegions = expressionRegions.map((region: any) => ({
Expand Down Expand Up @@ -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')

Check warning on line 196 in browser/src/GenePage/TissueExpressionTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement
console.log('tissue:', tissue)

Check warning on line 197 in browser/src/GenePage/TissueExpressionTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement

return (
<Track
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
renderLeftPanel={() => <TissueName>{gtexTissuesForDataset[tissue].fullName}</TissueName>}
renderLeftPanel={() => <TissueName>{gtexTissues[tissue].fullName}</TissueName>}
renderRightPanel={({ width }: any) =>
width > 36 && (
<svg width={width} height={31}>
Expand Down Expand Up @@ -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}`
}
>
<rect x={12} y={2} width={25} height={27} fill="none" pointerEvents="visible" />
Expand Down Expand Up @@ -264,7 +268,7 @@ const IndividualTissueTrack = ({
expressionRegions,
(r: any) =>
r.tissues.find((tissueObject: ExpressedTissue) => tissueObject.tissue === tissue)
.value
?.value || 0
)}
scalePosition={scalePosition}
width={width}
Expand Down Expand Up @@ -330,7 +334,8 @@ export type TranscriptWithTissueExpression = Omit<GeneTranscript, 'gtex_tissue_e
}

type TissueExpressionTrackProps = {
gtexTissues: Partial<AllGtexTissues>
datasetId: DatasetId
// gtexTissues: Partial<AllGtexTissues>
exons: {
start: number
stop: number
Expand All @@ -351,7 +356,8 @@ type TissueExpressionTrackProps = {
}

const TissueExpressionTrack = ({
gtexTissues,
// gtexTissues,
datasetId,
exons,
expressionRegions,
flags,
Expand All @@ -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
Expand All @@ -378,18 +394,26 @@ const TissueExpressionTrack = ({
}
type ExpressionByTissue = Record<string, ExpressionByTissueDetails>

// 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,
Expand All @@ -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)

Check failure on line 430 in browser/src/GenePage/TissueExpressionTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Expected '!==' and instead saw '!='
)

return {
Expand All @@ -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)

Expand Down Expand Up @@ -579,25 +621,28 @@ const TissueExpressionTrack = ({
}}
</Track>
{(tissueFilterText ? tissues.filter(tissuePredicate(tissueFilterText)) : tissues).map(
(tissue: any) => (
<IndividualTissueTrack
gtexTissues={gtexTissues}
key={tissue}
exons={exons}
expressionRegions={expressionRegions}
maxTranscriptExpressionInTissue={
expressionByTissue[tissue].maxTranscriptExpressionInTissue
}
maxMeanTranscriptExpressionInAnyTissue={maxMeanTranscriptExpressionInAnyTissue}
meanTranscriptExpressionInTissue={
expressionByTissue[tissue].meanTranscriptExpressionInTissue
}
transcriptWithMaxExpressionInTissue={
expressionByTissue[tissue].transcriptWithMaxExpressionInTissue
}
tissue={tissue}
/>
)
(tissue: any) => {
console.log(tissue)

Check warning on line 625 in browser/src/GenePage/TissueExpressionTrack.tsx

View workflow job for this annotation

GitHub Actions / Checks

Unexpected console statement
return (
<IndividualTissueTrack
gtexTissues={gtexTissues}
key={`${tissue}-${datasetId}`}
exons={exons}
expressionRegions={expressionRegions}
maxTranscriptExpressionInTissue={
expressionByTissue[tissue].maxTranscriptExpressionInTissue
}
maxMeanTranscriptExpressionInAnyTissue={maxMeanTranscriptExpressionInAnyTissue}
meanTranscriptExpressionInTissue={
expressionByTissue[tissue].meanTranscriptExpressionInTissue
}
transcriptWithMaxExpressionInTissue={
expressionByTissue[tissue].transcriptWithMaxExpressionInTissue
}
tissue={tissue}
/>
)
}
)}
<span>
<Button
Expand Down
Loading

0 comments on commit dd55e58

Please sign in to comment.