import { assert } from 'chai'; import React from 'react'; import _ from 'lodash'; import { AlteredStatus, calculateAssociation, calculateLogOddsRatio, calculatePValue, countOccurences, formatLogOddsRatio, formatPValue, formatQValueWithStyle, getData, getFilteredData, getTrackPairsCountText, } from './MutualExclusivityUtil'; import expect from 'expect'; import expectJSX from 'expect-jsx'; import { mount } from 'enzyme'; import MutualExclusivityTable from './MutualExclusivityTable'; expect.extend(expectJSX); const exampleData = [ { trackA: 'EGFR', trackB: 'KRAS', neitherCount: 0, aNotBCount: 5, bNotACount: 5, bothCount: 0, logOddsRatio: -Infinity, pValue: 0.003968253968253951, qValue: 0.023809523809523704, association: 'Mutual exclusivity', }, { trackA: 'TP53', trackB: 'BRAF', neitherCount: 6, aNotBCount: 0, bNotACount: 1, bothCount: 3, logOddsRatio: Infinity, pValue: 0.03333333333333314, qValue: 0.09999999999999942, association: 'Co-occurrence', }, { trackA: 'EGFR', trackB: 'TP53', neitherCount: 2, aNotBCount: 5, bNotACount: 3, bothCount: 0, logOddsRatio: -Infinity, pValue: 0.08333333333333293, qValue: 0.12499999999999939, association: 'Mutual exclusivity', }, { trackA: 'KRAS', trackB: 'TP53', neitherCount: 5, aNotBCount: 2, bNotACount: 0, bothCount: 3, logOddsRatio: Infinity, pValue: 0.08333333333333293, qValue: 0.12499999999999939, association: 'Co-occurrence', }, { trackA: 'EGFR', trackB: 'BRAF', neitherCount: 2, aNotBCount: 4, bNotACount: 3, bothCount: 1, logOddsRatio: -2.584962500721156, pValue: 0.2619047619047609, qValue: 0.2619047619047609, association: 'Mutual exclusivity', }, { trackA: 'KRAS', trackB: 'BRAF', neitherCount: 4, aNotBCount: 2, bNotACount: 1, bothCount: 3, logOddsRatio: 2.584962500721156, pValue: 0.2619047619047609, qValue: 0.2619047619047609, association: 'Co-occurrence', }, ]; const isSampleAlteredMap: any = { EGFR: [ AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, ], KRAS: [ AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, ], TP53: [ AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, ], BRAF: [ AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, ], }; describe('MutualExclusivityUtil', () => { describe('#calculateAssociation()', () => { it('returns Co-occurrence if log odds ratio is positive', () => { assert.equal(calculateAssociation(1), 'Co-occurrence'); }); it('returns Mutual exclusivity if log odds ratio is 0', () => { assert.equal(calculateAssociation(0), 'Mutual exclusivity'); }); it('returns Mutual exclusivity if log odds ratio is negative', () => { assert.equal(calculateAssociation(-1), 'Mutual exclusivity'); }); }); describe('#countOccurences()', () => { it('returns [1, 0, 0, 1] for [AlteredStatus.UNALTERED, AlteredStatus.ALTERED] and [AlteredStatus.UNALTERED, AlteredStatus.ALTERED]', () => { assert.deepEqual( countOccurences( [AlteredStatus.UNALTERED, AlteredStatus.ALTERED], [AlteredStatus.UNALTERED, AlteredStatus.ALTERED] ), [1, 0, 0, 1] ); }); it('returns [1, 1, 1, 1] for [AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED] and [AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED]', () => { assert.deepEqual( countOccurences( [ AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.ALTERED, ], [ AlteredStatus.UNALTERED, AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, ] ), [1, 1, 1, 1] ); }); it('returns [2, 0, 0, 0] for [AlteredStatus.UNALTERED, AlteredStatus.UNALTERED] and [AlteredStatus.UNALTERED, AlteredStatus.UNALTERED]', () => { assert.deepEqual( countOccurences( [AlteredStatus.UNALTERED, AlteredStatus.UNALTERED], [AlteredStatus.UNALTERED, AlteredStatus.UNALTERED] ), [2, 0, 0, 0] ); }); it('returns [1, 0, 1, 1] for [AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED] and [AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED]', () => { assert.deepEqual( countOccurences( [ AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, ], [ AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, ] ), [1, 0, 1, 0] ); }); it('returns [0, 0, 0, 0] for [AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED] and [AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED]', () => { assert.deepEqual( countOccurences( [ AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, ], [ AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, ] ), [0, 0, 0, 0] ); }); it('returns [0, 0, 0, 0] for [AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED] and [AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED]', () => { assert.deepEqual( countOccurences( [ AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, AlteredStatus.UNPROFILED, ], [ AlteredStatus.ALTERED, AlteredStatus.ALTERED, AlteredStatus.UNALTERED, AlteredStatus.UNALTERED, ] ), [0, 0, 0, 0] ); }); }); describe('#calculatePValue()', () => { it('returns 0.3653846153846146 for 4, 3, 7, 2', () => { assert.equal(calculatePValue(4, 3, 7, 2), 0.3653846153846146); }); it('returns 0.07706146926536687 for 13, 7, 3, 7', () => { assert.equal(calculatePValue(13, 7, 3, 7), 0.07706146926536687); }); }); /* describe("#calculateAdjustedPValue()", () => { it("returns 1 if bigger than 1", () => { assert.equal(calculateAdjustedPValue(0.345, 4), 1); }); it("returns the value if smaller than 1", () => { assert.equal(calculateAdjustedPValue(0.001, 3), 0.003); }); }); */ describe('#calculateLogOddsRatio()', () => { it('returns -1.3923174227787605 for 4, 3, 7, 2', () => { assert.equal( calculateLogOddsRatio(4, 3, 7, 2), -1.3923174227787605 ); }); it('returns 2.1154772174199357 for 13, 7, 3, 7', () => { assert.equal( calculateLogOddsRatio(13, 7, 3, 7), 2.1154772174199357 ); }); it('returns Infinity for 5, 0 ,1, 0', () => { assert.equal(calculateLogOddsRatio(5, 0, 1, 0), Infinity); }); }); /* describe("#getMutuallyExclusiveCounts()", () => { it("returns [no gene pair, null] for empty list", () => { const data: MutualExclusivity[] = []; const result = getMutuallyExclusiveCounts(data, n => n <= 0); expect(result[0]).toEqualJSX(no gene pair); assert.isNull(result[1]); }); it("returns [no gene pair, null] for 0 matched data", () => { const data: MutualExclusivity[] = [ { "trackA": "EGFR", "trackB": "KRAS", "neitherCount": 0, "aNotBCount": 5, "bNotACount": 5, "bothCount": 0, "logOddsRatio": Infinity, "pValue": 0.003968253968253968, "qValue": 0.003968253968253968, "association": "Co-occurrence" } ]; const result = getMutuallyExclusiveCounts(data, n => n <= 0); expect(result[0]).toEqualJSX(no gene pair); assert.isNull(result[1]); }); it("returns [1 gene pair, (none significant)] for " + "1 matched 0 significant data", () => { const data: MutualExclusivity[] = [ { "trackA": "EGFR", "trackB": "KRAS", "neitherCount": 0, "aNotBCount": 5, "bNotACount": 5, "bothCount": 0, "logOddsRatio": -2.1, "pValue": 0.06, "qValue": 0.06, "association": "Mutual exclusivity" } ]; const result = getMutuallyExclusiveCounts(data, n => n <= 0); expect(result[0]).toEqualJSX(1 gene pair); expect(result[1]).toEqualJSX( (none significant)); }); it("returns [1 gene pair, (1 significant)] " + "for 1 matched 1 significant data", () => { const data: MutualExclusivity[] = [ { "trackA": "EGFR", "trackB": "KRAS", "neitherCount": 0, "aNotBCount": 5, "bNotACount": 5, "bothCount": 0, "logOddsRatio": -2.1, "pValue": 0.04, "qValue": 0.04, "association": "Mutual exclusivity" } ]; const result = getMutuallyExclusiveCounts(data, n => n <= 0); expect(result[0]).toEqualJSX(1 gene pair); expect(result[1]).toEqualJSX( (1 significant)); }); it("returns [2 gene pairs, (2 significant)] " + "for 2 matched 2 significant data", () => { const data: MutualExclusivity[] = [ { "trackA": "EGFR", "trackB": "KRAS", "neitherCount": 0, "aNotBCount": 5, "bNotACount": 5, "bothCount": 0, "logOddsRatio": -6.51, "pValue": 0.02, "qValue": 0.04, "association": "Mutual exclusivity" }, { "trackA": "EGFR", "trackB": "TP53", "neitherCount": 2, "aNotBCount": 5, "bNotACount": 3, "bothCount": 0, "logOddsRatio": -2.1, "pValue": 0.001, "qValue": 0.002, "association": "Mutual exclusivity" } ]; const result = getMutuallyExclusiveCounts(data, n => n <= 0); expect(result[0]).toEqualJSX(2 gene pairs); expect(result[1]).toEqualJSX( (2 significant)); }); }); */ describe('#getCountsText()', () => { it('returns correct text', () => { const result = getTrackPairsCountText( exampleData, _.size(isSampleAlteredMap) ); expect(result).toEqualJSX(
The analysis tested 6 pairs between the 4{' '} tracks in the OncoPrint.
); }); }); describe('#getData()', () => { it('returns correct data', () => { const result = getData(isSampleAlteredMap); assert.deepEqual(result, exampleData); }); }); describe('#getFilteredData()', () => { it('returns the data correctly', () => { const result = getFilteredData(exampleData, true, false, true); assert.deepEqual(result, [ { trackA: 'EGFR', trackB: 'KRAS', neitherCount: 0, aNotBCount: 5, bNotACount: 5, bothCount: 0, logOddsRatio: -Infinity, pValue: 0.003968253968253951, qValue: 0.023809523809523704, association: 'Mutual exclusivity', }, ]); }); }); describe('#formatPValue()', () => { it('returns <0.001 for 0.0001', () => { assert.equal(formatPValue(0.0001), '<0.001'); }); it('returns 0.001 for 0.001', () => { assert.equal(formatPValue(0.001), '0.001'); }); it('returns 1.345 for 1.3454546', () => { assert.equal(formatPValue(1.3454546), '1.345'); }); it('returns 0.050 for 0.05', () => { assert.equal(formatPValue(0.05), '0.050'); }); }); describe('#formatPValueWithStyle()', () => { it('returns 0.050 for 0.05', () => { expect(formatQValueWithStyle(0.05)).toEqualJSX(0.050); }); it('returns 0.042 for 0.042', () => { expect(formatQValueWithStyle(0.042)).toEqualJSX( 0.042 ); }); }); describe('#formatLogOddsRatio()', () => { it('returns <-3 for -6.32', () => { assert.equal(formatLogOddsRatio(-6.32), '<-3'); }); it('returns -3.000 for -3', () => { assert.equal(formatLogOddsRatio(-3), '-3.000'); }); it('returns 0.230 for 0.23', () => { assert.equal(formatLogOddsRatio(0.23), '0.230'); }); it('returns 3.000 for 3', () => { assert.equal(formatLogOddsRatio(3), '3.000'); }); it('returns >3 for 4.32', () => { assert.equal(formatLogOddsRatio(4.32), '>3'); }); }); describe('