-
Notifications
You must be signed in to change notification settings - Fork 0
/
yamlCreator.py
150 lines (126 loc) · 3.69 KB
/
yamlCreator.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
import yaml
import sys
import os
from shutil import copyfile
global arguments
arguments = {}
global assemblers
#This can be a file...
assemblers = ["bioboxes/velvet",
"bioboxes/megahit",
"bioboxes/sga",
"bioboxes/idba",
"bioboxes/minia",
"bioboxes/ray",
"bioboxes/sparse",
"bioboxes/soap"]
def yamlCreator():
#Valid yaml creation
data = dict(
version = "0.9.0",
arguments = [dict(
fastq = [dict(
id = arguments["id"],
type = (arguments["type"]),
value = "/bbx/input/reads.fq.gz"
)]
)]
)
yamlFile = open(arguments["yaml"], "w")
with yamlFile as f:
yaml.dump(data, f, default_flow_style=False)
def folderPath(folder):
#If startswith / indicating that the complete path is already given
if folder.startswith('/'):
if folder.endswith('/'):
return folder
else:
return folder.rsplit('/', 1)[0]
#Otherwise append the path of the script to the current folder location of the script
return os.path.dirname(os.path.realpath(__file__)) + folder
def runDocker():
output = open("docker.sh", "w")
#INPUT needs to be the folder...
bash = '''
docker run \
--volume="'''+arguments["fastq"]+''':/bbx/input/reads.fq.gz:ro" \
--volume="'''+arguments["yaml"]+''':/bbx/input/biobox.yaml:ro" \
--volume="'''+arguments["output"]+''':/bbx/output/:rw" \
--rm \
'''+arguments["assembler"]+''' \
default
'''
output.write(bash)
output.close()
command = "bash docker.sh"
print(command)
os.system(command)
def test():
arguments["testoutput"] = arguments["output"]
assemblers = ["bioboxes/velvet",
"bioboxes/megahit",
"bioboxes/sga",
"bioboxes/idba",
"bioboxes/minia",
"bioboxes/ray",
"bioboxes/sparse",
"bioboxes/soap"]
for assembler in assemblers:
arguments["assembler"] = assembler
arguments["output"] = arguments["testoutput"] + "/" + assembler
#IF output folder does not exist yet...
if not os.path.isdir(arguments["output"]):
os.makedirs(arguments["output"])
yamlCreator()
runDocker()
if __name__ == '__main__':
if "--fastq" not in sys.argv:
print("--fastq FASTQ required")
sys.exit()
else:
#Get complete path of input file
arguments["fastq"] = os.path.abspath(sys.argv[sys.argv.index("--fastq")+1])
if "--output" not in sys.argv:
print("--output folder required")
sys.exit()
else:
#Get complete path of output folder
arguments["output"] = os.path.abspath(sys.argv[sys.argv.index("--output")+1])
arguments["yaml"] = arguments["output"]+"/biobox.yaml"
#IF output folder does not exist yet...
if not os.path.isdir(arguments["output"]):
os.mkdir(arguments["output"])
if "--type" not in sys.argv:
print("--type paired/single required")
sys.exit()
else:
arguments["type"] = sys.argv[sys.argv.index("--type")+1]
if "--id" not in sys.argv:
print("--id required")
sys.exit()
else:
arguments["id"] = sys.argv[sys.argv.index("--id")+1]
if "--test" in sys.argv:
print("PERFORMING TESTS")
test()
# soap needs fragment size
sys.exit()
if "--assembler" not in sys.argv:
print "Use --assembler to select your assembler"
print "Currently supported assemblers:"
print '\n'.join(assemblers)
sys.exit()
else:
arguments["assembler"] = sys.argv[sys.argv.index("--assembler")+1]
if arguments["assembler"] not in assemblers and "--force" not in sys.argv:
print "Currently supported assemblers:"
print '\n'.join(assemblers)
print "To force your public docker use --force"
sys.exit()
yamlCreator()
runDocker()
#If the output fasta file is required to be moved to somewhere else -ofasta is used
if "--fasta" in sys.argv:
arguments["fasta"] = sys.argv[sys.argv.index("--fasta")+1]
import shutil
shutil.move(arguments["output"]+"/contig.fa", arguments["fasta"])