1 /* The MIT License 2 3 Copyright (C) 2010, 2013-2014 Genome Research Ltd. 4 Copyright (C) 2011 Attractive Chaos <attractor@live.co.uk> 5 6 Permission is hereby granted, free of charge, to any person obtaining 7 a copy of this software and associated documentation files (the 8 "Software"), to deal in the Software without restriction, including 9 without limitation the rights to use, copy, modify, merge, publish, 10 distribute, sublicense, and/or sell copies of the Software, and to 11 permit persons to whom the Software is furnished to do so, subject to 12 the following conditions: 13 14 The above copyright notice and this permission notice shall be 15 included in all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 SOFTWARE. 25 */ 26 module htslib.kfunc; 27 28 @system: 29 nothrow: 30 @nogc: 31 32 extern (C): 33 34 /* Log gamma function 35 * \log{\Gamma(z)} 36 * AS245, 2nd algorithm, http://lib.stat.cmu.edu/apstat/245 37 */ 38 double kf_lgamma(double z); 39 40 /* complementary error function 41 * \frac{2}{\sqrt{\pi}} \int_x^{\infty} e^{-t^2} dt 42 * AS66, 2nd algorithm, http://lib.stat.cmu.edu/apstat/66 43 */ 44 double kf_erfc(double x); 45 46 /* The following computes regularized incomplete gamma functions. 47 * Formulas are taken from Wiki, with additional input from Numerical 48 * Recipes in C (for modified Lentz's algorithm) and AS245 49 * (http://lib.stat.cmu.edu/apstat/245). 50 * 51 * A good online calculator is available at: 52 * 53 * http://www.danielsoper.com/statcalc/calc23.aspx 54 * 55 * It calculates upper incomplete gamma function, which equals 56 * kf_gammaq(s,z)*tgamma(s). 57 */ 58 59 double kf_gammap(double s, double z); 60 double kf_gammaq(double s, double z); 61 62 /* Regularized incomplete beta function. The method is taken from 63 * Numerical Recipe in C, 2nd edition, section 6.4. The following web 64 * page calculates the incomplete beta function, which equals 65 * kf_betai(a,b,x) * gamma(a) * gamma(b) / gamma(a+b): 66 * 67 * http://www.danielsoper.com/statcalc/calc36.aspx 68 */ 69 double kf_betai(double a, double b, double x); 70 71 /* 72 * n11 n12 | n1_ 73 * n21 n22 | n2_ 74 * -----------+---- 75 * n_1 n_2 | n 76 */ 77 double kt_fisher_exact( 78 int n11, 79 int n12, 80 int n21, 81 int n22, 82 double* _left, 83 double* _right, 84 double* two); 85