Skip to content

Commit

Permalink
added support for installation in a Python virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
egaffo committed Jun 17, 2020
1 parent 014beaa commit 2d4af22
Showing 1 changed file with 108 additions and 72 deletions.
180 changes: 108 additions & 72 deletions src/ccp_install_tools.scons
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
import os
import os, sys

def SymLink(target, source, env):
os.symlink(os.path.abspath(str(source[0])), os.path.abspath(str(target[0])))

env = Environment(ENV=os.environ, SHELL = '/bin/bash')
tools_dir = os.path.join(env['ENV']['CIRCOMPARA_HOME'], 'tools')
ccp_bin_dir = os.path.join(env['ENV']['CIRCOMPARA_HOME'], 'bin')
python_lib_dir = os.path.join(tools_dir, 'lib', 'python2.7','site-packages')

#env.PrependENVPath('PYTHONUSERBASE', tools_dir)
env.PrependENVPath('PYTHONUSERBASE', tools_dir)
#env.PrependENVPath('PATH', os.path.join(tools_dir, 'bin'))

PYTHON_VERSION = str(sys.version_info.major) + '.' + str(sys.version_info.minor)

python_lib_dir = os.path.join(tools_dir, 'lib', 'python'+PYTHON_VERSION,'site-packages')
SET_PIP_USER = '--user'

## initialize VIRTUAL_ENV
if not env['ENV'].has_key('VIRTUAL_ENV'):
env['ENV']['VIRTUAL_ENV'] = ''

## pip does not work with --user if run inside a virtualenv
if env['ENV']['VIRTUAL_ENV']:
print 'Running in virtualenv. Python packages will be installed in the virtualenv directories'
SET_PIP_USER = ''
python_lib_dir = os.path.join(env['ENV']['VIRTUAL_ENV'], 'lib',
'python' + PYTHON_VERSION, 'site-packages')
else:
env.PrependENVPath('PYTHONUSERBASE', tools_dir)

env.PrependENVPath('PYTHONPATH', python_lib_dir)

## PIP
pip_file = 'get-pip.py'
pip_url = 'https://bootstrap.pypa.io/' + pip_file
pip_targets = [os.path.join(tools_dir, pip_file),
os.path.join(tools_dir, 'bin', 'pip')]
pip_cmd = ' && '.join(['wget -O ${TARGETS[0]} ' + pip_url,
'python ${TARGETS[0]} --user pip==20.1.1'])
pip = env.Command(pip_targets,
[],
pip_cmd)

## use virtualenv pip if run inside virtualenv
if env['ENV']['VIRTUAL_ENV']:
pip_targets = os.path.join(env['ENV']['VIRTUAL_ENV'], 'bin', 'pip2')
pip = env.Command(os.path.join(ccp_bin_dir, 'pip'), pip_targets, SymLink)
else:
pip_file = 'get-pip.py'
pip_url = 'https://bootstrap.pypa.io/' + pip_file
pip_targets = [os.path.join(tools_dir, pip_file),
os.path.join(tools_dir, 'bin', 'pip')]
pip_cmd = ' && '.join(['wget -O ${TARGETS[0]} ' + pip_url,
'python ${TARGETS[0]} ' + SET_PIP_USER + ' pip==20.1.1'])
pip = env.Command(pip_targets,
[],
pip_cmd)
pip = env.Command(os.path.join(ccp_bin_dir, 'pip'), pip[1], SymLink)

# BIOPYTHON
## N.B: if the virtualenv is not a subdirectory of circompara (installation),
## i.e. not under the Scons directory scope, then the installation could miss
## the targets in the virtualenv directories
BIOPYTHON_dir = os.path.join(python_lib_dir, 'Bio')
BIOPYTHON_target = [os.path.join(BIOPYTHON_dir, 'SeqIO', 'FastaIO.py')]
BIOPYTHON = env.Command(BIOPYTHON_target, [pip],
['pip install --ignore-installed --user -Iv biopython==1.76'])
['pip install --ignore-installed ' + SET_PIP_USER + ' -Iv biopython==1.76'])

