Skip to content

Commit

Permalink
display gene panel id for mutated and not profiled samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocnn1104 committed Oct 22, 2019
1 parent f5ba1e6 commit 4581762
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/pages/patientView/PatientViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export default class PatientViewPage extends React.Component<IPatientViewPagePro
columnVisibilityProps={{
onColumnToggled: this.onMutationTableColumnVisibilityToggled
}}
/>
/>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,18 @@ export default class CopyNumberTableWrapper extends React.Component<ICopyNumberT
order: 30
});

const GenePanelProps = (d:DiscreteCopyNumberData[]) => ({
data: d,
sampleToGenePanelId: this.props.sampleToGenePanelId,
sampleManager: this.props.sampleManager,
genePanelIdToGene: this.props.genePanelIdToEntrezGeneIds
});

columns.push({
name: "Gene panel",
render: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.renderFunction(d, this.props.sampleToMutationGenePanelId),
download: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.download(d, this.props.sampleToMutationGenePanelId),
sortBy: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.getGenePanelIds(d, this.props.sampleToMutationGenePanelId),
render: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.renderFunction(GenePanelProps(d)),
download: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.download(GenePanelProps(d)),
sortBy: (d:DiscreteCopyNumberData[]) => PanelColumnFormatter.getGenePanelIds(GenePanelProps(d)),
visible: false,
order: 35
});
Expand Down
13 changes: 10 additions & 3 deletions src/pages/patientView/mutation/PatientViewMutationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,19 @@ export default class PatientViewMutationTable extends MutationTable<IPatientView
download: (d:Mutation[])=>TumorColumnFormatter.getSample(d),
};

const GenePanelProps = (d:Mutation[]) => ({
data: d,
sampleToGenePanelId: this.props.sampleToGenePanelId,
sampleManager: this.props.sampleManager,
genePanelIdToGene: this.props.genePanelIdToEntrezGeneIds
});

this._columns[MutationTableColumnType.GENE_PANEL] = {
name: "Gene panel",
render: (d:Mutation[]) => PanelColumnFormatter.renderFunction(d, this.props.sampleToMutationGenePanelId),
download: (d:Mutation[]) => PanelColumnFormatter.download(d, this.props.sampleToMutationGenePanelId),
render: (d:Mutation[]) => PanelColumnFormatter.renderFunction(GenePanelProps(d)),
download: (d:Mutation[]) => PanelColumnFormatter.download(GenePanelProps(d)),
visible: false,
sortBy: (d:Mutation[]) => PanelColumnFormatter.getGenePanelIds(d, this.props.sampleToMutationGenePanelId)
sortBy: (d:Mutation[]) => PanelColumnFormatter.getGenePanelIds(GenePanelProps(d))
}

// customization for allele count columns
Expand Down
1 change: 0 additions & 1 deletion src/shared/components/mutationTable/MutationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export interface IMutationTableProps {
showCountHeader?:boolean;
columnVisibility?: {[columnId: string]: boolean};
columnVisibilityProps?: IColumnVisibilityControlsProps;
sampleToMutationGenePanelId?: {[sampleId:string]: string};
}

export enum MutationTableColumnType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PanelColumnFormatter from "./PanelColumnFormatter";
import { shallow } from "enzyme";
import PanelColumnFormatter from './PanelColumnFormatter';
import { shallow } from 'enzyme';
import { assert } from 'chai';
import SampleManager from 'pages/patientView/SampleManager';

