<s> import numpy as np <EOL> def _ecdf ( x ) : <EOL> '''<STR_LIT>''' <EOL> nobs = len ( x ) <EOL> return np . arange ( <NUM_LIT:1> , nobs + <NUM_LIT:1> ) / float ( nobs ) <EOL> def fdr_correction ( pvals , alpha = <NUM_LIT> , method = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> pvals = np . asarray ( pvals ) <EOL> shape_init = pvals . shape <EOL> pvals = pvals . ravel ( ) <EOL> pvals_sortind = np . argsort ( pvals ) <EOL> pvals_sorted = pvals [ pvals_sortind ] <EOL> sortrevind = pvals_sortind . argsort ( ) <EOL> if method in [ '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT:p>' , '<STR_LIT>' ] : <EOL> ecdffactor = _ecdf ( pvals_sorted ) <EOL> elif method in [ '<STR_LIT:n>' , '<STR_LIT>' ] : <EOL> cm = np . sum ( <NUM_LIT:1.> / np . arange ( <NUM_LIT:1> , len ( pvals_sorted ) + <NUM_LIT:1> ) ) <EOL> ecdffactor = _ecdf ( pvals_sorted ) / cm <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> reject = pvals_sorted < ( ecdffactor * alpha ) <EOL> if reject . any ( ) : <EOL> rejectmax = max ( np . nonzero ( reject ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> rejectmax = <NUM_LIT:0> <EOL> reject [ : rejectmax ] = True <EOL> pvals_corrected_raw = pvals_sorted / ecdffactor <EOL> pvals_corrected = np . minimum . accumulate ( pvals_corrected_raw [ : : - <NUM_LIT:1> ] ) [ : : - <NUM_LIT:1> ] <EOL> pvals_corrected [ pvals_corrected > <NUM_LIT:1.0> ] = <NUM_LIT:1.0> <EOL> pvals_corrected = pvals_corrected [ sortrevind ] . reshape ( shape_init ) <EOL> reject = reject [ sortrevind ] . reshape ( shape_init ) <EOL> return reject , pvals_corrected <EOL> def bonferroni_correction ( pval , alpha = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> pval = np . asarray ( pval ) <EOL> pval_corrected = pval * float ( pval . size ) <EOL> reject = pval_corrected < alpha <EOL> return reject , pval_corrected </s>
