Example #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'
Example #2
0
	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)
Example #3
0
	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 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])
			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')
Example #4
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'
Example #5
0
	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 xrange(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)