## CYTHON
#cython_dir = os.path.join(python_lib_dir, 'cython')
if env['ENV']['VIRTUAL_ENV']:
cython_target = [os.path.join(env['ENV']['VIRTUAL_ENV'], 'bin', 'cython')]
else:
cython_target = [os.path.join(tools_dir, 'bin', 'cython')]
cython_cmd = 'pip install ' + SET_PIP_USER + ' Cython==0.29.19 --install-option="--no-cython-compile"'
cython = env.Command(cython_target,
[pip],
cython_cmd)


# PYSAM
## freeze pysam to v0.15.4 since
Expand All @@ -39,38 +76,35 @@ PYSAM = env.Command(PYSAM_target, [pip],
['pip install --ignore-installed --user -Iv pysam==0.15.4'])


## CYTHON
#cython_dir = os.path.join(python_lib_dir, 'cython')
cython_target = [os.path.join(tools_dir, 'bin', 'cython')]
cython_cmd = 'pip install --user Cython==0.29.19 --ignore-installed --install-option="--no-cython-compile"'
cython = env.Command(cython_target,
[pip],
cython_cmd)

# HTSeq
#HTSeq_dir = os.path.join(tools_dir, 'HTSeq')
HTSeq_dir = os.path.join(python_lib_dir, 'HTSeq')
#HTSeq_target = [os.path.join(HTSeq_dir, 'lib','python2.7','site-packages',
# 'HTSeq', '__init__.py'),
HTSeq_target = [os.path.join(HTSeq_dir, '__init__.py'),
os.path.join(tools_dir, 'bin', 'htseq-count')]
HTSeq = env.Command(HTSeq_target, [pip],
HTSeq_target = [os.path.join(HTSeq_dir, '__init__.py')]
if env['ENV']['VIRTUAL_ENV']:
HTSeq_target.append(os.path.join(env['ENV']['VIRTUAL_ENV'], 'bin', 'htseq-count'))
else:
HTSeq_target.append(os.path.join(tools_dir, 'bin', 'htseq-count'))
HTSeq = env.Command(HTSeq_target, [pip, cython],
#['pip install --ignore-installed --install-option="--prefix=' +\
#os.path.abspath(HTSeq_dir) +\
#'" HTSeq'])
['pip install --ignore-installed --user -Iv HTSeq==0.12.3'])
['pip install --ignore-installed ' + SET_PIP_USER + ' -Iv HTSeq==0.12.3'])
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), HTSeq[1], SymLink)

# CIRCEXPLORER2
#CIRCEXPLORER2_dir = os.path.join(tools_dir, 'CIRCexplorer2')
CIRCEXPLORER2_dir = os.path.join(python_lib_dir, 'circ2')
CIRCEXPLORER2_target = [os.path.join(tools_dir, 'bin', 'CIRCexplorer2')]#,
# os.path.join(CIRCEXPLORER2_dir, 'bin', 'fast_circ.py')]
#CIRCEXPLORER2_dir = os.path.join(python_lib_dir, 'circ2')
if env['ENV']['VIRTUAL_ENV']:
CIRCEXPLORER2_target = [os.path.join(env['ENV']['VIRTUAL_ENV'], 'bin', 'CIRCexplorer2')]#,
else:
CIRCEXPLORER2_target = [os.path.join(tools_dir, 'bin', 'CIRCexplorer2')]#,
CIRCEXPLORER2 = env.Command(CIRCEXPLORER2_target, [pip, HTSeq, PYSAM],
#['pip install --install-option="--prefix=' +\
#os.path.abspath(CIRCEXPLORER2_dir) +\
#'" -Iv circexplorer2==2.3.3'])
['pip install --ignore-installed --user -Iv circexplorer2==2.3.8'])
['pip install --ignore-installed ' + SET_PIP_USER + ' -Iv circexplorer2==2.3.8'])
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), CIRCEXPLORER2[0], SymLink)
#env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), CIRCEXPLORER2[1], SymLink)

