示例#1
0
 def test_twostep_h2(self):
     # make sure two step isn't going crazy
     args = parser.parse_args('')
     args.ref_ld = DIR + '/simulate_test/ldscore/oneld_onefile'
     args.w_ld = DIR + '/simulate_test/ldscore/w'
     args.h2 = DIR + '/simulate_test/sumstats/1'
     args.out = DIR + '/simulate_test/1'
     args.chisq_max = 9999999
     args.two_step = 999
     x = s.estimate_h2(args, log)
     args.chisq_max = 9999
     args.two_step = 99999
     y = s.estimate_h2(args, log)
     assert_allclose(x.tot, y.tot, atol=1e-5)
示例#2
0
 def test_twostep_h2(self):
     # make sure two step isn't going crazy
     args = parser.parse_args('')
     args.ref_ld = DIR + '/simulate_test/ldscore/oneld_onefile'
     args.w_ld = DIR + '/simulate_test/ldscore/w'
     args.h2 = DIR + '/simulate_test/sumstats/1'
     args.out = DIR + '/simulate_test/1'
     args.chisq_max = 9999999
     args.two_step = 999
     x = s.estimate_h2(args, log)
     args.chisq_max = 9999
     args.two_step = 99999
     y = s.estimate_h2(args, log)
     assert_allclose(x.tot, y.tot, atol=1e-5)
示例#3
0
    def setUpClass(cls):
        args = parser.parse_args('')
        args.ref_ld = DIR + '/simulate_test/ldscore/twold_onefile'
        args.w_ld = DIR + '/simulate_test/ldscore/w'
        args.chisq_max = 99999
        h2 = []
        h2_noint = []
        for i in xrange(N_REP):
            args.intercept_h2 = None
            args.h2 = DIR + '/simulate_test/sumstats/' + str(i)
            args.out = DIR + '/simulate_test/1'
            h2.append(s.estimate_h2(args, log))
            args.intercept_h2 = 1
            h2_noint.append(s.estimate_h2(args, log))

        cls.h2 = h2
        cls.h2_noint = h2_noint
示例#4
0
    def setUpClass(cls):
        args = parser.parse_args('')
        args.ref_ld = DIR + '/simulate_test/ldscore/twold_onefile'
        args.w_ld = DIR + '/simulate_test/ldscore/w'
        args.chisq_max = 99999
        h2 = []
        h2_noint = []
        for i in xrange(N_REP):
            args.intercept_h2 = None
            args.h2 = DIR + '/simulate_test/sumstats/' + str(i)
            args.out = DIR + '/simulate_test/1'
            h2.append(s.estimate_h2(args, log))
            args.intercept_h2 = 1
            h2_noint.append(s.estimate_h2(args, log))

        cls.h2 = h2
        cls.h2_noint = h2_noint
示例#5
0
 def test_h2_M(self):  # check --M works
     args = parser.parse_args('')
     args.ref_ld = DIR + '/simulate_test/ldscore/oneld_onefile'
     args.w_ld = DIR + '/simulate_test/ldscore/w'
     args.h2 = DIR + '/simulate_test/sumstats/1'
     args.out = DIR + '/simulate_test/1'
     args.print_cov = True  # right now just check no runtime errors
     args.print_delete_vals = True
     x = s.estimate_h2(args, log)
     args.M = str(
         float(open(DIR + '/simulate_test/ldscore/oneld_onefile.l2.M_5_50').read()))
     y = s.estimate_h2(args, log)
     assert_array_almost_equal(x.tot, y.tot)
     assert_array_almost_equal(x.tot_se, y.tot_se)
     args.M = '1,2'
     assert_raises(ValueError, s.estimate_h2, args, log)
     args.M = 'foo_bar'
     assert_raises(ValueError, s.estimate_h2, args, log)
示例#6
0
 def test_h2_M(self):  # check --M works
     args = parser.parse_args('')
     args.ref_ld = DIR + '/simulate_test/ldscore/oneld_onefile'
     args.w_ld = DIR + '/simulate_test/ldscore/w'
     args.h2 = DIR + '/simulate_test/sumstats/1'
     args.out = DIR + '/simulate_test/1'
     args.print_cov = True  # right now just check no runtime errors
     args.print_delete_vals = True
     x = s.estimate_h2(args, log)
     args.M = str(
         float(open(DIR + '/simulate_test/ldscore/oneld_onefile.l2.M_5_50').read()))
     y = s.estimate_h2(args, log)
     assert_array_almost_equal(x.tot, y.tot)
     assert_array_almost_equal(x.tot_se, y.tot_se)
     args.M = '1,2'
     assert_raises(ValueError, s.estimate_h2, args, log)
     args.M = 'foo_bar'
     assert_raises(ValueError, s.estimate_h2, args, log)
