Skip to content

Commit

Permalink
add column formatter and fisher two sided unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Jul 7, 2023
1 parent de2bf9c commit 73cd7bc
Show file tree
Hide file tree
Showing 12 changed files with 840 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/pages/groupComparison/FisherExactTwoSidedTestLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import MutationMapperDataStore from 'shared/components/mutationMapper/MutationMa
import { ComparisonGroup } from './GroupComparisonUtils';
import { toConditionalPrecisionWithMinimum } from 'shared/lib/FormatUtils';
import _ from 'lodash';
import { getTwoTailedPValue } from 'shared/lib/FisherExactTestCalculator';
import { formatPercentValue } from 'cbioportal-utils';
import { getTwoTailedPValue } from 'shared/lib/calculation/FisherExactTestCalculator';
import intersect from 'fast_array_intersect';
import InfoIcon from 'shared/components/InfoIcon';
import { MutationOverlapOverlay } from 'shared/components/mutationTable/column/mutationOverlap/MutationOverlapOverlay';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/groupComparison/GroupComparisonUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
SessionGroupData,
} from 'shared/api/session-service/sessionServiceModels';
import { GroupComparisonMutation } from 'shared/model/GroupComparisonMutation';
import { getTwoTailedPValue } from 'shared/lib/FisherExactTestCalculator';
import { getTwoTailedPValue } from 'shared/lib/calculation/FisherExactTestCalculator';
import { calculateQValues } from 'shared/lib/calculation/BenjaminiHochbergFDRCalculator';

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ describe('MutualExclusivityUtil', () => {
});

