Esempio n. 1
0
def showTests(unknown_args):
    from spower.calculator.vat import getAllTests
    env.logger = getLogger(1)
    if len(unknown_args) == 0:
        # show all tests
        print('\n'.join([
            '{}{}{}'.format(
                test, ' ' * (22 - len(test)), '\n'.join(
                    textwrap.wrap('' if obj.__doc__ is None else obj.__doc__,
                                  initial_indent=' ' * 22,
                                  width=78,
                                  subsequent_indent=' ' * 22))[22:])
            for test, obj in getAllTests()
        ]))
    else:
        names = [x for x in unknown_args if not x.startswith('-')]
        if len(names) > 1:
            raise ValueError('Please specify only one test')
        tests = getAllTests()
        if names[0].lower() not in [x[0].lower() for x in tests]:
            raise ValueError('Unrecognized test name {}."'.format(names[0]))
        # test
        test = [y for x, y in tests if x.lower() == names[0].lower()][0]
        print('Name:          {}'.format(names[0]))
        print('Description:   {}'.format('\n'.join(
            textwrap.wrap(test.__doc__,
                          initial_indent='',
                          subsequent_indent=' ' * 15))))
        # create an instance of the test and pass -h to it
        test(1, ['-h'])
Esempio n. 2
0
 def __init__(self, args, unknown_args):
     self.args = args
     self.unknown_args = unknown_args
     self.option = checkInput(args)
     #
     env.logger = getLogger(max(min(args.verbosity - 1, 2), 0),
                            fn=os.path.splitext(args.output[0])[0],
                            fv=2 if args.verbosity is not 0 else 0)
     env.logger.debug('\n{0}\n{1}\n{0}'.format(
         "=" * min(len(args.cmd), 100), args.cmd))
     self.logger = env.logger.info if args.verbosity != 1 else printinfo
     #
     self.logger('Loading data from [{}] ...'.format(args.data))
     if self.option == 1:
         self.file = SFSFile(args.data)
     else:
         self.file = GFile(args.data)
     self.groups = self.file.getnames()
     self.logger('{:,d} units found'.format(len(self.groups)))
     # load non-missing data
     # to annotate to each variant position wether or not it is missing from assocation analysis
     # name it chip_file because it mimics the behavior of exome chip design
     if args.missing_unlisted:
         self.chip_file = SFSFile(args.missing_unlisted)
     else:
         self.chip_file = None
     # set limit
     if self.args.limit:
         self.limit = min(max(1, args.limit), len(self.groups))
         self.logger('{:,d} units will be analyzed'.format(self.limit))
     else:
         self.limit = len(self.groups)
     self.result = ResultManager(args.output,
                                 action='w' if not args.append else 'a')
     if self.args.verbosity == 1:
         # widgets = [FormatLabel('scanning: unit %(value)d - '), BouncingBar(marker=RotatingMarker())]
         widgets = [
             FormatLabel('scanning: unit %(value)d - '),
             Percentage(), ' ',
             Bar('>'), ' ',
             ETA()
         ]
         self.pbar = ProgressBar(widgets=widgets,
                                 maxval=self.limit,
                                 term_width=get_terminal_size()[0] -
                                 5).start()
     else:
         # use each group's progress bar or not progress bar at all
         self.pbar = ProgressBarNull()
     # this is buffer object to hold all input dict to a list
     self.data_buffer = [] if self.args.replicates < 0 else None
Esempio n. 3
0
 def __init__(self, args, unknown_args):
     self.args = args
     self.unknown_args = unknown_args
     self.option = checkInput(args)
     #
     env.logger = getLogger(
         max(min(args.verbosity - 1, 2), 0),
         fn=os.path.splitext(args.output[0])[0],
         fv=2 if args.verbosity is not 0 else 0,
     )
     env.logger.debug("\n{0}\n{1}\n{0}".format("=" * min(len(args.cmd), 100), args.cmd))
     self.logger = env.logger.info if args.verbosity != 1 else printinfo
     #
     self.logger("Loading data from [{}] ...".format(args.data))
     if self.option == 1:
         self.file = SFSFile(args.data)
     else:
         self.file = GFile(args.data)
     self.groups = self.file.getnames()
     self.logger("{:,d} units found".format(len(self.groups)))
     # load non-missing data
     # to annotate to each variant position wether or not it is missing from assocation analysis
     # name it chip_file because it mimics the behavior of exome chip design
     if args.missing_unlisted:
         self.chip_file = SFSFile(args.missing_unlisted)
     else:
         self.chip_file = None
     # set limit
     if self.args.limit:
         self.limit = min(max(1, args.limit), len(self.groups))
         self.logger("{:,d} units will be analyzed".format(self.limit))
     else:
         self.limit = len(self.groups)
     self.result = ResultManager(args.output, action="w" if not args.append else "a")
     if self.args.verbosity == 1:
         # widgets = [FormatLabel('scanning: unit %(value)d - '), BouncingBar(marker=RotatingMarker())]
         widgets = [FormatLabel("scanning: unit %(value)d - "), Percentage(), " ", Bar(">"), " ", ETA()]
         self.pbar = ProgressBar(widgets=widgets, maxval=self.limit, term_width=get_terminal_size()[0] - 5).start()
     else:
         # use each group's progress bar or not progress bar at all
         self.pbar = ProgressBarNull()
     # this is buffer object to hold all input dict to a list
     self.data_buffer = [] if self.args.replicates < 0 else None
