def test_probit(self): logging.info("Leap test_probit") related_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1.related')) bed, _ = leapUtils.loadData(self.bedbase, None, self.phen_fn, loadSNPs=False) keepArr = leapUtils.loadRelatedFile(bed, related_file) for i in range(1,11): h2_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{0}.h2'.format(i))) h2 = np.loadtxt(h2_file, usecols=[0]) eigen_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}.npz'.format(i))) eigen = np.load(eigen_file) ref_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{}.liabs'.format(i))) extractSim = 'dataset1/extracts/nochr{0}_extract.txt'.format(i) bed, _ = leapUtils.loadData(self.bedbase, extractSim, self.phen_fn, loadSNPs=True) output_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}'.format(i))) leapMain.probit(bed, self.phen_fn, h2=h2, prev=0.001, eigen=eigen, outFile=output_file, keepArr=keepArr, hess=False) self.compare_pheno(ref_file, output_file+'.liabs')
def test_gwas(self): logging.info("Leap test_gwas") for i in range(1,11): h2_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{0}.h2'.format(i))) h2 = np.loadtxt(h2_file, usecols=[0]) ref_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{}.gwas.out.txt'.format(i))) extractSim = 'dataset1/extracts/nochr{0}_extract.txt'.format(i) extract = 'dataset1/extracts/chr{0}_extract.txt'.format(i) bedSim, phe = leapUtils.loadData(self.bedbase, extractSim, self.phen_fn, loadSNPs=True) bedTest, phe = leapUtils.loadData(self.bedbase, extract, self.phen_fn, loadSNPs=True) output_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}.gwas.out.txt'.format(i))) liab_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{}.liabs'.format(i))) eigen_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}.npz'.format(i))) leapMain.leapGwas(bedSim, bedTest, liab_file, h2, output_file, eigenFile=eigen_file) self.compare_gwas(ref_file, output_file)
def setUpClass(self): from fastlmm.util.util import create_directory_if_necessary create_directory_if_necessary(self.tempout_dir, isfile=False) self.pythonpath = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)))) self.bedbase = os.path.join(self.pythonpath, 'dataset1/dataset1') self.phen_fn = os.path.join(self.pythonpath, 'dataset1/dataset1.phe') #Create eigendecompositions logging.info("Creating eigendecomposition files") for i in range(1,11): output_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}.npz'.format(i))) extractSim = 'dataset1/extracts/nochr{0}_extract.txt'.format(i) bed, _ = leapUtils.loadData(self.bedbase, extractSim, self.phen_fn, loadSNPs=True) leapMain.eigenDecompose(bed, output_file)
def test_calch2(self): logging.info("Leap test_calch2") related_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1.related')) bed, _ = leapUtils.loadData(self.bedbase, None, self.phen_fn, loadSNPs=False) keepArr = leapUtils.loadRelatedFile(bed, related_file) for i in range(1,11): h2_file = os.path.abspath(os.path.join(self.gold_dir, 'dataset1_nochr{0}.h2'.format(i))) eigen_file = os.path.abspath(os.path.join(self.tempout_dir, 'dataset1_nochr{}.npz'.format(i))) eigen = np.load(eigen_file) extractSim = 'dataset1/extracts/nochr{0}_extract.txt'.format(i) expected_h2 = np.loadtxt(h2_file, usecols=[0]) h2 = leapMain.calcH2(self.phen_fn, 0.001, eigen, keepArr=keepArr, h2coeff=1.0) assert np.abs(h2-expected_h2)<1e-5, 'Incorrect heritability estimated'
'relatedness cutoff (set to negative value to override relatedness check)' ) parser.add_argument('--missingPhenotype', metavar='missingPhenotype', default='-9', help='identifier for missing values (default: -9)') args = parser.parse_args() if (args.bfilesim is None): raise Exception('--bfilesim must be supplied') if (args.prev is None): raise Exception('--prev must be supplied') if (args.pheno is None): raise Exception('--pheno must be supplied') #Read bfilesim and pheno file for heritability computation bed, phe = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=(args.eigen is None), standardize=True) #Read/create eigendecomposition if (args.eigen is not None): eigen = np.load(args.eigen) else: import eigenDecompose eigen = eigenDecompose.eigenDecompose(bed) #Compute relatedness if (args.relCutoff <= 0): keepArr = np.ones(bed.iid.shape[0], dtype=bool) else: if (args.related is None): bed2 = bed if (args.extractSim is not None or args.eigen is not None):
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--bfilesim", metavar="bfilesim", default=None, help="Binary plink file") parser.add_argument("--extractSim", metavar="extractSim", default=None, help="SNPs subset to use") parser.add_argument("--out", metavar="out", default=None, help="output file") parser.add_argument( "--pheno", metavar="pheno", default=None, help="Phenotypes file (optional), only used for identifying unphenotyped individuals", ) parser.add_argument( "--missingPhenotype", metavar="missingPhenotype", default="-9", help="identifier for missing values (default: -9)", ) args = parser.parse_args() if args.bfilesim is None: raise Exception("bfilesim must be supplied") if args.out is None: raise Exception("output file name must be supplied") # Read input files bed, _ = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=True) leapMain.eigenDecompose(bed, args.out)
help='output file') parser.add_argument( '--pheno', metavar='pheno', default=None, help= 'Phenotypes file (optional), only used for identifying unphenotyped individuals' ) parser.add_argument('--missingPhenotype', metavar='missingPhenotype', default='-9', help='identifier for missing values (default: -9)') args = parser.parse_args() if (args.bfilesim is None and args.kinship is None): raise Exception('bfilesim or kinship must be supplied') if (args.bfilesim is not None and args.kinship is not None): raise Exception('bfilesim and kinship cannot both be supplied') if (args.out is None): raise Exception('output file name must be supplied') if (args.bfilesim is not None): bed, _ = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=True, standardize=True) else: bed = None leapMain.findRelated(bed, args.out, args.cutoff, args.kinship)
keepArr = leapUtils.findRelated(bed, cutoff, kinshipFile) if (outFile is not None): print 'Printing output to', outFile f = open(outFile, 'w') for i, (fid,iid) in enumerate(bed.iid): if (keepArr[i]): f.write(fid + ' ' + iid + ' 0\n') else: f.write(fid + ' ' + iid + ' 1\n') f.close() return keepArr if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--bfilesim', metavar='bfilesim', default=None, help='Binary plink file') parser.add_argument('--kinship', metavar='kinsip', default=None, help='A kinship matrix represented in a text file. Note that this matrix must correspond exactly to the phenotypes file, unlike the bfilesim file option.') parser.add_argument('--extractSim', metavar='extractSim', default=None, help='extractSim file') parser.add_argument('--cutoff', metavar='cutoff', type=float, default=0.05, help='Relationship cutoff (default 0.05)') parser.add_argument('--out', metavar='out', default=None, help='output file') parser.add_argument('--pheno', metavar='pheno', default=None, help='Phenotypes file (optional), only used for identifying unphenotyped individuals') parser.add_argument('--missingPhenotype', metavar='missingPhenotype', default='-9', help='identifier for missing values (default: -9)') args = parser.parse_args() if (args.bfilesim is None and args.kinship is None): raise Exception('bfilesim or kinship must be supplied') if (args.bfilesim is not None and args.kinship is not None): raise Exception('bfilesim and kinship cannot both be supplied') if (args.out is None): raise Exception('output file name must be supplied') if (args.bfilesim is not None): bed, _ = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=True, standardize=True) else: bed=None leapMain.findRelated(bed, args.out, args.cutoff, args.kinship)
parser.add_argument('--maxFixedIters', metavar='maxFixedIters', type=int, default=100, help='Max number of iterations for fitting of fixed effects') parser.add_argument('--epsilon', metavar='epsilon', type=float, default=1e-3, help='Convergence cutoff for fitting of fixed effects') parser.add_argument('--missingPhenotype', metavar='missingPhenotype', default='-9', help='identifier for missing values (default: -9)') args = parser.parse_args() if (args.extract is not None and args.bfile is None): raise Exception('--extract cannot be used without --bfile') if (args.bfile is not None and args.resfile is None): raise Exception('--bfile cannot be used without --resfile') if (args.bfilesim is None): raise Exception('bfilesim must be supplied') if (args.pheno is None): raise Exception('phenotype file must be supplied') if (args.out is None): raise Exception('output file name must be supplied') if (args.prev is None): raise Exception('prevlence must be supplied') if (args.h2 is None): raise Exception('heritability must be supplied') #Read bfilesim and pheno file for heritability computation bed, phe = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=(args.eigen is None), standardize=True) #Read/create eigendecomposition if (args.eigen is not None): eigen = np.load(args.eigen) else: import eigenDecompose eigen = eigenDecompose.eigenDecompose(bed) #Compute relatedness if (args.relCutoff <= 0): keepArr = np.ones(bed.iid.shape[0], dtype=bool) else: if (args.related is None): bed2 = bed if (args.extractSim is not None or args.eigen is not None): bed2, _ = leapUtils.loadData(args.bfilesim, None, args.pheno, args.missingPhenotype, loadSNPs=True) keepArr = leapUtils.findRelated(bed2, args.relCutoff) else:
parser.add_argument('--missingPhenotype', metavar='missingPhenotype', default='-9', help='identifier for missing values (default: -9)') args = parser.parse_args() if (args.bfile is None): raise Exception('bfile must be supplied') if (args.bfilesim is None): raise Exception('bfilesim must be supplied') if (args.pheno is None): raise Exception('phenotype file must be supplied') if (args.out is None): raise Exception('output file name must be supplied') if (args.h2 is None): raise Exception('h2 must be supplied') #Read bfile and pheno file bedSim, _ = leapUtils.loadData(args.bfilesim, args.extractSim, args.pheno, args.missingPhenotype, loadSNPs=True) bedTest, _ = leapUtils.loadData(args.bfile, args.extract, args.pheno, args.missingPhenotype, loadSNPs=True) # #Read covariates # if (args.covar is not None): # covar = leapUtils.loadCovars(bedSim, args.covar) # print 'Read', covar.shape[1], 'covariates from file' # else: covar = None leapMain.leapGwas(bedSim,