Expand All @@ -87,23 +121,25 @@ env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), CIRCEXPLORER2[0], SymLi
pandas_dir = os.path.join(python_lib_dir, 'pandas')
pandas = env.Command([os.path.join(pandas_dir, '__init__.py')],
[pip, HTSeq],
"pip install --ignore-installed --user pandas")
'pip install --ignore-installed ' + SET_PIP_USER + ' pandas')

#dcc_dir = os.path.join(python_lib_dir, 'DCC-0.4.6')
dcc_dir = os.path.join(tools_dir, 'DCC-0.4.6')
dcc_tar = 'v0.4.6.tar.gz'
dcc_url = 'https://github.com/dieterich-lab/DCC/archive/' + dcc_tar
dcc_target = [os.path.join(tools_dir, dcc_tar),
os.path.join(tools_dir, 'bin', 'DCC'),
#os.path.join(dcc_python_sitepkg, "site.py")]
os.path.join(python_lib_dir, 'DCC-0.4.6-py2.7.egg')]
dcc_target = [os.path.join(tools_dir, dcc_tar)]
if env['ENV']['VIRTUAL_ENV']:
dcc_target.append(os.path.join(env['ENV']['VIRTUAL_ENV'], 'bin', 'DCC'))
else:
dcc_target.append(os.path.join(tools_dir, 'bin', 'DCC'))
dcc_target.append(os.path.join(python_lib_dir, 'DCC-0.4.6-py'+ PYTHON_VERSION +'.egg'))
dcc = env.Command(dcc_target,
[pandas],
['wget -O ${TARGETS[0]} ' + dcc_url,
'tar -xzf ${TARGETS[0]} -C ${TARGETS[0].dir}',
'cd ' + dcc_dir +\
#' && python setup.py install --prefix ' + dcc_dir,
' && python setup.py install --user',
' && python setup.py install ' + SET_PIP_USER + '',
'cd ' + Dir('#').abspath]
)

Expand Down Expand Up @@ -285,38 +321,38 @@ FINDCIRC = env.Command(FINDCIRC_target, [], ['wget -O $TARGET ' + FINDCIRC_link
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), FINDCIRC[1], SymLink)
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), FINDCIRC[2], SymLink)

# FASTX-TOOLKIT
libgtextutils_tar = 'libgtextutils-0.7.tar.gz'
libgtextutils_link = 'https://github.com/agordon/libgtextutils/releases/download/0.7/' +\
libgtextutils_tar
libgtextutils_dir = os.path.join(tools_dir, 'libgtextutils-0.7')
libgtextutils_target = [os.path.join(tools_dir, libgtextutils_tar),
os.path.join(libgtextutils_dir, 'lib', 'libgtextutils.so'),
os.path.join(libgtextutils_dir, 'lib', 'pkgconfig', 'gtextutils.pc')]
libgtextutils = env.Command(libgtextutils_target, [],
['wget -O $TARGET ' + libgtextutils_link,
'tar -xf ${TARGETS[0]} -C ${TARGETS[0].dir}',
'cd ' + libgtextutils_dir + ' && ./configure --prefix=`pwd`'\
' && make && make install',
'cd ' + Dir('#').abspath])

libgtextutils_config_path = os.path.dirname(libgtextutils[2].abspath)

