Skip to content

Commit dd7aeff

Browse files
fixup: fixed order for keys
1 parent 0d03e64 commit dd7aeff

8 files changed

+75
-59
lines changed

browser/src/ShortTandemRepeatPage/ShortTandemRepeatAdjacentRepeatSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { Modal, Select } from '@gnomad/ui'
55
import ControlSection from '../VariantPage/ControlSection'
66

77
import ShortTandemRepeatPopulationOptions from './ShortTandemRepeatPopulationOptions'
8-
import { ShortTandemRepeatAdjacentRepeat, ScaleType, Sex, ColorBy } from './ShortTandemRepeatPage'
8+
import { ShortTandemRepeatAdjacentRepeat } from './ShortTandemRepeatPage'
9+
import { ScaleType, Sex, ColorBy } from './ShortTandemRepeatAlleleSizeDistributionPlot'
910
import ShortTandemRepeatAlleleSizeDistributionPlot from './ShortTandemRepeatAlleleSizeDistributionPlot'
1011
import ShortTandemRepeatGenotypeDistributionPlot from './ShortTandemRepeatGenotypeDistributionPlot'
1112
import ShortTandemRepeatGenotypeDistributionBinDetails from './ShortTandemRepeatGenotypeDistributionBinDetails'

browser/src/ShortTandemRepeatPage/ShortTandemRepeatAlleleSizeDistributionPlot.tsx

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ import { AnyD3Scale } from '@visx/scale'
99
import { LegendOrdinal } from '@visx/legend'
1010

