Package: adafdr
AdaFDRA fast and covariate-adaptive method for multiple hypothesis testing.Software accompanying the paper "AdaFDR: a Fast, Powerful and Covariate-Adaptive Approach to Multiple Hypothesis Testing", 2018.RequirementAdaFDR runs on python 3.6Installationpip install adafdrUsageImport packageadafdr.methodcontains all methods whileadafdr.data_loadercontains the data.
They can be imported asimportadafdr.methodasmdimportadafdr.data_loaderasdlOther ways of importing are usually compatible. For example, one can import the package withimport adafdrand call methodxxxin the method module viaadafdr.method.xxx()Input formatFor a set of N hypotheses, the input data includes the p-valuespand the d-dimensional covariatex,
with the following format:p: (N,) numpy.ndarray.x: (N,d) numpy.ndarray.When d=1,xis allowed to be either (N,) numpy.ndarray
or (N,1) numpy.ndarray.Covariate visualizationThe covariate visualization methodadafdr_explorecan be used asadafdr.method.adafdr_explore(p,x,output_folder=None,covariate_type=None)If theoutput_folderis a filepath (str) instead ofNone, the covariate visualization figures will be
saved inoutput_folder. Otherwise, they will show up in the console.covariate_type: a length-d python list with values 0/1. It specifies the type of each covariate: 0 means numerical/ordinal while 1 means categorical. For example,covariate_type=[0,1]means there are 2 covariates, the first is numerical/ordinal and the second is categorical. If not specified, a covariate with more than 75 distinct values is regarded as numerical/ordinal and otherwise categorical.See alsodocfor more details.Multiple testingThe multiple hypothesis testing methodadafdr_testcan be used asfast version (default):res=adafdr.method.adafdr_test(p,x,alpha=0.1,covariate_type=None)regular version:res=adafdr.method.adafdr_test(p,x,alpha=0.1,fast_mode=False,covariate_type=None)regular version with multi-core:res=adafdr.method.adafdr_test(p,x,alpha=0.1,fast_mode=False,single_core=False,covariate_type=None)resis a dictionary containing the results, including:res['decision']: a (N,) boolean vector, decision for each hypothesis with value 1 meaning rejection.res['threshold']: a (N,) float vector, threshold for each hypothesis.If theoutput_folderis a filepath (str) instead ofNone, the logfiles and some intermediate results will be
saved inoutput_folder. Otherwise, they will show up in the console.covariate_type: a length-d python list with values 0/1. It specifies the type of each covariate: 0 means numerical/ordinal while 1 means categorical. For example,covariate_type=[0,1]means there are 2 covariates, the first is numerical/ordinal and the second is categorical. If not specified, a covariate with more than 75 distinct values is regarded as numerical/ordinal and otherwise categorical.See alsodocfor more details.Example on airway RNA-seq dataThe following is an example on the airway RNA-seq data
used in the paper.Import package and load dataHere we load theairwaydata used in the paper.
Seevignettesfor other data accompanied with the package.importadafdr.methodasmdimportadafdr.data_loaderasdlp,x=dl.data_airway()Covariate visualization usingadafdr_exploremd.adafdr_explore(p,x,output_folder=None)Here, the left is a scatter plot of each hypothesis with p-values (y-axis) plotted against the covariate (x-axis).
The right panel shows the estimated null hypothesis distribution (blue) and the estimated alternative hypothesis
distribution (orange) with respect to the covariate. Here we can conclude that a hypothesis is more likely
to be significant if the covariate (gene expression) value is higher.Multiple hypothesis testing usingadafdr_testres=md.adafdr_test(p,x,fast_mode=True,output_folder=None)Here, the learned thresholdres['threshold']looks as follows.Each orange dot corresponds to the threhsold to one hypothesis. The discrepancy at the right is due to the difference between the thresholds learned by the two folds.Quick TestHere is a quick test. First check if the package can be successfully imported:importadafdr.methodasmdimportadafdr.data_loaderasdlNext, run a small example which should take a few seconds:importnumpyasnpp,x,h,_,_=dl.load_1d_bump_slope()res=md.adafdr_test(p,x,alpha=0.1)t=res['threshold']D=np.sum(p<=t)FD=np.sum((p<=t)&(~h))print('# AdaFDR successfully finished!')print('# D=%d, FD=%d, FDP=%0.3f'%(D,FD,FD/D))It runsAdaFDR-faston a 1d simulated data. If the package is successfully imported,
the result should look like:# AdaFDR successfully finished! 
# D=837, FD=79, FDP=0.094R API of python packageR API of this package can be foundhere.Citation informationZhang, Martin J., Fei Xia, and James Zou. "AdaFDR: a Fast, Powerful and Covariate-Adaptive Approach to Multiple Hypothesis Testing." bioRxiv (2018): 496372.Xia, Fei, et al. "Neuralfdr: Learning discovery thresholds from hypothesis features." Advances in Neural Information Processing Systems. 2017.