示例#7
0
    def test_h2_ref_ld(self):  # test different ways of reading ref ld
        args = parser.parse_args('')
        args.ref_ld_chr = DIR + '/simulate_test/ldscore/twold_onefile'
        args.w_ld = DIR + '/simulate_test/ldscore/w'
        args.h2 = DIR + '/simulate_test/sumstats/555'
        args.out = DIR + '/simulate_test/'
        x = s.estimate_h2(args, log)
        args.ref_ld = DIR + '/simulate_test/ldscore/twold_firstfile,' + \
            DIR + '/simulate_test/ldscore/twold_secondfile'
        y = s.estimate_h2(args, log)
        args.ref_ld_chr = DIR + '/simulate_test/ldscore/twold_firstfile,' + \
            DIR + '/simulate_test/ldscore/twold_secondfile'
        z = s.estimate_h2(args, log)
        assert_almost_equal(x.tot, y.tot)
        assert_array_almost_equal(y.cat, z.cat)
        assert_array_almost_equal(x.prop, y.prop)
        assert_array_almost_equal(y.coef, z.coef)

        assert_array_almost_equal(x.tot_se, y.tot_se)
        assert_array_almost_equal(y.cat_se, z.cat_se)
        assert_array_almost_equal(x.prop_se, y.prop_se)
        assert_array_almost_equal(y.coef_se, z.coef_se)
示例#8
0
    def test_h2_ref_ld(self):  # test different ways of reading ref ld
        args = parser.parse_args('')
        args.ref_ld_chr = DIR + '/simulate_test/ldscore/twold_onefile'
        args.w_ld = DIR + '/simulate_test/ldscore/w'
        args.h2 = DIR + '/simulate_test/sumstats/555'
        args.out = DIR + '/simulate_test/'
        x = s.estimate_h2(args, log)
        args.ref_ld = DIR + '/simulate_test/ldscore/twold_firstfile,' + \
            DIR + '/simulate_test/ldscore/twold_secondfile'
        y = s.estimate_h2(args, log)
        args.ref_ld_chr = DIR + '/simulate_test/ldscore/twold_firstfile,' + \
            DIR + '/simulate_test/ldscore/twold_secondfile'
        z = s.estimate_h2(args, log)
        assert_almost_equal(x.tot, y.tot)
        assert_array_almost_equal(y.cat, z.cat)
        assert_array_almost_equal(x.prop, y.prop)
        assert_array_almost_equal(y.coef, z.coef)

        assert_array_almost_equal(x.tot_se, y.tot_se)
        assert_array_almost_equal(y.cat_se, z.cat_se)
        assert_array_almost_equal(x.prop_se, y.prop_se)
        assert_array_almost_equal(y.coef_se, z.coef_se)
示例#9
0
                    log.log(
                        'The frequency file is unnecessary and is being ignored.'
                    )
                    args.frqfile = None
                    args.frqfile_chr = None
            if args.overlap_annot and not args.not_M_5_50:
                if not ((args.frqfile and args.ref_ld) or
                        (args.frqfile_chr and args.ref_ld_chr)):
                    raise ValueError(
                        'Must set either --frqfile and --ref-ld or --frqfile-chr and --ref-ld-chr'
                    )

            if args.rg:
                sumstats.estimate_rg(args, log)
            elif args.h2:
                sumstats.estimate_h2(args, log)
            elif args.h2_cts:
                sumstats.cell_type_specific(args, log)

            # bad flags
        else:
            print header
            print 'Error: no analysis selected.'
            print 'ldsc.py -h describes options.'
    except Exception:
        ex_type, ex, tb = sys.exc_info()
        log.log(traceback.format_exc(ex))
        raise
    finally:
        log.log('Analysis finished at {T}'.format(T=time.ctime()))
        time_elapsed = round(time.time() - start_time, 2)
示例#10
0
文件: ldsc.py 项目: Chris1221/ldsc
            if (args.samp_prev is not None) != (args.pop_prev is not None):
                raise ValueError('Must set both or neither of --samp-prev and --pop-prev.')

            if not args.overlap_annot or args.not_M_5_50:
                if args.frqfile is not None or args.frqfile_chr is not None:
                    log.log('The frequency file is unnecessary and is being ignored.')
                    args.frqfile = None
                    args.frqfile_chr = None
            if args.overlap_annot and not args.not_M_5_50:
                if not ((args.frqfile and args.ref_ld) or (args.frqfile_chr and args.ref_ld_chr)):
                    raise ValueError ('Must set either --frqfile and --ref-ld or --frqfile-chr and --ref-ld-chr')

            if args.rg:
                sumstats.estimate_rg(args, log)
            elif args.h2:
                sumstats.estimate_h2(args, log)

            # bad flags
        else:
            print header
            print 'Error: no analysis selected.'
            print 'ldsc.py -h describes options.'
    except Exception:
        ex_type, ex, tb = sys.exc_info()
        log.log( traceback.format_exc(ex) )
        raise
    finally:
        log.log('Analysis finished at {T}'.format(T=time.ctime()) )
        time_elapsed = round(time.time()-start_time,2)
        log.log('Total time elapsed: {T}'.format(T=sec_to_str(time_elapsed)))