| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
""" |
| 4 |
Copyright 2014, Daehwan Kim <[email protected]> |
| 5 |
|
| 6 |
This file is part of Centrifuge, which is copied and modified from bowtie2-inspect in the Bowtie2 package. |
| 7 |
|
| 8 |
Centrifuge 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 |
Centrifuge 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 Centrifuge. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
""" |
| 21 |
|
| 22 |
import sys |
| 23 |
import os |
| 24 |
#import imp |
| 25 |
import inspect |
| 26 |
import logging |
| 27 |
|
| 28 |
def build_args(): |
| 29 |
""" |
| 30 |
Parse the wrapper arguments. Returns the options,<programm arguments> tuple. |
| 31 |
""" |
| 32 |
|
| 33 |
parsed_args = {} |
| 34 |
to_remove = [] |
| 35 |
argv = sys.argv[:] |
| 36 |
for i, arg in enumerate(argv): |
| 37 |
if arg == '--debug': |
| 38 |
parsed_args[arg] = "" |
| 39 |
to_remove.append(i) |
| 40 |
elif arg == '--verbose': |
| 41 |
parsed_args[arg] = "" |
| 42 |
to_remove.append(i) |
| 43 |
|
| 44 |
for i in reversed(to_remove): |
| 45 |
del argv[i] |
| 46 |
|
| 47 |
return parsed_args, argv |
| 48 |
|
| 49 |
|
| 50 |
def main(): |
| 51 |
logging.basicConfig(level=logging.ERROR, |
| 52 |
format='%(levelname)s: %(message)s' |
| 53 |
) |
| 54 |
inspect_bin_name = "centrifuge-inspect" |
| 55 |
curr_script = os.path.realpath(inspect.getsourcefile(main)) |
| 56 |
ex_path = os.path.dirname(curr_script) |
| 57 |
inspect_bin_spec = os.path.join(ex_path, "centrifuge-inspect-bin") |
| 58 |
#bld = imp.load_source('centrifuge-build', os.path.join(ex_path,'centrifuge-build')) |
| 59 |
options,arguments = build_args() |
| 60 |
|
| 61 |
if '--verbose' in options: |
| 62 |
logging.getLogger().setLevel(logging.INFO) |
| 63 |
|
| 64 |
if '--debug' in options: |
| 65 |
inspect_bin_spec += '-debug' |
| 66 |
|
| 67 |
arguments[0] = inspect_bin_name |
| 68 |
arguments.insert(1, 'basic-0') |
| 69 |
arguments.insert(1, '--wrapper') |
| 70 |
logging.info('Command: %s %s' % (inspect_bin_spec,' '.join(arguments[1:]))) |
| 71 |
os.execv(inspect_bin_spec, arguments) |
| 72 |
|
| 73 |
|
| 74 |
if __name__ == "__main__": |
| 75 |
main() |