Skip to content

Commit 027d944

Browse files
author
Bryan Lai
committed
extract isExcludedProteinImpactType to separate function
1 parent d84f549 commit 027d944

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed

src/shared/components/mutationMapper/DriverAnnotationProteinImpactTypeBadgeSelector.tsx

+38-43
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ function badgeLabelFormat(
135135
}
136136
}
137137

138+
function isExcludedProteinImpactType(
139+
type: ProteinImpactType,
140+
excludedProteinTypes?: string[],
141+
counts?: { [proteinImpactType: string]: number }
142+
) {
143+
return !(
144+
excludedProteinTypes?.includes(
145+
type.split('_')[0] // get protein type without driver/vus suffix
146+
) ||
147+
((type === ProteinImpactType.OTHER_PUTATIVE_DRIVER ||
148+
type === ProteinImpactType.OTHER_UNKNOWN_SIGNIFICANCE ||
149+
type === ProteinImpactType.OTHER) &&
150+
counts &&
151+
counts[ProteinImpactType.OTHER_PUTATIVE_DRIVER] +
152+
counts[ProteinImpactType.OTHER_UNKNOWN_SIGNIFICANCE] ===
153+
0)
154+
);
155+
}
156+
138157
@observer
139158
export default class DriverAnnotationProteinImpactTypeBadgeSelector extends ProteinImpactTypeBadgeSelector<
140159
IDriverAnnotationProteinImpactTypeBadgeSelectorProps
@@ -146,29 +165,20 @@ export default class DriverAnnotationProteinImpactTypeBadgeSelector extends Prot
146165
super(props);
147166
makeObservable(this);
148167

149-
this.putativeDriverTypes = PUTATIVE_DRIVER_TYPE.filter(
150-
t =>
151-
!(
152-
this.props.excludedProteinTypes?.includes(
153-
t.slice(0, t.indexOf('_'))
154-
) ||
155-
(t === ProteinImpactType.OTHER_PUTATIVE_DRIVER &&
156-
this.props.counts?.[
157-
ProteinImpactType.OTHER_PUTATIVE_DRIVER
158-
] === 0)
159-
)
168+
// filter out driver/vus types prefixed by protein types in excludedProteinTypes
169+
this.putativeDriverTypes = PUTATIVE_DRIVER_TYPE.filter(t =>
170+
isExcludedProteinImpactType(
171+
t,
172+
this.props.excludedProteinTypes,
173+
this.props.counts
174+
)
160175
);
161-
this.unknownSignificanceTypes = UNKNOWN_SIGNIFICANCE_TYPE.filter(
162-
t =>
163-
!(
164-
this.props.excludedProteinTypes?.includes(
165-
t.slice(0, t.indexOf('_'))
166-
) ||
167-
(t === ProteinImpactType.OTHER_UNKNOWN_SIGNIFICANCE &&
168-
this.props.counts?.[
169-
ProteinImpactType.OTHER_UNKNOWN_SIGNIFICANCE
170-
] === 0)
171-
)
176+
this.unknownSignificanceTypes = UNKNOWN_SIGNIFICANCE_TYPE.filter(t =>
177+
isExcludedProteinImpactType(
178+
t,
179+
this.props.excludedProteinTypes,
180+
this.props.counts
181+
)
172182
);
173183
}
174184

@@ -252,27 +262,12 @@ export default class DriverAnnotationProteinImpactTypeBadgeSelector extends Prot
252262

253263
protected get options() {
254264
// get options, hide "Other" if it's 0
255-
let excludedProteinTypes = this.props.excludedProteinTypes || [];
256-
if (
257-
this.props.counts &&
258-
this.props.counts[ProteinImpactType.OTHER_PUTATIVE_DRIVER] +
259-
this.props.counts[
260-
ProteinImpactType.OTHER_UNKNOWN_SIGNIFICANCE
261-
] ===
262-
0
263-
) {
264-
excludedProteinTypes = excludedProteinTypes.concat([
265-
ProteinImpactWithoutVusMutationType.OTHER,
266-
]);
267-
}
268-
return SELECTOR_VALUE_WITH_VUS.filter(
269-
type =>
270-
!(
271-
excludedProteinTypes.includes(type) ||
272-
excludedProteinTypes.includes(
273-
type.slice(0, type.indexOf('_'))
274-
)
275-
)
265+
return SELECTOR_VALUE_WITH_VUS.filter(type =>
266+
isExcludedProteinImpactType(
267+
type,
268+
this.props.excludedProteinTypes,
269+
this.props.counts
270+
)
276271
).map(value => ({
277272
value,
278273
label: this.optionDisplayValueMap[value],

0 commit comments

Comments
 (0)