describe('#calculatePValue()', () => {
it('returns 0.3653846153846146 for 4, 3, 7, 2', () => {
it('returns 0.5961538461538457 for 4, 3, 7, 2', () => {
assert.equal(calculatePValue(4, 3, 7, 2), 0.5961538461538457);
});

it('returns 0.07706146926536687 for 13, 7, 3, 7', () => {
it('returns 0.12163918040979466 for 13, 7, 3, 7', () => {
assert.equal(calculatePValue(13, 7, 3, 7), 0.12163918040979466);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { getTwoTailedPValue } from '../../../shared/lib/FisherExactTestCalculator';
import { getTwoTailedPValue } from '../../../shared/lib/calculation/FisherExactTestCalculator';
import { MutualExclusivity } from '../../../shared/model/MutualExclusivity';
import { calculateQValues } from '../../../shared/lib/calculation/BenjaminiHochbergFDRCalculator';
import Combinatorics from 'js-combinatorics';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { assert } from 'chai';
import { initMutation } from 'test/MutationMockUtils';
import { Mutation } from 'cbioportal-ts-api-client';
import { GroupComparisonMutation } from 'shared/model/GroupComparisonMutation';
import { enrichedInRenderFunction } from './EnrichedInColumnFormatter';
import { mount, ReactWrapper } from 'enzyme';
import { ComparisonGroup } from 'pages/groupComparison/GroupComparisonUtils';
import styles from 'pages/resultsView/enrichments/styles.module.scss';

describe('EnrichedInColumnFormatter', () => {
const mutation1: Mutation = initMutation({
proteinChange: 'L702H',
});

const mutation2: Mutation = initMutation({
proteinChange: 'H875Y',
});

const mutation3: Mutation = initMutation({
proteinChange: 'A646D',
});

const rowDataByProteinChange: {
[proteinChange: string]: GroupComparisonMutation;
} = {
L702H: {
proteinChange: 'L702H',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedCount: 0,
groupBMutatedPercentage: 0,
logRatio: Infinity,
pValue: 0.00036917378321091467,
qValue: 0.005906780531374635,
},
H875Y: {
proteinChange: 'H875Y',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupBMutatedCount: 1,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: 3.6411453361142803,
pValue: 0.0023260213212133113,
qValue: 0.01860817056970649,
},
A646D: {
proteinChange: 'A646D',
enrichedGroup: '(B) Primary',
groupAMutatedCount: 0,
groupBMutatedCount: 1,
groupAMutatedPercentage: 0,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: -Infinity,
pValue: 0.999999999999234,
qValue: 0.999999999999234,
},
};

const groups: ComparisonGroup[] = [
{
color: '#DC3912',
uid: 'Metastasis',
name: 'Metastasis',
nameWithOrdinal: '(A) Metastasis',
ordinal: 'A',
studies: [],
nonExistentSamples: [],
origin: ['msk_impact_2017'],
description: '',
},
{
color: '#2986E2',
uid: 'Primary',
name: 'Primary',
nameWithOrdinal: '(B) Primary',
ordinal: 'B',
studies: [],
nonExistentSamples: [],
origin: ['msk_impact_2017'],
description: '',
},
];

let component1: ReactWrapper<any, any>;
let component2: ReactWrapper<any, any>;
let component3: ReactWrapper<any, any>;

beforeAll(() => {
component1 = mount(
enrichedInRenderFunction(
rowDataByProteinChange,
[mutation1],
groups
)
);
component2 = mount(
enrichedInRenderFunction(
rowDataByProteinChange,
[mutation2],
groups
)
);
component3 = mount(
enrichedInRenderFunction(
rowDataByProteinChange,
[mutation3],
groups
)
);
});

function testRenderedValues(
component: ReactWrapper<any, any>,
classNames: string[],
value: string
) {
assert.isTrue(
classNames.every(c =>
component.find(`div.${(styles as any)[c]}`).exists()
)
);
assert.equal(component.find(`div`).text(), value);
}

it('renders enriched in column correctly', () => {
testRenderedValues(
component1,
['Tendency', 'Significant', 'ColoredBackground'],
'(A) Metastasis'
);
testRenderedValues(
component2,
['Tendency', 'Significant', 'ColoredBackground'],
'(A) Metastasis'
);
testRenderedValues(component3, ['Tendency'], '(B) Primary');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { assert } from 'chai';
import { initMutation } from 'test/MutationMockUtils';
import { Mutation } from 'cbioportal-ts-api-client';
import { getGroupMutatedCountPercentageTextValue } from './GroupMutatedCountPercentageColumnFormatter';
import { GroupComparisonMutation } from 'shared/model/GroupComparisonMutation';

describe('GroupMutatedCountPercentageColumnFormatter', () => {
const mutation1: Mutation = initMutation({
proteinChange: 'L702H',
});

const mutation2: Mutation = initMutation({
proteinChange: 'H875Y',
});

const mutation3: Mutation = initMutation({
proteinChange: 'A646D',
});

const rowDataByProteinChange: {
[proteinChange: string]: GroupComparisonMutation;
} = {
L702H: {
proteinChange: 'L702H',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedCount: 0,
groupBMutatedPercentage: 0,
logRatio: Infinity,
pValue: 0.00036917378321091467,
qValue: 0.005906780531374635,
},
H875Y: {
proteinChange: 'H875Y',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupBMutatedCount: 1,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: 3.6411453361142803,
pValue: 0.0023260213212133113,
qValue: 0.01860817056970649,
},
A646D: {
proteinChange: 'A646D',
enrichedGroup: '(B) Primary',
groupAMutatedCount: 0,
groupBMutatedCount: 1,
groupAMutatedPercentage: 0,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: -Infinity,
pValue: 0.999999999999234,
qValue: 0.999999999999234,
},
};

it('gets mutated count percentage text value properly', () => {
assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 0, [
mutation1,
]),
'9 (3.25%)'
);
assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 1, [
mutation1,
]),
'0 (0.00%)'
);

assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 0, [
mutation2,
]),
'9 (3.25%)'
);
assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 1, [
mutation2,
]),
'1 (0.26%)'
);

assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 0, [
mutation3,
]),
'0 (0.00%)'
);
assert.equal(
getGroupMutatedCountPercentageTextValue(rowDataByProteinChange, 1, [
mutation3,
]),
'1 (0.26%)'
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { assert } from 'chai';
import { initMutation } from 'test/MutationMockUtils';
import { Mutation } from 'cbioportal-ts-api-client';
import { GroupComparisonMutation } from 'shared/model/GroupComparisonMutation';
import { getLogRatioTextValue } from './LogRatioColumnFormatter';

describe('LogRatioColumnFormatter', () => {
const mutation1: Mutation = initMutation({
proteinChange: 'L702H',
});

const mutation2: Mutation = initMutation({
proteinChange: 'H875Y',
});

const mutation3: Mutation = initMutation({
proteinChange: 'A646D',
});

const rowDataByProteinChange: {
[proteinChange: string]: GroupComparisonMutation;
} = {
L702H: {
proteinChange: 'L702H',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedCount: 0,
groupBMutatedPercentage: 0,
logRatio: Infinity,
pValue: 0.00036917378321091467,
qValue: 0.005906780531374635,
},
H875Y: {
proteinChange: 'H875Y',
enrichedGroup: '(A) Metastasis',
groupAMutatedCount: 9,
groupBMutatedCount: 1,
groupAMutatedPercentage: 3.2490974729241873,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: 3.6411453361142803,
pValue: 0.0023260213212133113,
qValue: 0.01860817056970649,
},
A646D: {
proteinChange: 'A646D',
enrichedGroup: '(B) Primary',
groupAMutatedCount: 0,
groupBMutatedCount: 1,
groupAMutatedPercentage: 0,
groupBMutatedPercentage: 0.26041666666666663,
logRatio: -Infinity,
pValue: 0.999999999999234,
qValue: 0.999999999999234,
},
};

it('gets mutated count percentage text value properly', () => {
assert.equal(
getLogRatioTextValue(rowDataByProteinChange, [mutation1]),
'>10'
);

assert.equal(
getLogRatioTextValue(rowDataByProteinChange, [mutation2]),
'3.64'
);

assert.equal(
getLogRatioTextValue(rowDataByProteinChange, [mutation3]),
'<-10'
);
});
});
Loading

0 comments on commit 73cd7bc

Please sign in to comment.