Skip to content

Commit

Permalink
Merge pull request #4704 from BasLee/patient-view-sample-colors-scale
Browse files Browse the repository at this point in the history
Add property to define custom sample type colors in patient view
  • Loading branch information
alisman authored Aug 31, 2023
2 parents 614eac8 + 8be8177 commit 45cd9ac
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config/IAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export interface IServerConfig {
skin_comparison_view_mutation_table_columns_show_on_init: string;
skin_patient_view_copy_number_table_columns_show_on_init: string;
skin_patient_view_structural_variant_table_columns_show_on_init: string;
skin_patient_view_custom_sample_type_colors_json: string;
comparison_categorical_na_values: string;
oncoprint_clinical_tracks_config_json: string;
oncoprint_clustered_default: boolean; // this has a default
Expand Down
18 changes: 18 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ export class ServerConfigHelpers {
return matches ? matches.map((s: string) => s.trim()) : [];
}

@memoize
static parseCustomSampleTypeColors(config: string | undefined): any {
const result = {
customSampleTypes: [] as string[],
customSampleTypeToColor: {} as any,
customSampleTypesLower: [] as string[],
};
if (!config) {
return result;
}
result.customSampleTypeToColor = JSON.parse(config);
result.customSampleTypes = _.keys(result.customSampleTypeToColor);
result.customSampleTypesLower = result.customSampleTypes.map(t =>
t.toLowerCase()
);
return result;
}

@memoize static parseConfigFormat(
str: string | null
): CategorizedConfigItems {
Expand Down
2 changes: 2 additions & 0 deletions src/config/serverConfigDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export const ServerConfigDefaults: Partial<IServerConfig> = {

skin_patient_view_structural_variant_table_columns_show_on_init: '',

skin_patient_view_custom_sample_type_colors_json: '',

studyview_max_samples_selected: 0,

study_download_url: '',
Expand Down
15 changes: 15 additions & 0 deletions src/pages/patientView/SampleManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import naturalSort from 'javascript-natural-sort';
import { ClinicalEvent, ClinicalEventData } from 'cbioportal-ts-api-client';
import { SampleLabelHTML } from 'shared/components/sampleLabel/SampleLabel';
import { computed, makeObservable } from 'mobx';
import { getServerConfig, ServerConfigHelpers } from 'config/config';

// sort samples based on event, clinical data and id
// 1. based on sample collection data (timeline event)
Expand Down Expand Up @@ -177,6 +178,7 @@ class SampleManager {
clinicalDataLegacyCleanAndDerived: { [s: string]: any };
sampleColors: { [s: string]: string };
commonClinicalDataLegacyCleanAndDerived: { [s: string]: string };
private customSampleTypeToColor: any;

constructor(
public samples: Array<ClinicalDataBySampleId>,
Expand All @@ -194,6 +196,9 @@ class SampleManager {
// clinical attributes that should be displayed at patient level, since
// they are the same in all samples
this.commonClinicalDataLegacyCleanAndDerived = {};
this.customSampleTypeToColor = ServerConfigHelpers.parseCustomSampleTypeColors(
getServerConfig().skin_patient_view_custom_sample_type_colors_json
).customSampleTypeToColor;

samples.forEach((sample, i) => {
// add legacy clinical data
Expand All @@ -209,6 +214,16 @@ class SampleManager {
// determine color based on DERIVED_NORMALIZED_CASE_TYPE
let color = 'black';
if (
this.customSampleTypeToColor[
this.clinicalDataLegacyCleanAndDerived[sample.id]
.DERIVED_NORMALIZED_CASE_TYPE
]
) {
color = this.customSampleTypeToColor[
this.clinicalDataLegacyCleanAndDerived[sample.id]
.DERIVED_NORMALIZED_CASE_TYPE
];
} else if (
this.clinicalDataLegacyCleanAndDerived[sample.id][
'DERIVED_NORMALIZED_CASE_TYPE'
] === 'Primary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as $ from 'jquery';
import _ from 'underscore';
import * as React from 'react';
import * as styleConsts from './clinicalAttributesStyleConsts.ts';
import { getServerConfig, ServerConfigHelpers } from 'config/config';

/**
* Functions for dealing with clinical attributes.
Expand Down Expand Up @@ -95,6 +96,13 @@ function getFirstKeyFound(object, keys) {
* @param {object} clinicalData - key/value pairs of clinical data
*/
function derive(clinicalData) {
const {
customSampleTypes,
customSampleTypesLower,
} = ServerConfigHelpers.parseCustomSampleTypeColors(
getServerConfig().skin_patient_view_custom_sample_type_colors_json
);

const derivedClinicalAttributes = $.extend({}, clinicalData);

/**
Expand All @@ -116,8 +124,12 @@ function derive(clinicalData) {

if (caseType !== null && typeof caseType !== 'undefined') {
caseTypeLower = caseType.toLowerCase();

if (caseTypeLower.indexOf('metasta') >= 0) {
const foundCustomIndex = customSampleTypesLower.findIndex(
type => caseTypeLower.indexOf(type) >= 0
);
if (foundCustomIndex >= 0) {
caseTypeNormalized = customSampleTypes[foundCustomIndex];
} else if (caseTypeLower.indexOf('metasta') >= 0) {
caseTypeNormalized = 'Metastasis';
} else if (caseTypeLower.indexOf('recurr') >= 0) {
caseTypeNormalized = 'Recurrence';
Expand Down

0 comments on commit 45cd9ac

Please sign in to comment.