Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mimic legacy BLAST's formatdb to execute BLAST+ makeblastdb command: Legacy BLAST の formatdb のふりをして makeblastdb を実行する
#!/usr/bin/env python
# coding: utf-8
"""Mimic legacy BLAST's formatdb to execute BLAST+ makeblastdb command
"""
import argparse, os, sys
def main():
sys.stderr.write('>>>>> %s\n' %(' '.join(sys.argv)))
parser = argparse.ArgumentParser()
simple_options_map = [
('i', 'in'),
('t', 'title'),
('l', 'logfile'),
('v', 'max_file_size'),
('n', 'out'),
('T', 'taxid_map'),
]
flag_options_map = [
('o', 'hash_index'),
]
special_options_map = [
('p', 'dbtype'),
('a', 'asn1_input'),
('b', 'asn1_binary'),
]
undefined = ['s', 'L', 'F', 'B', 'V', 'e']
for opt, dest in simple_options_map:
parser.add_argument('-'+opt, dest=dest)
for opt, dest in flag_options_map:
parser.add_argument('-'+opt, dest=dest, nargs='?', const=True, default=False)
#special options
parser.add_argument('-e', dest='seq_entry_input')
parser.add_argument('-p', dest='dbtype')
parser.add_argument('-a', dest='asn1_input')
parser.add_argument('-b', dest='asn1_binary')
args = parser.parse_args()
# selection of program
program = 'makeblastdb'
cmdline_args = [program]
# simple argument conversion
for opt, dest in simple_options_map:
arg = getattr(args, dest, None)
if not (arg==None):
if False: # arg.split()>1:
arg.strip('"').strip("'") # unquote
arg = '"%s"' %arg # requote
cmdline_args.extend(['-'+dest, arg])
# flag conversion
for opt, dest in flag_options_map:
arg = getattr(args, dest, None)
if arg==True:
cmdline_args.append('-'+dest)
# special conversion
dbtype = getattr(args, 'dbtype')
dbtype_val = 'prot'
if dbtype=='F':
dbtype_val = 'nucl'
cmdline_args.extend(['-dbtype', dbtype_val])
input_type='fasta'
if getattr(args, 'asn1_input', None)=='T':
input_type='asn1_txt'
elif getattr(args, 'asn1_binary', None)=='T':
input_type='asn1_bin'
if input_type != 'fasta':
cmdline_args.extend(['-input_type', input_type])
sys.stderr.write('>>>>> %s\n' %(' '.join(cmdline_args)))
os.execvp(program, cmdline_args)
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.