Repository navigation
Expand file tree
/
Copy pathgemini_update.py
More file actions
158 lines (149 loc) · 6.57 KB
/
Copy pathgemini_update.py
File metadata and controls
158 lines (149 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""Perform in-place updates of gemini and databases when installed into virtualenv.
"""
import os
import shutil
import subprocess
import sys
import gemini.config
def release(parser, args):
"""Update gemini to the latest release, along with associated data files.
"""
url = "https://raw.github.com/arq5x/gemini/master/requirements.txt"
repo = "https://github.com/arq5x/gemini.git"
cbl_repo = "https://github.com/chapmanb/cloudbiolinux.git"
# update locally isolated python
base = os.path.dirname(os.path.realpath(sys.executable))
gemini_cmd = os.path.join(base, "gemini")
pip_bin = os.path.join(base, "pip")
fab_cmd = os.path.join(base, "fab")
activate_bin = os.path.join(base, "activate")
conda_bin = os.path.join(base, "conda")
if not args.dataonly:
if os.path.exists(conda_bin):
pkgs = ["bx-python", "conda", "cython", "ipython", "jinja2", "nose", "numpy",
"pip", "pycrypto", "pyparsing", "pysam", "pyyaml",
"pyzmq", "pandas", "scipy"]
channels = ["-c", "https://conda.binstar.org/bcbio"]
subprocess.check_call([conda_bin, "install", "--yes", "numpy"])
subprocess.check_call([conda_bin, "install", "--yes"] + channels + pkgs)
elif os.path.exists(activate_bin):
pass
else:
raise NotImplementedError("Can only upgrade gemini installed in anaconda or virtualenv")
# allow downloads excluded in recent pip (1.5 or greater) versions
try:
p = subprocess.Popen([pip_bin, "--version"], stdout=subprocess.PIPE)
pip_version = p.communicate()[0].split()[1]
except:
pip_version = ""
pip_compat = []
if pip_version >= "1.5":
for req in ["python-graph-core", "python-graph-dot"]:
pip_compat += ["--allow-external", req, "--allow-unverified", req]
# update libraries
subprocess.check_call([pip_bin, "install"] + pip_compat + [
8000
"-r", url])
if args.devel:
print("Installing latest GEMINI development version")
subprocess.check_call([pip_bin, "install", "--upgrade", "--no-deps",
"git+%s" % repo])
print "Gemini upgraded to latest version"
if args.tooldir:
print "Upgrading associated tools..."
cbl = get_cloudbiolinux(cbl_repo)
fabricrc = write_fabricrc(cbl["fabricrc"], args.tooldir, args.sudo)
install_tools(fab_cmd, cbl["tool_fabfile"], fabricrc)
# update datafiles
config = gemini.config.read_gemini_config(args=args)
extra_args = ["--extra=%s" % x for x in args.extra]
subprocess.check_call([sys.executable, _get_install_script(), config["annotation_dir"]] + extra_args)
print "Gemini data files updated"
# update tests
if not args.dataonly:
test_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(pip_bin))),
"gemini")
if not os.path.exists(test_dir) or os.path.isdir(test_dir):
_update_testbase(test_dir, repo, gemini_cmd)
print "Run test suite with: cd %s && bash master-test.sh" % test_dir
def _get_install_script():
try:
import pkg_resources
return pkg_resources.resource_filename(__name__, "install-data.py")
except ImportError:
return os.path.join(os.path.dirname(__file__), "install-data.py")
def _update_testbase(repo_dir, repo, gemini_cmd):
cur_dir = os.getcwd()
needs_git = True
if os.path.exists(repo_dir):
os.chdir(repo_dir)
try:
subprocess.check_call(["git", "pull", "origin", "master", "--tags"])
needs_git = False
except:
os.chdir(cur_dir)
shutil.rmtree(repo_dir)
if needs_git:
os.chdir(os.path.split(repo_dir)[0])
subprocess.check_call(["git", "clone", repo])
os.chdir(repo_dir)
_update_testdir_revision(gemini_cmd)
os.chdir(cur_dir)
def _update_testdir_revision(gemini_cmd):
"""Update test directory to be in sync with a tagged installed version or development.
"""
try:
p = subprocess.Popen([gemini_cmd, "--version"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
gversion = p.communicate()[0].split()[1]
except:
gversion = ""
tag = ""
if gversion:
try:
p = subprocess.Popen("git tag -l | grep %s" % gversion, stdout=subprocess.PIPE, shell=True)
tag = p.communicate()[0].strip()
except:
tag = ""
if tag:
subprocess.check_call(["git", "checkout", "tags/%s" % tag])
pass
else:
subprocess.check_call(["git", "reset", "--hard", "HEAD"])
# ## Tools
def get_cloudbiolinux(repo):
base_dir = os.path.join(os.getcwd(), "cloudbiolinux")
if not os.path.exists(base_dir):
subprocess.check_call(["git", "clone", repo])
return {"fabricrc": os.path.join(base_dir, "config", "fabricrc.txt"),
"tool_fabfile": os.path.join(base_dir, "fabfile.py")}
def write_fabricrc(base_file, tooldir, use_sudo):
out_file = os.path.join(os.getcwd(), os.path.basename(base_file))
with open(base_file) as in_handle:
with open(out_file, "w") as out_handle:
for line in in_handle:
if line.startswith("system_install"):
line = "system_install = %s\n" % tooldir
elif line.startswith("local_install"):
line = "local_install = %s/install\n" % tooldir
elif line.startswith("use_sudo"):
line = "use_sudo = %s\n" % use_sudo
elif line.startswith("edition"):
line = "edition = minimal\n"
out_handle.write(line)
return out_file
def install_tools(fab_cmd, fabfile, fabricrc):
"""Install 3rd party tools used by Gemini using a custom CloudBioLinux flavor.
"""
tools = ["tabix", "grabix", "samtools", "bedtools"]
flavor_dir = os.path.join(os.getcwd(), "gemini-flavor")
if not os.path.exists(flavor_dir):
os.makedirs(flavor_dir)
with open(os.path.join(flavor_dir, "main.yaml"), "w") as out_handle:
out_handle.write("packages:\n")
out_handle.write(" - bio_nextgen\n")
out_handle.write("libraries:\n")
with open(os.path.join(flavor_dir, "custom.yaml"), "w") as out_handle:
out_handle.write("bio_nextgen:\n")
for tool in tools:
out_handle.write(" - %s\n" % tool)
cmd = [fab_cmd, "-f", fabfile, "-H", "localhost", "-c", fabricrc,
"install_biolinux:target=custom,flavor=%s" % flavor_dir]
subprocess.check_call(cmd)