-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
executable file
·320 lines (248 loc) · 12.7 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env python
"""Description:
Setup script for Haystack -- Epigenetic Variability and Transcription Factor Motifs Analysis Pipeline
@status: beta
@version: $Revision$
@author: Luca Pinello
@contact: lpinello@jimmy.harvard.edu
"""
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
import time
from distutils.dir_util import copy_tree
#TO INSTALL HAYSTACK DEPENDECIENS IN A CUSTOM LOCATION SET THE ENV VARIABLE: HAYSTACK_DEPENDENCIES_FOLDER
if os.environ.get('HAYSTACK_DEPENDENCIES_FOLDER'):
INSTALLATION_PATH=os.environ.get('HAYSTACK_DEPENDENCIES_FOLDER')
else:
INSTALLATION_PATH='%s/Haystack_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('haystack/haystack_common.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=version,
name = "haystack_bio",
include_package_data = True,
packages = ["haystack"],
package_dir={'haystack': 'haystack'},
package_data={'haystack': ['./*']},
entry_points = {
"console_scripts": ['haystack_pipeline = haystack.haystack_pipeline_CORE:main',
'haystack_hotspots = haystack.haystack_hotspots_CORE:main',
'haystack_motifs = haystack.haystack_motifs_CORE:main',
'haystack_tf_activity_plane = haystack.haystack_tf_activity_plane_CORE:main',
'haystack_download_genome = haystack.haystack_download_genome_CORE:main',]
},
description="Epigenetic Variability and Transcription Factor Motifs Analysis Pipeline",
author='Luca Pinello',
author_email='lpinello@jimmy.harvard.edu',
url='http://github.com/lucapinello/Haystack',
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Programming Language :: Python',
],
install_requires=[
'numpy>=1.8.2',
'pandas>=0.13.1',
'matplotlib>=1.3.1',
'argparse>=1.3',
'scipy>=0.13.3',
'jinja2>=2.7.3',
'bx-python>=0.7.3',
],
)
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,verbose=False):
if os.path.isfile(filename):
if verbose:
sys.stdout.write('%s is/was succesfully installed ' % tool_name)
return True
else:
if verbose:
sys.stdout.write('Sorry I cannot install %s for you, check you have all the required dependencies and and try again to install HAYSTACK.' % tool_name)
return False
def check_fimo():
if not check_installation(os.path.join(BIN_FOLDER,'fimo'),'FIMO',verbose=False):
sys.stdout.write('\nHAYSTACK requires to install FIMO from the MEME suite(4.11.1)')
sys.stdout.write('I will download and install for you. Please be patient!')
os.chdir('dependencies/')
sb.call('rm -Rf meme_4.11.1 &> /dev/null',shell=True)
sb.call('rm meme_4.11.1.tar.bz2 &> /dev/null',shell=True)
urllib.urlretrieve ('http://bcb.dfci.harvard.edu/~lpinello/HAYSTACK/dependencies/meme_4.11.1.tar.bz2','meme_4.11.1.tar.bz2')
sb.call('tar xvjf meme_4.11.1.tar.bz2',shell=True)
os.chdir('meme_4.11.1/')
cmd_cfg='./configure --prefix=%s --enable-build-libxml2 --enable-build-libxslt ' % INSTALLATION_PATH
sys.stdout.write(cmd_cfg)
sb.call(cmd_cfg,shell=True)
#sb.call('make clean',shell=True)
sb.call('make && make install',shell=True)
#sb.call('make clean',shell=True)
os.chdir('..')
sb.call('rm -Rf meme_4.11.1',shell=True)
sb.call('rm meme_4.11.1.tar.bz2',shell=True)
os.chdir('..')
#installa fimo
sys.stdout.write('FIMO should be installed (please check the output)')
if not check_installation(os.path.join(BIN_FOLDER,'fimo'),'FIMO'):
sys.exit(1)
def check_samtools():
if not check_installation(os.path.join(BIN_FOLDER,'samtools'),'SAMTOOLS',verbose=False):
sys.stdout.write('\nHAYSTACK requires to install SAMTOOLS 0.1.19:http://sourceforge.net/projects/samtools/files/samtools/0.1.19/')
sys.stdout.write('I will download and install for you. Please be patient!')
os.chdir('dependencies/')
sb.call('rm -Rf samtools-0.1.19 &> /dev/null',shell=True)
sb.call('rm samtools-0.1.19.tar.bz2 &> /dev/null',shell=True)
urllib.urlretrieve ('http://bcb.dfci.harvard.edu/~lpinello/HAYSTACK/dependencies/samtools-0.1.19.tar.bz2','samtools-0.1.19.tar.bz2')
sb.call('tar xvjf samtools-0.1.19.tar.bz2',shell=True)
os.chdir('samtools-0.1.19/')
sb.call('make clean',shell=True)
sb.call('make',shell=True)
try:
shutil.copy2('samtools',BIN_FOLDER)
except:
pass
#sb.call('make clean',shell=True)
os.chdir('..')
sb.call('rm -Rf samtools-0.1.19',shell=True)
sb.call('rm samtools-0.1.19.tar.bz2',shell=True)
os.chdir('..')
if not check_installation(os.path.join(BIN_FOLDER,'samtools'),'SAMTOOLS'):
sys.exit(1)
def check_bedtools():
if not check_installation(os.path.join(BIN_FOLDER,'bedtools'),'BEDTOOLS',verbose=False):
sys.stdout.write('\nHAYSTACK requires to install BEDTOOLS v2.20.1')
sys.stdout.write('I will download and install for you. Please be patient!')
os.chdir('dependencies/')
sb.call('rm bedtools2-2.20.1.tar.bz2 &> /dev/null',shell=True)
sb.call('rm -Rf bedtools2-2.20.1 &> /dev/null',shell=True)
urllib.urlretrieve ('http://bcb.dfci.harvard.edu/~lpinello/HAYSTACK/dependencies/bedtools2-2.20.1.tar.bz2','bedtools2-2.20.1.tar.bz2')
sb.call('tar xvjf bedtools2-2.20.1.tar.bz2',shell=True)
os.chdir('bedtools2-2.20.1/')
sb.call('make clean',shell=True)
sb.call('make',shell=True)
for filename in glob.glob(os.path.join('bin', '*')):
shutil.copy(filename, BIN_FOLDER)
#sb.call('make clean',shell=True)
os.chdir('..')
sb.call('rm -Rf bedtools2-2.20.1',shell=True)
sb.call('rm bedtools2-2.20.1.tar.bz2',shell=True)
os.chdir('..')
if not check_installation(os.path.join(BIN_FOLDER,'bedtools'),'BEDTOOLS'):
sys.exit(1)
def check_ghostscript(CURRENT_PLATFORM):
if (not check_installation(os.path.join(BIN_FOLDER,'gs'),'Ghostscript',verbose=False) and CURRENT_PLATFORM=='Linux') or ( CURRENT_PLATFORM=='Darwin' and which('gs') is None):
sys.stdout.write('\nHAYSTACK requires to install Ghostscript 9.14')
if CURRENT_PLATFORM=='Linux':
sys.stdout.write('I will download and install for you. Please be patient!')
sb.call('rm dependencies/Linux/gs &> /dev/null',shell=True)
urllib.urlretrieve ('http://bcb.dfci.harvard.edu/~lpinello/HAYSTACK/dependencies/Linux/gs','dependencies/Linux/gs')
shutil.copy2('dependencies/Linux/gs',BIN_FOLDER)
time.sleep(3) # we need some time to allow the NFS to sync the file...
sb.call('chmod +x %s' % os.path.join(BIN_FOLDER,'gs'),shell=True)
sb.call('rm dependencies/Linux/gs',shell=True)
#if not check_installation(os.path.join(BIN_FOLDER,'gs'),'Ghostscript'):
# sys.exit(1)
elif CURRENT_PLATFORM=='Darwin':
sys.stdout.write('Ok downloading and launching the installer for you!')
sb.call('rm dependencies/Darwin/Ghostscript-9.14.pkg &> /dev/null',shell=True)
urllib.urlretrieve ('http://bcb.dfci.harvard.edu/~lpinello/HAYSTACK/dependencies/Darwin/Ghostscript-9.14.pkg','dependencies/Darwin/Ghostscript-9.14.pkg')
sys.stdout.write('To install Ghostscript I need admin privileges.')
sb.call('sudo installer -pkg dependencies/Darwin/Ghostscript-9.14.pkg -target /',shell=True)
sb.call('rm dependencies/Darwin/Ghostscript-9.14.pkg',shell=True)
def install_dependencies(CURRENT_PLATFORM):
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...')
check_ghostscript(CURRENT_PLATFORM)
check_fimo()
check_bedtools()
check_samtools()
def copy_data(CURRENT_PLATFORM):
#coping data in place
d_path = lambda x: (x,os.path.join(INSTALLATION_PATH,x))
s_path=lambda x: os.path.join(INSTALLATION_PATH,x)
copy_tree(*d_path('genomes'))
copy_tree(*d_path('gene_annotations'))
copy_tree(*d_path('motif_databases'))
copy_tree(*d_path('extra'))
if CURRENT_PLATFORM=='Linux':
src='precompiled_binary/Linux/'
elif CURRENT_PLATFORM=='Darwin':
src='precompiled_binary/Darwin/'
dest=BIN_FOLDER
src_files = os.listdir(src)
for file_name in src_files:
full_file_name = os.path.join(src, file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, dest)
#fix permission so people can write in haystack dep folders
sb.call('chmod -R 777 %s' % os.path.join(INSTALLATION_PATH,'genomes'),shell=True)
sb.call('chmod -R 777 %s' % os.path.join(INSTALLATION_PATH,'gene_annotations'),shell=True)
sb.call('chmod -R 777 %s' % os.path.join(INSTALLATION_PATH,'motif_databases'),shell=True)
#COPY current env for subprocess
os.environ['PATH']=('%s:' % BIN_FOLDER) +os.environ['PATH'] #here the order is important
os.environ['HAYSTACK_DEPENDENCIES_PATH']=INSTALLATION_PATH
system_env=os.environ
cp.dump(system_env,open(os.path.join('haystack','system_env.pickle'),'w+'))
if __name__ == '__main__':
if sys.argv[1]=='install':
CURRENT_PLATFORM=platform.system().split('_')[0]
sys.stdout.write ('\n\nInstalling dependencies...')
install_dependencies(CURRENT_PLATFORM)
copy_data(CURRENT_PLATFORM)
sys.stdout.write ('\nInstalling Python package installed')
main()
if sys.argv[1]=='install':
sys.stdout.write ('\n\nINSTALLATION COMPLETED, open a NEW terminal and enjoy HAYSTACK!' )