def install_jbrowse(install_dir, root_url, rename_to=None, conf_file=None): if not conf_file: conf_file = config.get_default_conf_file() install_dir = util.abspath(install_dir) pkg_data_dir = config.get_pkg_data_dir() jbrowse_zip = glob(pjoin(pkg_data_dir,"JBrowse*")) assert len(jbrowse_zip) == 1, "Expected a single JBrowse archive "+\ "stored within the package data dir: %s" % (pkg_data_dir,) jbrowse_zip = jbrowse_zip[0] util.makedir(install_dir) #context manager only works for zipfile in Python 2.7 f = zipfile.ZipFile(jbrowse_zip, 'r') try: install_name = os.path.dirname(f.namelist()[0]) assert (install_name not in (".","..")) and \ os.path.dirname(install_name) == "",\ "Unsafe path detected in JBrowse archive: {}".format(f.namelist()[0]) install_home = pjoin(install_dir,install_name) #JBrowse setup script will not install Pelr modules #if it is executed in a directory where it was ran before, #even unsuccessfuly. #Wack the existing directory: if os.path.exists(install_home): shutil.rmtree(install_home) #somehow zipfile module wacks executable bits #f.extractall(path=install_dir) #unsafe: check_call(["unzip","-q","-o",jbrowse_zip],cwd=install_dir) finally: f.close() if rename_to: install_home_new = pjoin(install_dir,rename_to) if os.path.exists(install_home_new): shutil.rmtree(install_home_new) os.rename(install_home,install_home_new) install_home = install_home_new check_call(["./setup.sh"],cwd=install_home) for line in fileinput.input(pjoin(install_home,"index.html"),inplace=True): #Galaxy Web server intercepts 'data' in URL params, we need to use another name print line.replace('queryParams.data','queryParams.jbrowse_data'), conf = util.load_config_json(conf_file) conf["jbrowse_bin_dir"] = util.abspath(pjoin(install_home,"bin")) conf["jbrowse_url"] = util.urljoin_path(root_url, os.path.basename(install_home)) util.save_config_json(conf,conf_file) return conf_file
def to_jbrowse( genome_name, annot_inp_fasta, annot_out, index_html, data_dir_out, conf_file=None): args = locals() args.pop("conf_file") if not conf_file: conf_file = config.get_default_conf_file() opt = util.load_config_json(conf_file) args["annot_inp_fasta"] = util.none_from_str(args["annot_inp_fasta"]) args["genome_name"] = util.none_from_str(args["genome_name"]) return galaxy_jbrowse(**opt).vicvb_to_jbrowse(**args)
def install_jbrowse(install_dir, root_url, rename_to=None, conf_file=None): if not conf_file: conf_file = config.get_default_conf_file() install_dir = util.abspath(install_dir) pkg_data_dir = config.get_pkg_data_dir() jbrowse_zip = glob(pjoin(pkg_data_dir, "JBrowse*")) assert len(jbrowse_zip) == 1, "Expected a single JBrowse archive "+\ "stored within the package data dir: %s" % (pkg_data_dir,) jbrowse_zip = jbrowse_zip[0] util.makedir(install_dir) #context manager only works for zipfile in Python 2.7 f = zipfile.ZipFile(jbrowse_zip, 'r') try: install_name = os.path.dirname(f.namelist()[0]) assert (install_name not in (".","..")) and \ os.path.dirname(install_name) == "",\ "Unsafe path detected in JBrowse archive: {}".format(f.namelist()[0]) install_home = pjoin(install_dir, install_name) #JBrowse setup script will not install Pelr modules #if it is executed in a directory where it was ran before, #even unsuccessfuly. #Wack the existing directory: if os.path.exists(install_home): shutil.rmtree(install_home) #somehow zipfile module wacks executable bits #f.extractall(path=install_dir) #unsafe: check_call(["unzip", "-q", "-o", jbrowse_zip], cwd=install_dir) finally: f.close() if rename_to: install_home_new = pjoin(install_dir, rename_to) if os.path.exists(install_home_new): shutil.rmtree(install_home_new) os.rename(install_home, install_home_new) install_home = install_home_new check_call(["./setup.sh"], cwd=install_home) for line in fileinput.input(pjoin(install_home, "index.html"), inplace=True): #Galaxy Web server intercepts 'data' in URL params, we need to use another name print line.replace('queryParams.data', 'queryParams.jbrowse_data'), conf = util.load_config_json(conf_file) conf["jbrowse_bin_dir"] = util.abspath(pjoin(install_home, "bin")) conf["jbrowse_url"] = util.urljoin_path(root_url, os.path.basename(install_home)) util.save_config_json(conf, conf_file) return conf_file