FASTXTOOLKIT_tar = 'fastx_toolkit-0.0.14.tar.bz2'
FASTXTOOLKIT_link = 'https://github.com/agordon/fastx_toolkit/releases/download/0.0.14/' +\
FASTXTOOLKIT_tar
FASTXTOOLKIT_dir = os.path.join(tools_dir, 'fastx_toolkit-0.0.14')
FASTXTOOLKIT_target = [os.path.join(tools_dir, FASTXTOOLKIT_tar),
os.path.join(FASTXTOOLKIT_dir, 'bin', 'fastx_quality_stats')]
FASTXTOOLKIT = env.Command(FASTXTOOLKIT_target, [Value(libgtextutils_config_path), libgtextutils[2]],
['wget -O $TARGET ' + FASTXTOOLKIT_link,
'tar -xf ${TARGETS[0]} -C ${TARGETS[0].dir}',
'cd ' + FASTXTOOLKIT_dir + ' && ./configure --prefix=' +\
FASTXTOOLKIT_dir + ' PKG_CONFIG_PATH=${SOURCES[0]}'\
':$$PKG_CONFIG_PATH '\
' && make && make install',
'cd ' + Dir('#').abspath])
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), FASTXTOOLKIT[1], SymLink)
## FASTX-TOOLKIT
#libgtextutils_tar = 'libgtextutils-0.7.tar.gz'
#libgtextutils_link = 'https://github.com/agordon/libgtextutils/releases/download/0.7/' +\
# libgtextutils_tar
#libgtextutils_dir = os.path.join(tools_dir, 'libgtextutils-0.7')
#libgtextutils_target = [os.path.join(tools_dir, libgtextutils_tar),
# os.path.join(libgtextutils_dir, 'lib', 'libgtextutils.so'),
# os.path.join(libgtextutils_dir, 'lib', 'pkgconfig', 'gtextutils.pc')]
#libgtextutils = env.Command(libgtextutils_target, [],
# ['wget -O $TARGET ' + libgtextutils_link,
# 'tar -xf ${TARGETS[0]} -C ${TARGETS[0].dir}',
# 'cd ' + libgtextutils_dir + ' && ./configure --prefix=`pwd`'\
# ' && make && make install',
# 'cd ' + Dir('#').abspath])
#
#libgtextutils_config_path = os.path.dirname(libgtextutils[2].abspath)
#
#FASTXTOOLKIT_tar = 'fastx_toolkit-0.0.14.tar.bz2'
#FASTXTOOLKIT_link = 'https://github.com/agordon/fastx_toolkit/releases/download/0.0.14/' +\
# FASTXTOOLKIT_tar
#FASTXTOOLKIT_dir = os.path.join(tools_dir, 'fastx_toolkit-0.0.14')
#FASTXTOOLKIT_target = [os.path.join(tools_dir, FASTXTOOLKIT_tar),
# os.path.join(FASTXTOOLKIT_dir, 'bin', 'fastx_quality_stats')]
#FASTXTOOLKIT = env.Command(FASTXTOOLKIT_target, [Value(libgtextutils_config_path), libgtextutils[2]],
# ['wget -O $TARGET ' + FASTXTOOLKIT_link,
# 'tar -xf ${TARGETS[0]} -C ${TARGETS[0].dir}',
# 'cd ' + FASTXTOOLKIT_dir + ' && ./configure --prefix=' +\
# FASTXTOOLKIT_dir + ' PKG_CONFIG_PATH=${SOURCES[0]}'\
# ':$$PKG_CONFIG_PATH '\
# ' && make && make install',
# 'cd ' + Dir('#').abspath])
#env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), FASTXTOOLKIT[1], SymLink)

# gtfToGenePred
gtfToGenePred_link = 'http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/gtfToGenePred'
Expand Down Expand Up @@ -376,8 +412,8 @@ tophat2 = env.Command(tophat2_target,
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), tophat2[1], SymLink)

# STRINGTIE
stringtie_dir = 'stringtie-2.0.3.Linux_x86_64'
stringtie_tar = 'stringtie-2.0.3.Linux_x86_64.tar.gz'
stringtie_dir = 'stringtie-2.1.1.Linux_x86_64'
stringtie_tar = 'stringtie-2.1.1.Linux_x86_64.tar.gz'
stringtie_url = 'http://ccb.jhu.edu/software/stringtie/dl/' + stringtie_tar
stringtie_target = [os.path.join(tools_dir, stringtie_tar),
os.path.join(tools_dir, stringtie_dir, 'stringtie')]
Expand Down Expand Up @@ -420,7 +456,7 @@ cfinder = env.Command(cfinder_target,
[],
['wget -O ${TARGETS[0]} ' + cfinder_url,
'tar -xzf ${TARGETS[0]} -C ${TARGETS[0].dir}'])
for t in cfinder:
for t in cfinder[1:]:
env.Command(os.path.join(ccp_bin_dir, "${SOURCE.file}"), t, SymLink)

# SAMTOOLS <v1.0 is required by circrna_finder
Expand Down

0 comments on commit 2d4af22

Please sign in to comment.