-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·168 lines (153 loc) · 6.89 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
#!/usr/bin/env python3
import subprocess
import pkg_resources
import os
import stat
import sys
import pickle
from zipfile import ZipFile
import urllib.request
import shutil
def install_python_packages(): #check for required python packages; installs if absent
required = {"shyaml","pyyaml","pandas","numpy",
"matplotlib","seaborn","multiqc",
"cutadapt","scipy","scikit-learn",
"tqdm","gseapy","matplotlib-venn"}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if missing:
python = sys.executable
print("Installing missing required Python3 packages")
try:
install_command=[python, '-m', 'pip', 'install', *missing]
subprocess.check_call(install_command, stdout=subprocess.DEVNULL)
except:
sys.exit("ERROR: package installation failed, check log")
else:
print("All required Python3 packages already installed")
def install_fastqc(script_dir,fastqc_dir):
exe_dict=pickle.load(open(os.path.join(script_dir,".exe_dict.obj"),"rb"))
if not "fastqc" in exe_dict:
url="https://www.bioinformatics.babraham.ac.uk/projects/fastqc/fastqc_v0.11.9.zip"
download_file=os.path.join(script_dir,"fastqc_v0.11.9.zip")
print("Installing FastQC to "+script_dir)
urllib.request.urlretrieve(url,download_file)
#unzip FastQC file
with ZipFile(download_file, 'r') as zip_ref:
zip_ref.extractall(script_dir)
#add FastQC directory to exe_dict
exe_dict["fastqc"]=fastqc_dir
#save exe_dict to file
try:
pickle.dump(exe_dict, file=open(os.path.join(script_dir,".exe_dict.obj"),"wb"))
except pickle.PicklingError:
print("Storing of FastQC dir to dictionary with dependency locations failed")
#chmod +x fastqc
fastqc_file=os.path.join(fastqc_dir,"fastqc")
st = os.stat(fastqc_file)
os.chmod(fastqc_file, st.st_mode | stat.S_IEXEC)
#remove download file
os.remove(download_file)
else:
print("FastQC already installed")
return(None)
def install_mageck(script_dir,mageck_dir):
exe_dict=pickle.load(open(os.path.join(script_dir,".exe_dict.obj"),"rb"))
if not "mageck" in exe_dict:
url="https://sourceforge.net/projects/mageck/files/0.5/mageck-0.5.9.4.tar.gz/download"
download_file=os.path.join(script_dir,"mageck-0.5.9.4.tar.gz")
print("Installing MAGeCK to "+script_dir)
urllib.request.urlretrieve(url,download_file)
#unpack MAGeCK file
tar_command="tar -xzf "+ download_file
subprocess.run(tar_command,shell=True)
curr_dir=os.getcwd()
os.chdir(os.path.join(script_dir,"mageck-0.5.9.4"))
mageck_install_command="python3 "+os.path.join(script_dir,"mageck-0.5.9.4","setup.py"+" install --user")
subprocess.run(mageck_install_command,shell=True)
os.chdir(curr_dir)
#add MAGeCK directory to exe_dict
exe_dict["mageck"]=mageck_dir
#save exe_dict to file
try:
pickle.dump(exe_dict, file=open(os.path.join(script_dir,".exe_dict.obj"),"wb"))
except pickle.PicklingError:
print("Storing of MAGeCK dir to dictionary with dependency locations failed")
#remove download file and folder
os.remove(download_file)
shutil.rmtree(os.path.join(script_dir,"mageck-0.5.9.4"))
else:
print("MAGeCK already installed")
return(None)
def install_bowtie2(script_dir):
exe_dict=pickle.load(open(os.path.join(script_dir,".exe_dict.obj"),"rb"))
if not "bowtie2" in exe_dict:
if sys.platform in ["linux","linux2"]:
url="https://sourceforge.net/projects/bowtie-bio/files/bowtie2/2.4.3/bowtie2-2.4.3-linux-x86_64.zip/download"
download_file=os.path.join(script_dir,"bowtie2-2.4.3-linux-x86_64.zip")
bowtie2_dir=os.path.join(script_dir,"bowtie2-2.4.3-linux-x86_64")
elif sys.platform == "darwin":
url="https://sourceforge.net/projects/bowtie-bio/files/bowtie2/2.4.3/bowtie2-2.4.3-macos-x86_64.zip/download"
download_file=os.path.join(script_dir,"bowtie2-2.4.3-macos-x86_64.zip")
bowtie2_dir=os.path.join(script_dir,"bowtie2-2.4.3-macos-x86_64")
print("Installing Bowtie2 to"+script_dir)
urllib.request.urlretrieve(url,download_file)
#unzip Bowtie2 file
unzip_command="unzip -qq "+download_file+" -d "+script_dir
subprocess.run(unzip_command,shell=True)
#add Bowtie directory to exe_dict
exe_dict["bowtie2"]=bowtie2_dir
#save exe_dict to file
try:
pickle.dump(exe_dict, file=open(os.path.join(script_dir,".exe_dict.obj"),"wb"))
except pickle.PicklingError:
print("Storing of Bowtie2 dir to dictionary with dependency locations failed")
#remove download file
os.remove(download_file)
else:
print("Bowtie2 already installed")
return(None)
def install_bagel2(script_dir,bagel2_dir):
exe_dict=pickle.load(open(os.path.join(script_dir,".exe_dict.obj"),"rb"))
if not "bagel2" in exe_dict:
print("Installing BAGEL2 to "+script_dir)
clone_command="git "+"clone --quiet "+"https://github.com/hart-lab/bagel.git "+os.path.join(script_dir,"bagel2")
subprocess.run(clone_command, shell=True)
#add Bowtie directory to exe_dict
exe_dict["bagel2"]=bagel2_dir
#save exe_dict to file
try:
pickle.dump(exe_dict, file=open(os.path.join(script_dir,".exe_dict.obj"),"wb"))
except pickle.PicklingError:
print("Storing of BAGEL2 dir to dictionary with dependency locations failed")
else:
print("BAGEL2 already installed")
return(None)
def install_GSEA(script_dir):
pass
def install_R_packages():
install_command="Rscript "+os.path.join(script_dir,"R","install_R_packages.R")
subprocess.run(install_command,shell=True)
def check_env(script_dir,work_dir):
fastqc_dir=os.path.join(script_dir,"FastQC")
mageck_dir=os.path.join(script_dir,"mageck-0.5.9.4","bin")
bagel2_dir=os.path.join(script_dir,"bagel2")
#create dictionary for storing paths and save to file
exe_dict=dict()
exe_dict_file=os.path.join(script_dir,".exe_dict.obj")
try:
pickle.dump(exe_dict, file=open(exe_dict_file,"wb"))
except pickle.PicklingError:
print("Storing of dictionary with dependency locations failed")
#download dependencies and store path to exe_dict
install_fastqc(script_dir,fastqc_dir)
install_mageck(script_dir,mageck_dir)
install_bowtie2(script_dir)
install_bagel2(script_dir,bagel2_dir)
print("Installation finished")
if __name__ == "__main__":
work_dir=os.getcwd()
script_dir=os.path.abspath(os.path.dirname(__file__))
install_python_packages()
install_R_packages()
check_env(script_dir,work_dir)