Esempio n. 4
0
def showTests(unknown_args):
    from spower.calculator.vat import getAllTests

    env.logger = getLogger(1)
    if len(unknown_args) == 0:
        # show all tests
        print (
            "\n".join(
                [
                    "{}{}{}".format(
                        test,
                        " " * (22 - len(test)),
                        "\n".join(
                            textwrap.wrap(
                                "" if obj.__doc__ is None else obj.__doc__,
                                initial_indent=" " * 22,
                                width=78,
                                subsequent_indent=" " * 22,
                            )
                        )[22:],
                    )
                    for test, obj in getAllTests()
                ]
            )
        )
    else:
        names = [x for x in unknown_args if not x.startswith("-")]
        if len(names) > 1:
            raise ValueError("Please specify only one test")
        tests = getAllTests()
        if names[0].lower() not in [x[0].lower() for x in tests]:
            raise ValueError('Unrecognized test name {}."'.format(names[0]))
        # test
        test = [y for x, y in tests if x.lower() == names[0].lower()][0]
        print ("Name:          {}".format(names[0]))
        print (
            "Description:   {}".format(
                "\n".join(textwrap.wrap(test.__doc__, initial_indent="", subsequent_indent=" " * 15))
            )
        )
        # create an instance of the test and pass -h to it
        test(1, ["-h"])
Esempio n. 5
0
from spower.utils import getLogger
from playground import *
if __name__ == "__main__":
    d = PlayGround(getLogger(1))
    # Generate GF in cases, via PAR model
    #- set PAR model
    # huge OR resulted
    assert True == L.PARModel([.25, .25, 0, 0], True).apply(d.data)
    res = d.get(["effect", 'par'])
    almost_equal(.5, sum(res["par"]))
    almost_equal(
        res['effect'],
        (3.69538420811764, 2446.0352249655757, 64.6018420615153,
         2446.0352249655757, 1.0, 1.0, 1.0, 9.990065341916748e-05,
         16.80005324201965, 2446.0352249655757, 1.0, 3.8916187359828944))
    almost_equal(
        res['par'],
        (0.002596439286207404, 0.07529673618148339, 0.01254945603024723,
         0.07529673618148339, 0.0, 0.0, 0.0, 0.25, 0.006274726759048802,
         0.07529673618148339, 0.0, 0.0026891693800463775))
    #- update GF by PAR method
    res0 = d.get(["gf0", "gf2"])
    assert True == L.PARGFUpdater(2).apply(d.data)
    res = d.get(["gf0", "gf2"])
    strictly_le(res["gf0"], res0["gf0"])
    strictly_ge(res["gf2"], res0["gf2"])
    almost_equal(res['gf0'],
                 (0.9964586302149315, 0.9345310735676225, 0.9875652213478052,
                  0.9345310735676225, 0.9999000924155059, 0.64071956214016,
                  0.9341482876914409, 0.9999666969172785, 0.9934107737743848,
                  0.9345310735676225, 0.9982689749609894, 0.99640017414124))
Esempio n. 6
0
from spower.utils import getLogger
from playground import *
if __name__ == "__main__":
    d = PlayGround(getLogger(1))
    # Generate GF in cases, via OR model
    #- set OR model
    assert True == L.ORModel([0,1.78,0,0.9,1.1]).apply(d.data)
    res = d.get(["effect", 'par'])
    assert res['effect'] == (1.78, 1.78, 1.78, 1.78, 1.0, 1.1, 1.0, 0.9, 1.78, 1.78, 1.0, 1.78)
    almost_equal(res['par'], (0.0007527551788200869, 2.5975946043922594e-05, 0.00015583543875803612, 2.5975946043922594e-05, 0.0, 0.038674581525736176, 0.0, 3.700359640847335e-06, 0.0003116223926300634, 2.5975946043922594e-05, 0.0, 0.000726816919595037))
    #- update GF by OR method
    res0 = d.get(["gf0", "gf2"])
    assert True == L.ORGFUpdater(2.0, 0.01).apply(d.data)
    res = d.get(["gf0", "gf2"])
    #
    for x,y,z in zip(res0['gf0'], res['gf0'], d.get("direction")):
        if z == 'd':
            assert x > y
        else:
            assert round(x,5) <= round(y,5)

    for x,y,z in zip(res0['gf2'], res['gf2'], d.get("direction")):
        if z == 'd':
            assert x < y
        else:
            assert round(x,5) >= round(y,5)
    #
    almost_equal(res['gf0'], (0.9982956803933704, 0.9999411806025909, 0.9996471369540085, 0.9999411806025909, 0.9999000924155059, 0.616389730164512, 0.9341482876914409, 0.9999699971512321, 0.9992944017432116, 0.9999411806025909, 0.9982689749609894, 0.9983544003888292))
    almost_equal(res['gf2'], (5.901075301235597e-07, 7.021750290206489e-10, 2.5275076303345994e-08, 7.021750290206489e-10, 2.4955060214016003e-09, 0.04588573802725315, 0.0011213476914409, 2.223230920032367e-10, 1.0108487126230469e-07, 7.021750290206489e-10, 7.497609894787601e-07, 5.501261115497627e-07))
    #
    res = d.get(['wt_penetrance','heterozygotes_penetrance','homozygotes_penetrance','all_prevalence'])
Esempio n. 7
0
from spower.utils import getLogger
from spower.simulator.sampler import Sample

if __name__ == "__main__":
    d = Sample(getLogger(1))
    d.seed(0, 1)
    c = d.clone()
    c.seed(0, 1)
Esempio n. 8
0
from spower.utils import getLogger
from spower.simulator.sampler import Sample
if __name__ == "__main__":
    d = Sample(getLogger(1))
    d.seed(0, 1)
    c = d.clone()
    c.seed(0, 1)