import { DefaultTooltip } from 'cbioportal-frontend-commons'; import _ from 'lodash'; import * as React from 'react'; import { observer } from 'mobx-react'; import { IndicatorQueryResp, IndicatorQueryTreatment, } from 'oncokb-ts-api-client'; import featureTableStyle from '../featureTable/FeatureTable.module.scss'; import { generateOncokbLink, ONCOKB_URL } from '../pathogenicity/Oncokb'; interface ITherapeuticImplicationProps { oncokb: IndicatorQueryResp | undefined; isCanonicalTranscriptSelected: boolean; } export const SENSITIVE_LEVELS = [ 'LEVEL_1', 'LEVEL_2', 'LEVEL_3', 'LEVEL_3A', 'LEVEL_3B', 'LEVEL_4', ]; export const RESISTANT_LEVELS = ['LEVEL_R1', 'LEVEL_R2']; @observer class TherapeuticImplication extends React.Component< ITherapeuticImplicationProps > { public sensitiveDrugs( oncokbData: IndicatorQueryResp | undefined, oncokbUrl: string ) { const treatmentsGroupByLevel = this.getTreatmentsGroupByLevel( oncokbData ); // group treatments by level if ( oncokbData && oncokbData.highestSensitiveLevel && treatmentsGroupByLevel ) { const sensitiveTreatmentLevels = this.getSensitiveTreatmentLevels( treatmentsGroupByLevel ); // get all sensitive levels in this mutation const sensitiveDrugs = this.allDrugs( treatmentsGroupByLevel, sensitiveTreatmentLevels ); return (

Sensitive to: {sensitiveDrugs}

); } return null; } public resistantDrugs( oncokbData: IndicatorQueryResp | undefined, oncokbUrl: string ) { const treatmentsGroupByLevel = this.getTreatmentsGroupByLevel( oncokbData ); // group treatments by level if ( oncokbData && oncokbData.highestResistanceLevel && treatmentsGroupByLevel ) { const resistantTreatmentLevels = this.getResistantTreatmentLevels( treatmentsGroupByLevel ); // get all resistant levels in this mutation const resistantDrugs = this.allDrugs( treatmentsGroupByLevel, resistantTreatmentLevels ); return (

Resistant to: {resistantDrugs}

); } return null; } public oncokbTooltip(oncokbUrl: string) { return ( OncoKB™  is a precision oncology knowledge base that contains
information about the effects and treatment implications
of specific cancer gene alterations. } > OncoKB  {!this.props.isCanonicalTranscriptSelected && ( * )}
); } public render() { const oncokbUrl = generateOncokbLink(ONCOKB_URL, this.props.oncokb); const sensitiveDrugs = this.sensitiveDrugs( this.props.oncokb, oncokbUrl ); const resistantDrugs = this.resistantDrugs( this.props.oncokb, oncokbUrl ); return sensitiveDrugs || resistantDrugs ? (
{this.oncokbTooltip(oncokbUrl)}
{sensitiveDrugs} {resistantDrugs}
) : (
{this.oncokbTooltip(oncokbUrl)}
N/A
); } private allDrugs( treatmentsGroupByLevel: { [level: string]: IndicatorQueryTreatment[] }, levels: string[] ) { const drugs: any[] = []; let drugNames: string = ''; _.forEach(levels, level => { drugs.push( _.chain(treatmentsGroupByLevel[level]) .flatMap(treatment => treatment.drugs) .map(drug => drug.drugName) .uniq() .value() ); }); drugNames = _.chain(drugs) .flatMap() .uniq() .value() .join(', '); return drugNames; } private getTreatmentsGroupByLevel( oncokbData: IndicatorQueryResp | undefined ): { [level: string]: IndicatorQueryTreatment[] } | undefined { if (oncokbData && oncokbData.treatments) { return _.groupBy( oncokbData.treatments, treatment => treatment.level ); } return undefined; } private getSensitiveTreatmentLevels(treatmentsGroupByLevel: { [level: string]: IndicatorQueryTreatment[]; }) { return _.chain(treatmentsGroupByLevel) .keys() .filter(level => SENSITIVE_LEVELS.includes(level)) .uniq() .value(); } private getResistantTreatmentLevels(treatmentsGroupByLevel: { [level: string]: IndicatorQueryTreatment[]; }) { return _.chain(treatmentsGroupByLevel) .keys() .filter(level => RESISTANT_LEVELS.includes(level)) .uniq() .value(); } } export default TherapeuticImplication;