Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes for #9943 on frontend #4576

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default class AlterationEnrichmentTable extends React.Component<
Derived from{' '}
{_.values(this.props.data[0].groupsSet).length > 2
? 'Chi-squared test'
: 'one-sided Fisher Exact test'}
: 'two-sided Fisher Exact test'}
</span>
) : (
undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class MutualExclusivityTable extends React.Component<
render: (d: MutualExclusivity) => (
<span>{formatPValue(d.pValue)}</span>
),
tooltip: <span>Derived from one-sided Fisher Exact Test</span>,
tooltip: <span>Derived from two-sided Fisher Exact Test</span>,
sortBy: (d: MutualExclusivity) => d.pValue,
download: (d: MutualExclusivity) => formatPValue(d.pValue),
};
Expand Down
6 changes: 6 additions & 0 deletions src/shared/lib/FisherExactTestCalculator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Calculates the probability of observing the observed counts (a,b,c,d) in a 2x2 contingency table
// given the total count (n) and the factorial of the counts (logFactorial).
function getProbability(
a: number,
b: number,
Expand All @@ -19,6 +21,7 @@ function getProbability(
return Math.exp(p);
}

// Cumulative p-value for a 2x2 contingency table using Fisher's exact test
export function getCumulativePValue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in MutualExclusivityTable, we are using getCumulativePValue function in FisherExactTestCalculator.ts to calculate one-sided Fisher's exact test right now. So we might need to implement a new method for this table to calculate two-sided Fisher's exact test. You can reference the backend implementation: https://github.com/cBioPortal/cbioportal/blob/master/core/src/main/java/org/mskcc/cbio/portal/stats/FisherExact.java#L240

a: number,
b: number,
Expand All @@ -35,14 +38,17 @@ export function getCumulativePValue(
logFactorial[j] = logFactorial[j - 1] + Math.log(j);
}

// probability for the given contingency table
p += getProbability(a, b, c, d, logFactorial);
// cumulative p-value for all tables with greater proportion of observations in 1st row and 1st column
if (a * d >= b * c) {
min = c < b ? c : b;
for (i = 0; i < min; i++) {
p += getProbability(++a, --b, --c, ++d, logFactorial);
}
}

// cumulative p-value for all tables with greater proportion of observations in 2nd row and 2nd column
if (a * d < b * c) {
min = a < d ? a : d;
for (i = 0; i < min; i++) {
Expand Down