Last active
August 29, 2015 14:11
-
-
Save czarrar/c779c1a962e71011b18d to your computer and use it in GitHub Desktop.
Running CWAS with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To use, please install CPAC (CWAS branch) or clone and add this to your path | |
# git clone https://github.com/FCP-INDI/C-PAC.git | |
# cd C-PAC | |
# git checkout cwas | |
# also see: https://github.com/FCP-INDI/C-PAC/tree/cwas | |
from CPAC.cwas import calc_cwas | |
# Load your data | |
## Create the (`S`,`T`,`V`) dataset to hold everything: `S` subjects, `T` timepoints, `V` voxels | |
subjects_data = np.zeros((nsubs,ntpts,nvoxs)) | |
## Loop through each subjects data, load and add to dataset. | |
## Data should be space separated files, although can be anything if set loadtxt differently | |
for i,fname in enumerate(subject_fnames): | |
subjects_data[i,:,:] = np.loadtxt(fname) | |
# Load regressors/model | |
## also should be space separated file but can use something else (e.g., a csv with the pandas library) | |
## Matrix of shape (`S`, `R`), `S` subjects and `R` regressors | |
regressors = np.loadtxt(model_fname) | |
# Setup other variables | |
## indicate the columns that are your regressors of interest and you want to permute | |
## for instance the 2nd column might be age effects, in which case you specify 1 | |
## (since python is 0-based, the 1 is actually the 2nd column) | |
cols = [1] # must be a list | |
## memory limit (beta) | |
memlimit = 4 | |
## strata (if you have a within-subjects design, then specify this) | |
## for instance, if you have drug and placebo scans, then this should be a list indicating the subjects ids for each scan | |
## in this way, MDMR will only permute scan type (drug or placebo) within each subject | |
strata = None | |
## number of permutations | |
nperms = 1000 | |
# Run | |
## the F_set are the raw F-statistics | |
## the p_set output is likely what you would be interested in giving the significance | |
## the Fperms are the F-stats for all the permuted datasets as well as the original data | |
F_set, p_set, Fperms = calc_cwas(subjects_data, regressors, cols, nperms, memlimit=memlimit, strata=strata): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment