forked from tonyreina/CRISPResso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·278 lines (231 loc) · 8.77 KB
/
setup.py
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python
"""Description:
Setup script for CRISPResso -- Software pipeline for the analysis of CRISPR-Cas9 genome editing outcomes from deep sequencing data
@status: beta
@version: $Revision$
@author: Luca Pinello
@updater: Tony Reina
@contact: [email protected]
python setup.py bdist_wheel
"""
import os
import sys
import re
from setuptools import setup, Extension
import os
import pickle as cp
import glob
import subprocess as sb
import sys
import platform
import shutil
from os.path import expanduser
import urllib
# TO INSTALL CRISPRESSO DEPENDENCIES IN A CUSTOM LOCATION SET THE ENV VARIABLE: CRISPRESSO_DEPENDENCIES_FOLDER
if os.environ.get("CRISPRESSO_DEPENDENCIES_FOLDER"):
INSTALLATION_PATH = os.environ.get("CRISPRESSO_DEPENDENCIES_FOLDER")
else:
INSTALLATION_PATH = "%s/CRISPResso_dependencies" % os.environ["HOME"]
BIN_FOLDER = os.path.join(INSTALLATION_PATH, "bin")
def main():
# if float(sys.version[:3])<2.6 or float(sys.version[:3])>=2.8:
# sys.stdout.write("CRITICAL: Python version must be 2.7!\n")
# sys.exit(1)
version = re.search(
'^__version__\s*=\s*"(.*)"', open("CRISPResso/CRISPRessoCORE.py").read(), re.M
).group(1)
# if float(sys.version[:3])<2.6 or float(sys.version[:3])>=2.8:
# sys.stdout.write("ERROR: Python version must be 2.6 or 2.7!\n")
# sys.exit(1)
setup(
version="1.1.0",
name="CRISPResso-1.1",
include_package_data=True,
packages=["CRISPResso"],
package_dir={"CRISPResso": "CRISPResso"},
package_data={"CRISPResso": ["data/*"]},
entry_points={
"console_scripts": [
"CRISPResso = CRISPResso.CRISPRessoCORE:main",
"CRISPRessoPooled = CRISPResso.CRISPRessoPooledCORE:main",
"CRISPRessoWGS = CRISPResso.CRISPRessoWGSCORE:main",
"CRISPRessoCompare = CRISPResso.CRISPRessoCompareCORE:main",
"CRISPRessoPooledWGSCompare = CRISPResso.CRISPRessoPooledWGSCompareCORE:main",
"CRISPRessoCount = CRISPResso.CRISPRessoCountCORE:main",
]
},
description="Software pipeline for the analysis of CRISPR-Cas9 genome editing outcomes from deep sequencing data",
author="Luca Pinello / Tony Reina",
author_email="[email protected]",
url="https://github.com/tonyreina/CRISPResso",
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: AGPL License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Programming Language :: Python :: 3",
],
install_requires=[
"numpy",
"pandas",
"matplotlib",
"biopython",
"seaborn",
],
)
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def check_installation(filename, tool_name):
if os.path.isfile(filename):
sys.stdout.write("%s was succesfully installed " % tool_name)
return True
else:
sys.stdout.write(
"Sorry I cannot install %s for you, install manually and try again."
% tool_name
)
return False
def check_flash():
if which("flash"):
sys.stdout.write("\nflash is already installed!")
return True
else:
sys.stdout.write(
"\nCRISPResso requires a recent version FLASh from: http://ccb.jhu.edu/software/FLASH/"
)
sys.stdout.write("\nTrying to install it, please be patient!")
os.chdir("dependencies/")
sb.call("tar xvzf FLASH-1.2.11.tar.gz", shell=True)
os.chdir("FLASH-1.2.11")
sb.call("make", shell=True)
shutil.copy("flash", BIN_FOLDER)
os.chdir("..")
sb.call("rm -Rf FLASH-1.2.11", shell=True)
os.chdir("..")
sys.stdout.write("\nFLASh should be installed (please check the output)")
if not check_installation(os.path.join(BIN_FOLDER, "flash"), "flash"):
sys.exit(1)
else:
return False
def check_needle():
if which("needle"):
sys.stdout.write("\nneedle is already installed!")
return True
else:
sys.stdout.write(
"\nCRISPResso requires a recent version needle from the EMBOSS suite(>=6): http://emboss.sourceforge.net/download/#Stable/"
)
sys.stdout.write("\nTrying to download and install it, please be patient!")
os.chdir("dependencies/")
sys.stdout.write("\nDownloading EMBOSS source please be patient...")
urllib.urlretrieve(
"ftp://emboss.open-bio.org/pub/EMBOSS/old/6.5.0/EMBOSS-6.5.7.tar.gz",
"EMBOSS-6.5.7.tar.gz",
)
sb.call("tar xvzf EMBOSS-6.5.7.tar.gz", shell=True)
os.chdir("EMBOSS-6.5.7")
cmd_cfg = "./configure --prefix=%s --without-x" % INSTALLATION_PATH
sb.call(cmd_cfg, shell=True)
sb.call("make && make install", shell=True)
os.chdir("..")
sb.call("rm -Rf EMBOSS-6.5.7", shell=True)
sb.call("rm EMBOSS-6.5.7.tar.gz", shell=True)
os.chdir("..")
# installa needle
sys.stdout.write("\nneedle should be installed (please check the output)")
if not check_installation(os.path.join(BIN_FOLDER, "needle"), "needle"):
sys.exit(1)
else:
return False
def install_dependencies():
CURRENT_PLATFORM = platform.system().split("_")[0]
if (
CURRENT_PLATFORM not in ["Linux", "Darwin"]
and platform.architecture() != "64bit"
):
sys.stdout.write(
"Sorry your platform is not supported\n CRISPResso is supported only on 64bit versions of Linux or OSX "
)
sys.exit(1)
if not os.path.exists(INSTALLATION_PATH):
sys.stdout.write("OK, creating the folder:%s" % INSTALLATION_PATH)
os.makedirs(INSTALLATION_PATH)
os.makedirs(BIN_FOLDER)
else:
sys.stdout.write(
"\nI cannot create the folder!\nThe folder %s is not empty!"
% INSTALLATION_PATH
)
try:
os.makedirs(BIN_FOLDER)
except:
pass
sys.stdout.write("\nCHECKING DEPENDENCIES...")
flash_already_installed = check_flash()
needle_already_installed = check_needle()
dependencies_already_installed = (
flash_already_installed and needle_already_installed
)
if dependencies_already_installed:
pass
else:
# ADD CRISPResso dependencies to PATH
home = expanduser("~")
shell = os.environ["SHELL"].split("/")[-1]
shell_profile = [
None,
]
line_to_add = None
if shell == "bash":
shell_profiles = [".bash_profile", ".bashrc"]
elif shell == "sh" or shell == "ksh":
shell_profiles = [".profile"]
elif shell == "tcsh":
shell_profiles = [".tcshrc"]
elif shell == "csh":
shell_profiles = [".cshrc"]
if shell in ["bash", "sh", "ksh"]:
line_to_add = "export PATH=%s:$PATH" % BIN_FOLDER
elif shell in ["tcsh", "csh"]:
line_to_add = "set path = ( %s $path)" % BIN_FOLDER
for shell_profile in shell_profiles:
cmd_add_path = "echo '%s' >> ~/%s" % (line_to_add, shell_profile)
if (
not os.path.exists(os.path.join(home, shell_profile))
or not line_to_add in open(os.path.join(home, shell_profile)).read()
):
if shell_profile is None:
sys.stdout.write(
"I cannot determine automatically the shell you are using. Please add the folder %s to your PATH manually!"
% BIN_FOLDER
)
sys.stdout.write("\nExecuting:%s" % cmd_add_path)
sb.call(cmd_add_path, shell=True)
sb.call(line_to_add, shell=True)
sys.stdout.write(
"\n\nINSTALLATION COMPLETED, open a NEW terminal and enjoy CRISPResso!"
)
if __name__ == "__main__":
main()
if sys.argv[1] == "install":
sys.stdout.write("\nPython package installed")
sys.stdout.write("\n\nChecking dependencies...")
install_dependencies()
sys.stdout.write("\nAll done!")