This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_IOGA.py
128 lines (117 loc) · 3.86 KB
/
setup_IOGA.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
#!/usr/bin/python
import glob
import sys
import json
import wget
import os
import shutil
from subprocess import Popen,PIPE
import gzip
import contextlib
dependencies = { 'samtools':{'source':'http://sourceforge.net/projects/samtools/files/samtools/0.1.19/samtools-0.1.19.tar.bz2',
'target':'IOGA_samtools.tbz',
'dir':'samtools-0.1.19',
'unpack':'tar -xjf IOGA_samtools.tbz',
'install':'make',
'exe':'samtools'},
'bbmap.sh':{'source':'http://downloads.sourceforge.net/project/bbmap/BBMap_33.89_java7.tar.gz',
'target':'IOGA_bbmap.tgz',
'dir':'bbmap',
'unpack':'tar -xzf IOGA_bbmap.tgz',
'install':'',
'exe':'bbmap.sh'},
'SOAPdenovo-127mer':{ 'source':'http://downloads.sourceforge.net/project/soapdenovo2/SOAPdenovo2/bin/r240/SOAPdenovo2-bin-LINUX-generic-r240.tgz',
'target':'IOGA_SOAPdenovo.tgz',
'dir':'SOAPdenovo2-bin-LINUX-generic-r240',
'unpack':'tar -xzf IOGA_SOAPdenovo.tgz',
'install':'',
'exe':'SOAPdenovo-127mer'},
'seqtk':{ 'source':'https://github.com/lh3/seqtk/archive/master.zip',
'target':'IOGA_seqtk.zip',
'dir':'seqtk-master',
'unpack':'unzip IOGA_seqtk.zip',
'install':'make',
'exe':'seqtk'},
'picard.jar':{ 'source':'https://github.com/broadinstitute/picard/releases/download/1.124/picard-tools-1.124.zip',
'target':'IOGA_picard.zip',
'dir':'picard-tools-1.124',
'unpack':'unzip IOGA_picard.zip',
'install':'chmod +x picard.jar',
'exe':'picard.jar'},
'ALE':{ 'source':'https://github.com/sc932/ALE/archive/master.zip',
'target':'IOGA_ALE.zip',
'dir':'ALE-master',
'unpack':'unzip IOGA_ALE.zip',
'install':'make',
'exe':'src/ALE'},
'spades.py':{ 'source':'http://cab.spbu.ru/files/release3.1.1/SPAdes-3.1.1-Linux.tar.gz',
'target':'IOGA_SPAdes.tgz',
'dir':'SPAdes-3.1.1-Linux',
'unpack':'tar -xzf IOGA_SPAdes.tgz',
'install':'',
'exe':'bin/spades.py'}
}
def main():
"""
Download dependencies for IOGA.py
"""
config = {}
failed = []
try:
os.mkdir('exe')
except OSError:
shutil.rmtree('exe')
os.mkdir('exe')
original = os.getcwd()
os.chdir('exe')
curdir = os.getcwd()
for dep in dependencies:
print dep
source = dependencies[dep]['source']
target = dependencies[dep]['target']
directory = dependencies[dep]['dir']
unpack = dependencies[dep]['unpack']
install = dependencies[dep]['install']
exe = os.path.abspath('{0}/{1}'.format(directory,dependencies[dep]['exe']))
wget.download(source,out=target)
p = Popen(unpack.split(),stdout=PIPE,stderr=PIPE)
out,err = p.communicate()
if err:
print err
quit()
print
if install:
print install
os.chdir(directory)
p = Popen(install.split(),stdout=PIPE,stderr=PIPE)
out,err = p.communicate()
os.chdir(curdir)
try:
print 'trying {0}'.format(exe)
if dep == 'picard.jar':
e = 'java -jar {0}'.format(exe)
else:
e = exe
p = Popen(e.split(),stdout=PIPE,stderr=PIPE)
out,err = p.communicate()
print 'succes'
config[dep] = exe
except OSError:
print '{0} installation failed'.format(dep)
config[dep] = ''
failed.append(dep)
if dep == 'bbmap.sh':
config['bbduk.sh'] = exe.strip('bbmap.sh') + 'bbduk.sh'
os.chdir(original)
with contextlib.closing(gzip.open('exe/bbmap/alladapters.fa.gz','wb')) as outfile:
for f in glob.glob('exe/bbmap/resources/*fa.gz'):
with contextlib.closing(gzip.open(f,'rb')) as infile:
for line in infile:
outfile.write(line)
config['adapters'] = os.path.abspath('exe/bbmap/alladapters.fa.gz')
with open('IOGA_config.json','w') as fh:
json.dump(config,fh,indent=1)
for f in failed:
print '{0} failed, if you have installed it manually you can add it to the config'.format(f)
if __name__ == '__main__':
main()