def test_gwas(self): logging.info("Leap test_gwas") for i in xrange(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)
#Compute eigendecomposition for the data eigenFile = 'temp_eigen.npz' eigen = leapMain.eigenDecompose(bedExclude, outFile=eigenFile) #compute heritability explained by this data h2 = leapMain.calcH2(phenoFile, prevalence, eigen, keepArr=indsToKeep, h2coeff=1.0) #Compute liabilities explained by this data liabs = leapMain.probit(bedExclude, phenoFile, h2, prevalence, eigen, keepArr=indsToKeep) #perform GWAS, using the liabilities as the observed phenotypes results_df = leapMain.leapGwas(bedExclude, bedTest, liabs, h2) frame_list.append(results_df) #Join together the results of all chromosomes, and print the top ranking SNPs frame = pd.concat(frame_list) frame.sort("PValue", inplace=True) frame.index = np.arange(len(frame)) print('Top 10 most associated SNPs:') print(frame.head(n=10))
#Create a bed object excluding SNPs from the current chromosome bedExclude = leapUtils.getExcludedChromosome(bfile, chrom) #Create a bed object including only SNPs from the current chromosome bedTest = leapUtils.getChromosome(bfile, chrom) #Compute eigendecomposition for the data eigenFile = 'temp_eigen.npz' eigen = leapMain.eigenDecompose(bedExclude, outFile=eigenFile) #compute heritability explained by this data h2 = leapMain.calcH2(phenoFile, prevalence, eigen, keepArr=indsToKeep) #Compute liabilities explained by this data liabs = leapMain.probit(bedExclude, phenoFile, h2, prevalence, eigen, keepArr=indsToKeep) #perform GWAS, using the liabilities as the observed phenotypes results_df = leapMain.leapGwas(bedExclude, bedTest, liabs, h2) frame_list.append(results_df) #Join together the results of all chromosomes, and print the top ranking SNPs frame = pd.concat(frame_list) frame.sort("PValue", inplace=True) frame.index = np.arange(len(frame)) print 'Top 10 most associated SNPs:' print frame.head(n=10)