1111
import { TooltipAnchor } from '@gnomad/ui'
12-
import {
13-
AlleleSizeDistributionItem,
14-
ColorBy,
15-
ColorByValue,
16-
GenotypeQuality,
17-
QScoreBin,
18-
ScaleType,
19-
} from './ShortTandemRepeatPage'
2012
import { GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
13+
import { PopulationId } from '@gnomad/dataset-metadata/gnomadPopulations'
2114

2215
// The 100% width/height container is necessary the component
2316
// to size to fit its container vs staying at its initial size.
@@ -35,6 +28,46 @@ const BarWithHoverEffect = styled(Bar)`
3528
}
3629
`
3730

31+
export type ScaleType = 'linear' | 'linear-truncated' | 'log'
32+
33+
export const genotypeQualityKeys = [
34+
'low',
35+
'medium-low',
36+
'medium',
37+
'medium-high',
38+
'high',
39+
'not-reviewed',
40+
] as const
41+
42+
export type GenotypeQuality = (typeof genotypeQualityKeys)[number]
43+
44+
export const qScoreKeys = [
45+
'0.0',
46+
'0.1',
47+
'0.2',
48+
'0.3',
49+
'0.4',
50+
'0.5',
51+
'0.6',
52+
'0.7',
53+
'0.8',
54+
'0.9',
55+
'1',
56+
] as const
57+
58+
export type QScoreBin = (typeof qScoreKeys)[number]
59+
export type ColorByValue = GenotypeQuality | QScoreBin | Sex | PopulationId | ''
60+
61+
export type AlleleSizeDistributionItem = {
62+
repunit_count: number
63+
frequency: number
64+
colorByValue: ColorByValue
65+
}
66+
67+
export type Sex = 'XX' | 'XY'
68+
69+
export type ColorBy = 'quality_description' | 'q_score' | 'population' | 'sex'
70+
3871
const defaultColor = '#73ab3d'
3972
const colorMap: Record<ColorBy | '', Record<string, string>> = {
4073
'': {
@@ -59,8 +92,7 @@ const colorMap: Record<ColorBy | '', Record<string, string>> = {
5992
'0.7': '#99ff66',
6093
'0.8': '#66ff99',
6194
'0.9': '#33ffcc',
62-
'1.0': '#00ff00',
63-
'': defaultColor,
95+
'1': '#00ff00',
6496
},
6597
sex: {
6698
XX: '#F7C3CC',
@@ -100,8 +132,7 @@ const qScoreLabels: Record<QScoreBin, string> = {
100132
'0.7': '0.6 < q ≤ 0.7',
101133
'0.8': '0.7 < q ≤ 0.8',
102134
'0.9': '0.8 < q ≤ 0.9',
103-
'1.0': '0.9 < q ≤ 1.0',
104-
'': 'Not reviewed',
135+
'1': '0.9 < q ≤ 1',
105136
}
106137

107138
const fixedLegendLabels: Partial<Record<ColorBy, Record<string, string>>> = {
@@ -152,13 +183,20 @@ type Bin = Partial<Record<ColorByValue, number>> & {
152183
fullFrequency: number
153184
}
154185

186+
const legendKeys: Record<ColorBy, string[]> = {
187+
quality_description: [...genotypeQualityKeys],
188+
q_score: [...qScoreKeys],
189+
sex: ['XX', 'XY'],
190+
population: ['nfe', 'afr', 'fin', 'amr', 'ami', 'asj', 'eas', 'mid', 'oth', 'sas'],
191+
}
192+
155193
const LegendFromColorBy = ({ colorBy }: { colorBy: ColorBy | '' }) => {
156194
if (colorBy === '') {
157195
return null
158196
}
159197

160-
const keys = Object.keys(colorMap[colorBy])
161-
const labels = legendLabels(colorBy, keys)
198+
const keys = legendKeys[colorBy]
199+
const labels = legendLabels(colorBy, [...keys])
162200
const colors = keys.map((key) => colorMap[colorBy][key])
163201
const scale = scaleOrdinal().domain(labels).range(colors)
164202
return <LegendOrdinal scale={scale} direction="row" />

browser/src/ShortTandemRepeatPage/ShortTandemRepeatColorBySelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Dispatch, SetStateAction } from 'react'
22
import styled from 'styled-components'
33

44
import { Select } from '@gnomad/ui'
5-
import { ColorBy, ScaleType } from './ShortTandemRepeatPage'
5+
import { ColorBy, ScaleType } from './ShortTandemRepeatAlleleSizeDistributionPlot'
66

77
const Label = styled.label`
88
padding-right: 1em;

browser/src/ShortTandemRepeatPage/ShortTandemRepeatGenotypeDistributionBinDetails.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { List, ListItem } from '@gnomad/ui'
55
import {
66
ShortTandemRepeat,
77
ShortTandemRepeatAdjacentRepeat,
8-
Sex,
98
GenotypeDistributionItem,
109
} from './ShortTandemRepeatPage'
10+
1111
import { getSelectedGenotypeDistribution } from './shortTandemRepeatHelpers'
1212

13+
import { Sex } from './ShortTandemRepeatAlleleSizeDistributionPlot'
14+
1315
type Props = {
1416
shortTandemRepeatOrAdjacentRepeat: ShortTandemRepeat | ShortTandemRepeatAdjacentRepeat
1517
selectedPopulation: string | ''

browser/src/ShortTandemRepeatPage/ShortTandemRepeatPage.tsx

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import ShortTandemRepeatAssociatedDiseasesTable from './ShortTandemRepeatAssocia
1414
import ShortTandemRepeatAttributes from './ShortTandemRepeatAttributes'
1515
import ShortTandemRepeatPopulationOptions from './ShortTandemRepeatPopulationOptions'
1616
import ShortTandemRepeatColorBySelect from './ShortTandemRepeatColorBySelect'
17-
import ShortTandemRepeatAlleleSizeDistributionPlot from './ShortTandemRepeatAlleleSizeDistributionPlot'
17+
import ShortTandemRepeatAlleleSizeDistributionPlot, {
18+
ColorBy,
19+
GenotypeQuality,
20+
QScoreBin,
21+
Sex,
22+
ScaleType,
23+
AlleleSizeDistributionItem,
24+
} from './ShortTandemRepeatAlleleSizeDistributionPlot'
1825
import ShortTandemRepeatGenotypeDistributionPlot, {
1926
Bin as GenotypeBin,
2027
} from './ShortTandemRepeatGenotypeDistributionPlot'
@@ -38,38 +45,6 @@ type ShortTandemRepeatReferenceRegion = {
3845
stop: number
3946
}
4047

41-
export type GenotypeQuality =
42-
| 'low'
43-
| 'medium-low'
44-
| 'medium'
45-
| 'medium-high'
46-
| 'high'
47-
| 'not-reviewed'
48-
export type QScoreBin =
49-
| '0.0'
50-
| '0.1'
51-
| '0.2'
52-
| '0.3'
53-
| '0.4'
54-
| '0.5'
55-
| '0.6'
56-
| '0.7'
57-
| '0.8'
58-
| '0.9'
59-
| '1.0'
60-
| ''
61-
export type ColorByValue = GenotypeQuality | QScoreBin | Sex | PopulationId | ''
62-
63-
export type AlleleSizeDistributionItem = {
64-
repunit_count: number
65-
frequency: number
66-
colorByValue: ColorByValue
67-
}
68-
69-
export type Sex = 'XX' | 'XY'
70-
71-
export type ColorBy = 'quality_description' | 'q_score' | 'population' | 'sex'
72-
7348
export type AlleleSizeDistributionCohort = {
7449
ancestry_group: PopulationId
7550
sex: Sex
@@ -168,8 +143,6 @@ type ShortTandemRepeatPageProps = {
168143
shortTandemRepeat: ShortTandemRepeat
169144
}
170145

171-
export type ScaleType = 'linear' | 'linear-truncated' | 'log'
172-
173146
// Stacked bar plots only make sense when the y scale factor stays constant
174147
// throughout, so log scale is only allowed when there's only one bar per
175148
// column, that is, when not breaking down the data into subsets.

browser/src/ShortTandemRepeatPage/ShortTandemRepeatPopulationOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Select } from '@gnomad/ui'
55

66
import { PopulationId, GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
77

8-
import { Sex } from './ShortTandemRepeatPage'
8+
import { Sex } from './ShortTandemRepeatAlleleSizeDistributionPlot'
99

1010
const Wrapper = styled.div`
1111
@media (max-width: 600px) {

browser/src/ShortTandemRepeatPage/shortTandemRepeatHelpers.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import {
2-
ColorBy,
3-
GenotypeQuality,
4-
Sex,
52
ShortTandemRepeat,
6-
AlleleSizeDistributionItem,
73
AlleleSizeDistributionCohort,
84
GenotypeDistributionCohort,
95
GenotypeDistributionItem,
106
ShortTandemRepeatAdjacentRepeat,
11-
ColorByValue,
127
} from './ShortTandemRepeatPage'
138

9+
import {
10+
ColorBy,
11+
Sex,
12+
ColorByValue,
13+
AlleleSizeDistributionItem,
14+
} from './ShortTandemRepeatAlleleSizeDistributionPlot'
15+
1416
type AlleleSizeDistributionParams = {
1517
selectedPopulation: string | ''
1618
selectedSex: Sex | ''

browser/src/__factories__/ShortTandemRepeat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const shortTandemRepeatFactory = Factory.define<ShortTandemRepeat>(({ params, as
4949
short_allele_repunit: 'ACCA',
5050
long_allele_repunit: 'GATA',
5151
quality_description: 'high',
52-
q_score: '1.0',
52+
q_score: '1',
5353
distribution: [
5454
{ short_allele_repunit_count: 8, long_allele_repunit_count: 9, frequency: 15 },
5555
{ short_allele_repunit_count: 8, long_allele_repunit_count: 10, frequency: 19 },

0 commit comments

Comments
 (0)