Пример #1
0
    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'
Пример #2
0
	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 xrange(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'
Пример #3
0
    print('Analyzing chromosome', chrom, '...')

    #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,
                         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)
Пример #4
0
for chrom in chromosomes:
	print
	print 'Analyzing chromosome', chrom, '...'

	#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)