# Using Python to solve problems in bioinformatics

## Special functions

For statistical calculations, you will need use special functions for cumulative distributions, such as the cumulative standard normal distribution or the cumulative Student's t distribution. The `transcendental` package, described below, is an extension module that gives access to the special functions available in Cephes. For reasons of portability, this extension module is written in ANSI-C; its compilation should therefore be straightforward. It compiled out of the box on the following systems:

• Microsoft Windows
• Cygwin
• Mac OS X
• Redhat Linux 7.3
• Sun Fire 15K running SunOS 5.8
The `transcendental` module contains an extensive collection of special functions, listed below.

### Usage examples

``` >>> from transcendental import * >>> ndtr(2.) - ndtr(-2.) 0.95449973610364158 ``` About 95% of the normal distribution is contained with 2 standard deviations from the mean.

``` >>> ndtri(0.025) -1.9599639845400545 ``` For a two-sided test, you need a Z-score of about 1.96 (in absolute value) for a statistically significant result at α = 5%.

``` >>> x = array([2.6, 2.1, 1.2, 3.9, -0.3]) >>> n = len(x) >>> m = sum(x)/n >>> m 1.8999999999999999 >>> s = sqrt(sum((x-m)**2)/(n-1)) >>> t = m*sqrt(n)/s >>> t 2.7060146365054543 >>> p = stdtr(n-1,t) >>> p 0.97312075603186332 ``` In a one-sided t-test, this result is significant at α = 5%; in a two-sided t-test, it is not.

## List of available functions

• `cbrt(x)`: Cube root
• `erf(x)`: Error function
• `erfc(x)`: Complementary error function
• `ndtr(x)`: Cumulative standard normal distribution
• `ndtri(p)`: Inverse of the cumulative normal distribution
• `fac(i)`: Factorial function
• `bdtr(k,n,p)`: Cumulative binomial probability density
• `bdtrc(k,n,p)`: Complemented binomial distribution
• `bdtri(k,n,y)`: Inverse binomial distribution
• `nbdtr(k,n,p)`: Cumulative negative binomial probability density
• `nbdtrc(k,n,p)`: Complemented cumulative negative binomial distribution
• `nbdtri(k,n,y)`: Inverse of the cumulative negative binomial distribution
• `gdtr(a,b,x)`: Cumulative gamma probability density
• `gdtrc(a,b,x)`: Complemented cumulative gamma distribution function
• `pdtr(k,m)`: Cumulative Poisson distribution
• `pdtrc(k,m)`: Complemented cumulative Poisson distribution
• `pdtri(k,p)`: Inverse of the cumulative Poisson distribution
• `beta(a,b)`: Beta function
• `igam(a,x)`: Incomplete gamma integral
• `igamc(a,x)`: Complemented incomplete gamma integral
• `igami(a,p)`: Inverse of the complemented incomplete gamma integral
• `incbet(a,b,x)`: Incomplete beta integral
• `incbi(a,b,y)`: Inverse of the incomplete beta integral
• `fresnl(x)`: Fresnel cosine and sine integrals
• `stdtr(k,t)`: Cumulative Student's t distribution
• `stdtri(k,p)`: Inverse of the cumulative Student's t distribution
• `chdtr(v,x)`: Cumulative chi square distribution
• `chdtrc(v,x)`: Complemented cumulative chi square distribution
• `chdtri(v,p)`: Inverse of the complemented cumulative chi square distribution.
• `fdtr(a,b,x)`: Cumulative F distribution
• `fdtrc(a,b,x)`: Complemented cumulative F distribution
• `fdtri(a,b,p)`: Inverse of the complemented cumulative F distribution
• `gamma(x)`: Gamma function
• `lgamma(x)`: Natural logarithm of gamma function
• `rgamma(x)`: Reciprocal gamma function
• `psi(x)`: Psi (digamma) function
• `dawsn(x)`: Dawson's integral
• `j0(x)`: Bessel function of order 0
• `j1(x)`: Bessel function of order 1
• `jn(n,x)`: Bessel function of integer order n
• `jv(v,x)`: Bessel function of noninteger order v
• `y0(x)`: Bessel function of the second kind, order 0
• `y1(x)`: Bessel function of the second kind, order 1
• `yn(n,x)`: Bessel function of the second kind, integer order n
• `yv(v,x)`: Bessel function of the second kind, noninteger order v
• `i0(x)`: Modified Bessel function, order 0
• `i0e(x)`: Modified Bessel function, order 0, exponentially scaled
• `i1(x)`: Modified Bessel function, order 1
• `i1e(x)`: Modified Bessel function, order 1, exponentially scaled
• `iv(v,x)`: Modified Bessel function, order v
• `k0(x)`: Modified Bessel function, third kind, order 0
• `k0e(x)`: Modified Bessel function, third kind, order 0, exponentially scaled
• `k1(x)`: Modified Bessel function, third kind, order 1
• `k1e(x)`: Modified Bessel function, third kind, order 1, exponentially scaled
• `kn(n,x)`: Modified Bessel function, third kind, order n
• `airy(x)`: Airy function
• `expn(n, x)`: Exponential integral
• `shichi(x)`: Hyperbolic sine and cosine integrals
• `sici(x)`: Sine and cosine integrals
• `hyperg(a, b, x)`: Confluent hypergeometric function
• `hyp2f1(a, b, c, x)`: Gauss hypergeometric function
• `ellpk(m1)`: Complete elliptic integral of the first kind
• `ellik(phi, m)`: Incomplete elliptic integral of the first kind
• `ellpe(x)`: Complete elliptic integral of the second kind
• `ellpe(phi, m)`: Incomplete elliptic integral of the second kind
• `ellpj(u, m)`: Jacobian Elliptic functions
• `spence(x)`: Dilogarithm
• `zeta(x, q)`: Riemann zeta function of two arguments
• `zetac(x)`: Riemann zeta function
• `struve(v, x)`: Struve function

### Installation

On Windows, you can use the binary installer. On all other platforms, you can compile the module in three steps:
• `python setup.py config`
This step is actually not necessary, and may not work with Python versions older than 2.3. If you decide to skip it, the loss in precision will be minimal. This step will determine your computer architecture (IEEE 754, Motorola IEEE 754, or DEC), and checks your math library. You may see a lot of error messages when running this command. These messages are normal and can be ignored; the error messages are due to failed trial compilations during the configuration step. The configuration results are written to a file `config.h`, which is used in the subsequent `build` step.
Some `config.h` files that were generated by running `python setup.py config` on various platforms:
• `python setup.py build`
• `python setup.py install`
For the last step, you may need to login as superuser.
transcendental-0.10.tar.gz (source distribution)
transcendental-0.10.win32-py2.5.exe (windows installer for Python 2.5)
transcendental-0.10.win32-py2.6.exe (windows installer for Python 2.6)
transcendental-0.10.win32-py2.7.exe (windows installer for Python 2.7)