Skip to content

Code documentation

Matthew Reyna edited this page Jan 2, 2018 · 14 revisions

Scripts

Follow the links below to view documentation on each of the scripts for running WExT.

API for exclusivity tests

We strive to make it easy to compute the weighted-row exclusivity (WR-exclusivity) test with WExT, or the row-exclusivity (RE-exclusivity) test with CoMEt in your own Python scripts. We provide documentation of the interface for computing the WR-exclusivity or RE-exclusivity tests, as well as an example, below.

WR-exclusivity test with WExT

WExT's wre_test computes the WR-exclusivity p-value exactly or with the saddlepoint approximation.

wre_test(t, x, p, method=EXACT, verbose=0)
Parameter Required (Default) Description
t True Number of samples with an exclusive mutation.
x True List of length k number of mutated samples per gene.
p True k nested lists of length N with the per gene, per patient mutation probabilities.
method False (EXACT) The method (EXACT or SADDLEPOINT) used to compute the p-value.
verbose False (0) Flag verbose output.

RE-exclusivity test with WExT

The re_test computes the p-value exactly (with CoMEt's tail enumeration procedure) or with the saddlepoint approximation.

re_test(t, x, tbl, method=EXACT, verbose=0)
Parameter Required (Default) Description
t True Number of samples with an exclusive mutation.
x True List of length k number of mutated samples per gene.
tbl True List representing a flattened contingency table.
method False (EXACT) The method (EXACT or SADDLEPOINT) used to compute the p-value.
verbose False (0) Flag verbose output.

WR test with WExT

WExT's general_wre_test computes the WR p-value with for various test statistics, including exclusivity, using the saddlepoint approximation.

general_wre_test(gene_set, geneToCases, p, condition, verbose=0)
Parameter Required (Default) Description
gene_set True List of genes.
geneToCases True Dictionary with mutated samples for each gene in gene set.
p True k nested lists of length N with the per gene, per patient mutation probabilities.
condition True The test statistic (EXCLUSIVITY, ANY_CO_OCCURRENCE, ALL_CO_OCCURRENCE, or user defined) used to compute the p-value.
verbose False (0) Flag verbose output.

Example

In this code example, we compute the weighted (WExT) and unweighted (CoMEt) tests directly.

# Load required modules
from wext import wre_test, re_test, SADDLEPOINT, EXACT
import numpy as np

# Hard-code data and generate random mutation probabilities
N   = 100
k   = 3
T   = 54
X   = [ 29, 26, 19 ]
tbl = [ 35, 22, 17, 5, 15, 0, 2, 2 ]
P   = np.random.rand(k, N)

# Compute the saddlepoint approximation of WExT
wre_test( T, X, P, method=EXACT )
wre_test( T, X, P, method=SADDLEPOINT )

# Compute the exact and saddlepoint approximation of CoMEt 
re_test( T, X, tbl, method=SADDLEPOINT )
re_test( T, X, tbl, method=EXACT )

Last modified: 1:43 PM Tuesday, Jan 2, 2017 (EST)

Clone this wiki locally