const mockData = [
{
Expand All @@ -21,29 +22,39 @@ const mockData = [
}
];

const mockSampleToMutationGenePanelId = { 'sampleId': 'genePanelId' };
const mockSamples = [
{ id: 'sampleId', clinicalData: [] }
]

describe("PanelColumnFormatter", () => {
it('renders spinner icon if sampleToMutationGenePanelId object is empty', () => {
const PanelColumn = shallow(PanelColumnFormatter.renderFunction(mockData, {}));
const mockSampleToGenePanelId = { 'sampleId': 'genePanelId' };
const mockGenePanelIdToGene = { 'genePanelId': [1] };
const mockSampleManager = new SampleManager(mockSamples);

const mock = {
data: mockData,
sampleToGenePanelId: mockSampleToGenePanelId,
sampleManager: mockSampleManager,
genePanelIdToGene: mockGenePanelIdToGene
}

describe('PanelColumnFormatter', () => {
it('renders spinner icon if sampleToGenePanelId object is empty', () => {
const PanelColumn = shallow(PanelColumnFormatter.renderFunction({...mock, sampleToGenePanelId: {}}));
assert.isTrue(PanelColumn.find('i.fa-spinner').exists());
});

it('renders gene panel information', () => {
const PanelColumn = shallow(PanelColumnFormatter.renderFunction(
mockData,
mockSampleToMutationGenePanelId
));
const PanelColumn = shallow(PanelColumnFormatter.renderFunction(mock));
assert.isTrue(PanelColumn.text().includes('genePanelId'));
});

it('returns a list of gene panel ids on download', () => {
const genePanelIds = PanelColumnFormatter.download(mockData, mockSampleToMutationGenePanelId);
const genePanelIds = PanelColumnFormatter.download(mock);
assert.deepEqual(genePanelIds, ['genePanelId'])
});

it('returns a list of gene panel ids on getGenePanelIds', () => {
const genePanelIds = PanelColumnFormatter.getGenePanelIds(mockData, mockSampleToMutationGenePanelId);
const genePanelIds = PanelColumnFormatter.getGenePanelIds(mock);
assert.deepEqual(genePanelIds, ['genePanelId'])
})
});
})
63 changes: 35 additions & 28 deletions src/shared/components/mutationTable/column/PanelColumnFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as React from 'react';
import {
Mutation,
DiscreteCopyNumberData
} from 'shared/api/generated/CBioPortalAPI';
import {map} from 'lodash';
import SampleManager from 'pages/patientView/SampleManager';
import { ClinicalDataBySampleId } from 'shared/api/api-types-extended';
import TumorColumnFormatter from 'pages/patientView/mutation/column/TumorColumnFormatter';

interface PanelColumnFormatterProps {
data: Mutation[] | DiscreteCopyNumberData[];
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined;
data: {sampleId:string, entrezGeneId:number}[];
sampleToGenePanelId: {[sampleId: string]: string|undefined};
sampleManager: SampleManager|null;
genePanelIdToGene: {[genePanelId: string]: number[]}
}

class PanelColumn extends React.Component<PanelColumnFormatterProps, {}> {
Expand All @@ -15,18 +17,14 @@ class PanelColumn extends React.Component<PanelColumnFormatterProps, {}> {
}

render() {
const { data, sampleToMutationGenePanelId } = this.props;

if (!sampleToMutationGenePanelId) return;
const { sampleToGenePanelId, sampleManager } = this.props;
if (!sampleToGenePanelId || !sampleManager) return;

if (sampleToMutationGenePanelId && !Object.keys(sampleToMutationGenePanelId).length) {
if (sampleToGenePanelId && !Object.keys(sampleToGenePanelId).length) {
return <i className='fa fa-spinner fa-pulse' />;
}

const genePanelIds: string[] = getGenePanelIds(
data,
sampleToMutationGenePanelId
);
const genePanelIds: string[] = getGenePanelIds(this.props);

return (
<div style={{ position: 'relative' }}>
Expand All @@ -38,30 +36,39 @@ class PanelColumn extends React.Component<PanelColumnFormatterProps, {}> {
}
}

const getGenePanelIds = (
data: any[],
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined
) => {
if (sampleToMutationGenePanelId) {
const sampleIds = data.map((datum) => datum.sampleId);
return sampleIds.map((id) => sampleToMutationGenePanelId[id]);
const getGenePanelIds = (props:PanelColumnFormatterProps) => {
const { data, sampleToGenePanelId, sampleManager, genePanelIdToGene } = props;
if (sampleToGenePanelId && sampleManager) {
const samples = sampleManager.samples;
const sampleIds = map(samples, (sample:ClinicalDataBySampleId) => sample.id)
const entrezGeneId = data[0].entrezGeneId;
const mutatedSamples = TumorColumnFormatter.getPresentSamples(data);
const profiledSamples = TumorColumnFormatter.getProfiledSamplesForGene(entrezGeneId, sampleIds, sampleToGenePanelId, genePanelIdToGene);

const genePanelsIds = samples.map(sample => {
const isMutated = sample.id in mutatedSamples;
const isProfiled = sample.id in profiledSamples && profiledSamples[sample.id];
if (isProfiled && !isMutated) return "";
return sampleToGenePanelId[sample.id] || "N/A";
});

return genePanelsIds.filter(id => id);
}
return [];
};

export default {
renderFunction: (
data: Mutation[] | DiscreteCopyNumberData[],
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined
props:PanelColumnFormatterProps
) => (
<PanelColumn
data={data}
sampleToMutationGenePanelId={sampleToMutationGenePanelId}
data={props.data}
sampleToGenePanelId={props.sampleToGenePanelId}
sampleManager={props.sampleManager}
genePanelIdToGene={props.genePanelIdToGene}
/>
),
download: (
data: Mutation[] | DiscreteCopyNumberData[],
sampleToMutationGenePanelId: {[sampleId:string]: string} | undefined
) => getGenePanelIds(data, sampleToMutationGenePanelId),
props:PanelColumnFormatterProps) => getGenePanelIds(props),
getGenePanelIds
};

0 comments on commit 4581762

Please sign in to comment.