From 4b5c49df3736172a2b9e8c9c0ac5926ab1a8de0d Mon Sep 17 00:00:00 2001 From: Kinggerm Date: Sun, 11 Oct 2020 01:57:38 +0800 Subject: [PATCH] get _set_vdbcfg worked with file caching turned off --- kmunity/Kmunity.py | 106 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/kmunity/Kmunity.py b/kmunity/Kmunity.py index 4559bbd..010b1f5 100644 --- a/kmunity/Kmunity.py +++ b/kmunity/Kmunity.py @@ -78,7 +78,7 @@ def __init__(self, srr=None, db="mammals", workdir="/tmp", repo="./kmunity", **k # config setup only if kwargs.get("config"): self._get_binary() - self._vdb_config() + # self._vdb_config() # run checks on existing results, paths and binaries. else: @@ -248,6 +248,7 @@ def _get_binary(self): self.binaries["prefetch"] = bin_pre self.binaries["fasterq-dump"] = bin_fas self.binaries["vdb-config"] = bin_vdb + self._set_vdbcfg() # print software versions logger.warning("VERSIONS") @@ -458,26 +459,26 @@ def _x_kmerfreq(self, version_only=False): - def _vdb_config(self): - """ - Check whether vdb has been config'd. If not, warn user and exit. - Check whether vdb-config has cache true, and exit if yes. - """ - # user config file is F&$&*$# FORCED to be in home by sra-tools. - logger.warning("CONFIG") - logger.info( - "To finish config sra-tools *requires* you run vdb-config once.") - logger.info( - "I highly recommend turning off 'enable local file caching'.") - logger.info( - "{} -i" - .format(self.binaries["vdb-config"])) - logger.debug( - "This will create a sra-tools config file in {}" - .format(os.path.expanduser("~/.ncbi/"))) - - logger.debug("") - # user config file is F&$&*$# FORCED to be in home by sra-tools. + # def _vdb_config(self): + # """ + # Check whether vdb has been config'd. If not, warn user and exit. + # Check whether vdb-config has cache true, and exit if yes. + # """ + # # user config file is F&$&*$# FORCED to be in home by sra-tools. + # logger.warning("CONFIG") + # logger.info( + # "To finish config sra-tools *requires* you run vdb-config once.") + # logger.info( + # "I highly recommend turning off 'enable local file caching'.") + # logger.info( + # "{} -i" + # .format(self.binaries["vdb-config"])) + # logger.debug( + # "This will create a sra-tools config file in {}" + # .format(os.path.expanduser("~/.ncbi/"))) + # + # logger.debug("") + # # user config file is F&$&*$# FORCED to be in home by sra-tools. @@ -623,36 +624,39 @@ def _clean_work(self): # THIS DOESN'T WORK, VDB-CONFIG CANNOT DISABLE CACHE NON-INTERACTIVELY # AS FAR AS I CAN TELL. UGH. NEED TO ASK USERS TO DO IT WITH -I. - # def _set_vdbcfg(self, reset=False): - # # reset to initial value - # if reset: - # cmd0 = [ - # "vdb-config", "--set", "cache-disabled:{}" - # .format(self.init_cache)] - # out = sps.Popen(cmd0).communicate() - # logger.debug( - # "{vdb-config} --set cache-disabled:{}" - # .format(self.init_cache)) - - # # get and store the initial cache setting - # cmd0 = [self.binaries["vdb-config"], "-a"] - # cmd1 = ["grep", "cache"] - # proc0 = sps.Popen(cmd0, stderr=sps.STDOUT, stdout=sps.PIPE) - # proc1 = sps.Popen(cmd1, stdin=proc0.stdout, stdout=sps.PIPE) - # out = proc1.communicate() - # if proc1.returncode: - # logger.error("Failed: {}".format(out[0].decode())) - # raise OSError("Failed: {}".format(out[0].decode())) - # self.init_cache = out[0].decode().split(">")[-1].split("<")[0] - - # # set new cache value to "true" - # if self.init_cache != "true": - # cmd0 = [ - # self.binaries["vdb-config"], "--set", "cache-disabled:true"] - # out = sps.Popen(cmd0).communicate() - # logger.debug("vdb-config 'cache-disabled' set to 'true'") - - + def _set_vdbcfg(self, reset=False): + # only "--interactive-mode graphical" works for initialization + if not os.path.exists("~/.ncbi/user-settings.mkfg"): + cmd = [self.binaries["vdb-config"], "-i"] + proc = sps.Popen(cmd, stdin=sps.PIPE, stderr=sps.PIPE, stdout=sps.PIPE) + proc.wait() + + # # reset to initial value + # if reset: + # cmd0 = [ + # "vdb-config", "--set", "cache-disabled:{}" + # .format(self.init_cache)] + # out = sps.Popen(cmd0).communicate() + # logger.debug( + # "{vdb-config} --set cache-disabled:{}" + # .format(self.init_cache)) + + # get and store the initial cache setting + # cmd0 = [self.binaries["vdb-config"], "-a"] + # cmd1 = ["grep", "cache"] + # proc0 = sps.Popen(cmd0, stderr=sps.STDOUT, stdout=sps.PIPE) + # proc1 = sps.Popen(cmd1, stdin=proc0.stdout, stdout=sps.PIPE) + # out = proc1.communicate() + # if proc1.returncode: + # logger.error("Failed: {}".format(out[0].decode())) + # raise OSError("Failed: {}".format(out[0].decode())) + # self.init_cache = out[0].decode().split(">")[-1].split("<")[0] + + # set new cache value to "true" + cmd0 = [ + self.binaries["vdb-config"], "--set", "/repository/user/main/public/cache-disabled=true"] + out = sps.Popen(cmd0).communicate() + logger.debug("vdb-config 'cache-disabled' set to 'true'")