-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
180 lines (158 loc) · 5.84 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
from pyd.support import setup, Extension
import itertools
import distutils.ccompiler
from distutils.command.clean import clean
import subprocess
import glob
import sys
import os
import shutil
projName = 'recontig'
htslibVersion = "1.13"
# default htslib path is local
htslibLocalPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),"htslib-{}".format(htslibVersion))
retcode = subprocess.call(["bash","version.sh"])
if retcode != 0:
raise Exception("could not pre-generate source/recontig/_version.d")
SHARED_EXT = ".so"
if sys.platform == "darwin":
SHARED_EXT = ".dylib"
# download htslib from github
def getHtslib():
sys.stdout.flush()
try:
retcode = subprocess.call(
["curl", "https://github.com/samtools/htslib/releases/download/{v}/htslib-{v}.tar.bz2".format(v=htslibVersion),"-o","htslib-{v}.tar.bz2".format(v=htslibVersion)]
)
if retcode != 0:
return False
else:
return True
except OSError as e:
return False
# untar and decompress htslib package
def unpackHtslib():
sys.stdout.flush()
try:
retcode = subprocess.call(
["tar", "-xjf","htslib-{}.tar.bz2".format(htslibVersion)],
)
if retcode != 0:
return False
else:
return True
except OSError as e:
return False
# run configure
def runConfigure(option):
sys.stdout.flush()
try:
retcode = subprocess.call(
" ".join(("./configure", option)),
shell=True,cwd=htslibLocalPath)
if retcode != 0:
return False
else:
return True
except OSError as e:
return False
# run make
def runMake():
sys.stdout.flush()
try:
retcode = subprocess.call(
["make"],
cwd=htslibLocalPath)
if retcode != 0:
return False
else:
return True
except OSError as e:
return False
# download and build htslib
def buildHtslib():
# is downloaded?
if not os.path.exists(htslibLocalPath):
if not getHtslib():
raise Exception("Could not download htslib")
if not unpackHtslib():
raise Exception("Could not unpack htslib")
# is built?
elif checkForHtslibSharedLibraries(htslibLocalPath):
if not runConfigure(option=""):
raise Exception("Could not run htslib configure")
if not runMake():
raise Exception("Could not run htslib make")
# check for htslib shared library files
def checkForHtslibSharedLibraries(dir):
# check for libhts.dylib or libhts.so
if not os.path.exists(os.path.join(dir,"libhts" + SHARED_EXT)):
print(os.path.join(dir,"libhts" + SHARED_EXT))
return False
# check for libhts.3.dylib
if not os.path.exists(os.path.join(dir,"libhts" + ".3" + SHARED_EXT)):
# check for libhts.so.3
if not os.path.exists(os.path.join(dir,"libhts" + SHARED_EXT + ".3")):
sys.stderr.write("Installed htslib is too out of date (needed version >= 1.10)\n")
return False
return True
# get HTSLIB_DIR env var
HTSLIB_DIR = os.environ.get("HTSLIB_DIR",None)
# Find htslib under /usr/local/lib
# or specify it with HTSLIB_DIR env var
# or download and build it
def resolveHtslib():
if HTSLIB_DIR:
if not checkForHtslibSharedLibraries(HTSLIB_DIR):
raise Exception("No htslib usable shared library in HTSLIB_DIR")
else:
return os.path.abspath(HTSLIB_DIR)
elif checkForHtslibSharedLibraries("/usr/local/lib/"):
return "/usr/local/lib/"
else:
sys.stderr.write("Downloading and building htslib {}\n".format(htslibVersion))
buildHtslib()
if not checkForHtslibSharedLibraries(htslibLocalPath):
raise Exception("Something went wrong during the build process: no shared library files")
return htslibLocalPath
class MyCleaner(clean):
# cleans up htslib install
# then runs normal clean
def run(self):
if os.path.exists(htslibLocalPath):
shutil.rmtree(htslibLocalPath)
if os.path.exists("htslib-{v}.tar.bz2".format(v=htslibVersion)):
os.remove("htslib-{v}.tar.bz2".format(v=htslibVersion))
super().run()
htslib_shared_path = resolveHtslib()
recontigSources = glob.glob(os.path.join("source","recontig","*.d")) + \
glob.glob(os.path.join("source","recontig","mapping","*.d"))
dhtslibSources = glob.glob(os.path.join("dhtslib","source","dhtslib","*.d")) + \
glob.glob(os.path.join("dhtslib","source","dhtslib", "bed","*.d")) + \
glob.glob(os.path.join("dhtslib","source","dhtslib", "gff","*.d")) + \
glob.glob(os.path.join("dhtslib","source","dhtslib", "sam","*.d")) + \
glob.glob(os.path.join("dhtslib","source","dhtslib", "vcf","*.d")) + \
glob.glob(os.path.join("dhtslib","source","htslib","*.d")) + \
glob.glob(os.path.join("dhtslib","coordinates","source","dhtslib","coordinates","package.d"))
options = {
# "extra_compile_args" : ['-w','-L-lhts'],
"build_deimos" : True,
"d_lump" : True,
"libraries" : ["hts"],
"library_dirs" :[htslib_shared_path],
"version_flags" :["usepyd"]
}
setup(
name=projName,
version='1.1.1',
platforms=["POSIX", "UNIX", "MacOS"],
# packages=['htslib-{}'.format(htslibVersion)],
# package_data={'htslib-{}'.format(htslibVersion): ['htslib-{}/libhts.so'.format(htslibVersion)]},
ext_modules=[
Extension(projName, recontigSources + dhtslibSources,
**options
),
],
cmdclass={"clean": MyCleaner},
requires=["pyd","pandas"]
)