Debian Codegraph @

bowtie2-build

raw ◀ ▶
2 Debian patches touch this file
•1 #!/usr/bin/python3
2
3 """
4 Copyright 2014, Ben Langmead <[email protected]>
5
6 This file is part of Bowtie 2.
7
8 Bowtie 2 is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Bowtie 2 is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Bowtie 2. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 import os
23 import sys
24 import gzip
25 import inspect
26 import logging
27 import argparse
28 import platform
29 import subprocess
30
31
32 def get_gunzip_size(fn):
33 size = 0
34 with gzip.open(fn) as f:
35 while True:
36 data = f.read(8192)
37 size += len(data)
38 if not data:
39 break
40 return size
41
42 def sais_enabled(build_bin_spec):
43 output = subprocess.check_output([build_bin_spec, "--version"], universal_newlines=True)
44
45 return output.find("USE_SAIS") != -1
46
47 def main():
48 parser = argparse.ArgumentParser(add_help = False)
49
50 parser.add_argument('--large-index', action='store_true')
51 parser.add_argument('--verbose', action='store_true')
52
53 group = parser.add_mutually_exclusive_group()
54 group.add_argument('--debug', action='store_true')
55
56 logging.basicConfig(level=logging.ERROR,
57 format='%(levelname)s: %(message)s'
58 )
59 delta = 200
60 small_index_max_size= 4 * 1024**3 - delta
61 build_bin_name = 'bowtie2-build'
62 build_bin_s = 'bowtie2-build-s'
63 build_bin_l = 'bowtie2-build-l'
64 curr_script = os.path.realpath(inspect.getsourcefile(main))
65 ex_path = os.path.dirname(curr_script)
66 build_bin_spec = os.path.join(ex_path,build_bin_s)
67
68 if sais_enabled(build_bin_spec):
69 small_index_max_size = 2 * 1024 ** 3 - delta
70
71 script_options, argv = parser.parse_known_args()
72
73 if script_options.verbose:
74 logging.getLogger().setLevel(logging.INFO)
75
76 if script_options.debug:
77 build_bin_spec += "-debug"
78 build_bin_l += "-debug"
79
•80 # if script_options.sanitized:
81 # build_bin_spec += "-sanitized"
82 # build_bin_l += "-sanitized"
83
84 fastas = []
85 if "-c" not in argv and len(argv) >= 2:
86 for index in reversed(range(len(argv) - 1)):
87 arg = argv[index]
88 if arg.startswith("-") or arg.isdigit():
89 break
90 fastas.insert(0, arg)
91 argv.remove(arg)
92 if fastas:
93 fastas = ",".join(fastas)
94 argv.insert(len(argv) - 1, fastas)
95
96 if script_options.large_index:
97 build_bin_spec = os.path.join(ex_path, build_bin_l)
98 elif fastas:
99 tot_size = 0
100 for fn in fastas.split(","):
101 if os.path.exists(fn):
102 if fn.endswith(".gz"):
103 tot_size += get_gunzip_size(fn)
104 elif fn.endswith(".zst"):
105 sys.stderr.write(
106 "{} cannot determine the uncompressed size of ZSTD compressed files.\
107 Please make sure that the uncompressed file size is suitable for\
108 building the current index".format(
109 curr_script
110 )
111 )
112 else:
113 statinfo = os.stat(fn)
114 tot_size += statinfo.st_size
115 if tot_size > small_index_max_size:
116 build_bin_spec = os.path.join(ex_path, build_bin_l)
117
118 if "Windows" in platform.platform():
119 build_bin_spec += '.exe'
120
121 if not os.path.exists(build_bin_spec):
122 sys.stderr.write(
123 "{0} does not exist, try running `[g]make {0}'\n".format(
124 os.path.basename(build_bin_spec)
125 )
126 )
127 sys.exit(1)
128
129 argv.insert(0, "basic-0")
130 argv.insert(0, "--wrapper")
131 argv.insert(0, build_bin_spec)
132 logging.info("Command: %s" % " ".join(argv))
133 sys.exit(subprocess.call(argv))
134
135
136 if __name__ == "__main__":
137 main()