def main(argv): parser = OptionParser(usage="usage: %prog [options]", version="%prog 0.1a") parser.add_option("-a", "--app", dest = "app", help = "The application to build. Required.") parser.add_option("-t", "--task", dest = "task", default = 'default', help = "The task(s) that need(s) to be run. Optional. \ Comma separate to run multiple tasks. Default: `%default`") parser.add_option("-p", "--path", dest = "path", default = '.', help = "Conche root path. Default: Current Working Directory. Optional. Default: `%default`") (options, args) = parser.parse_args() if len(args): parser.error("Unexpected arguments encountered.") if not options.app: parser.error("You must specify an application.") path = options.path if path == ".": path = os.getcwdu() cnf = Conf(path) cnf.run_task(options.app, options.task) if argv == []: print parser.format_option_help()
def main(): global ALIGNER,ADAPTER,TRIM,GENOME,PARA_MAP usage = "usage: autopipeline.pl [arguments]\n\ \nOptional arguments: --help print help message --man print complete\ documentation --aligner Aligner (default : BWA). User can specify BWA,\ BOWTIE, TOPHAT or ALL to do alignment using all alingers. --adapter\ Remove adapters from raw reads. --trim Trim low quality reads. --genome\ Input reference genome with full path.\n\ sampleSheet.txt has to be in working directory." parser = OptionParser(usage) parser.add_option("--aligner",dest="aligner",default="BWA",help="Aligner to\ align sequencing reads to refrence sequences. \n\ The default aligner is BWA but user can specify BOWTIE and internally it \ will use BOWTIE 2, TOPHAT or choose ALL. \nIf no parameter are specified \ after prompt, the pipeline uses specified aligner with all default\ settings.") parser.add_option("--man",dest="man",action="store_true",default=False,help="Print complete manual of the program") parser.add_option("--adapter",dest="adapter",default="yes",help="Remove \ adapters from raw reads and perform quality control check on the resulting reads. \ \nThe default option is 'yes' but user can specify 'no' to skip this step. \ \nIf this parameter is set as yes, the pipeline will remove adaptors from raw \ reads and generate report after performing quality check.") parser.add_option("--trim",dest="trim",default="yes",help="Trim the low quality reads. \ \nThe default option is 'yes' but user can specify 'no' to skip this step. \ \nIf this parameter is set as yes, the pipeline will remove the low quality \ reads and generate report after performing quality check.") parser.add_option("--genome",dest="genome",default="./genome/RefGenome.fa",help="Reference genomepathway and file name. \ \nThe default option is './genome/RefGenome.fa'. This is a mandatory option. \ \nYou have to give pipepline the correct reference genome path and file name.") parser.add_option("--para_map",dest="para_map",default="",help="parameters for mapping. \ \nThe default options is alinger defualt. This is an optional option.") (options, args) = parser.parse_args() ALIGNER=options.aligner ADAPTER=options.adapter TRIM=options.trim GENOME=options.genome PARA_MAP=options.para_map if options.man: print("SYNOPSIS:autopipeline.pl [arguments]\n\ \nOptional arguments: --help print help message --man print complete\ documentation --aligner Aligner (default : BWA). User can specify BWA,\ BOWTIE, TOPHAT or ALL to do alignment using all alingers. --adapter\ Remove adapters from raw reads. --trim Trim low quality reads. --genome\ Input reference genome with full path. sampleSheet.txt has to be in working\ directory.\n") print(parser.format_option_help()) parser.exit()
def format_option_help(self, formatter = None): if formatter is None: formatter = self.formatter help_sections = [ OptionParser.format_option_help(self, formatter = formatter)] for group in self.groups: old_parser = formatter.parser formatter.set_parser(self.groups[group]) try: help_sections.append( self.groups[group].format_option_help(formatter = formatter)) finally: formatter.set_parser(old_parser) return '\n'.join(help_sections)
def format_option_help(self, formatter=None): if formatter is None: formatter = self.formatter help_sections = [ OptionParser.format_option_help(self, formatter=formatter) ] for group in self.groups: old_parser = formatter.parser formatter.set_parser(self.groups[group]) try: help_sections.append( self.groups[group].format_option_help(formatter=formatter)) finally: formatter.set_parser(old_parser) return '\n'.join(help_sections)
def main(argv): parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 0.4") parser.add_option("-s", "--sitepath", dest = "site_path", help = "Change the path of the site folder.") parser.add_option("-i", "--init", action = 'store_true', dest = "init", default = False, help = "Create a new hyde site.") parser.add_option("-f", "--force", action = 'store_true', dest = "force_init", default = False, help = "") parser.add_option("-t", "--template", dest = "template", help = "Choose which template you want to use.") parser.add_option("-g", "--generate", action = "store_true", dest = "generate", default = False, help = "Generate the source for your hyde site.") parser.add_option("-k", "--keep_watching", action = "store_true", dest = "keep_watching", default = False, help = "Start monitoring the source folder for changes.") parser.add_option("-d", "--deploy_to", dest = "deploy_to", help = "Change the path of the deploy folder.") parser.add_option("-w", "--webserve", action = "store_true", dest = "webserve", default = False, help = "Start an instance of the CherryPy webserver.") parser.add_option("-p", "--port", dest = "port", default=8080, type='int', help = "Port webserver should listen on (8080).") parser.add_option("-a", "--address", dest = "address", default='localhost', help = "Address webserver should listen on (localhost).") (options, args) = parser.parse_args() if len(args): parser.error("Unexpected arguments encountered.") if not options.site_path: options.site_path = os.getcwdu() if options.deploy_to: options.deploy_to = os.path.abspath(options.deploy_to) if options.init: initializer = Initializer(options.site_path) initializer.initialize(PROG_ROOT, options.template, options.force_init) generator = None server = None def quit(*args, **kwargs): if server and server.alive: server.quit() if generator: generator.quit() if options.generate: generator = Generator(options.site_path) generator.generate(options.deploy_to, options.keep_watching, quit) if options.webserve: server = Server(options.site_path, address=options.address, port=options.port) server.serve(options.deploy_to, quit) if ((options.generate and options.keep_watching) or options.webserve): try: print "Letting the server and/or the generator do their thing..." if server: server.block() if generator: generator.quit() elif generator: generator.block() except: print sys.exc_info() quit() if argv == []: print parser.format_option_help()
def format_option_help(self, formatter=None): if not formatter: formatter = self.formatter return '%s\n%s' % (formatter.format_commands( self.commands), OptionParser.format_option_help(self, formatter))
class Command(object): """generic help string for any command""" # class variables cmd = [] cmd_dict = {} def commands_string(): s = '' list = [x.name[0] for x in Command.cmd] list.sort() for x in list: s += x + '\n' return s commands_string = staticmethod(commands_string) def get_command(cmd, fail=False): if Command.cmd_dict.has_key(cmd): return Command.cmd_dict[cmd]() if fail: print "Unrecognized command: ", cmd sys.exit(1) else: return None get_command = staticmethod(get_command) # instance variabes def __init__(self): # now for the real parser import pisi self.parser = OptionParser(usage=getattr(self, "__doc__"), version="%prog " + pisi.__version__) self.options() self.commonopts() (self.options, self.args) = self.parser.parse_args() self.args.pop(0) # exclude command arg self.check_auth_info() def commonopts(self): '''common options''' p = self.parser p.add_option("-D", "--destdir", action="store") p.add_option("", "--yes-all", action="store_true", default=False, help = "assume yes in all yes/no queries") p.add_option("-u", "--username", action="store") p.add_option("-p", "--password", action="store") p.add_option("-P", action="store_true", dest="getpass", default=False, help="Get password from the command line") p.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="detailed output") p.add_option("-d", "--debug", action="store_true", default=True, help="show debugging information") p.add_option("-n", "--dry-run", action="store_true", default=False, help = "do not perform any action, just show what\ would be done") return p def options(self): """This is a fall back function. If the implementer module provides an options function it will be called""" pass def check_auth_info(self): username = self.options.username password = self.options.password # TODO: We'll get the username, password pair from a configuration # file from users home directory. Currently we need user to # give it from the user interface. # if not username and not password: # if someauthconfig.username and someauthconfig.password: # self.authInfo = (someauthconfig.username, # someauthconfig.password) # return if username and password: self.authInfo = (username, password) return if username and self.options.getpass: from getpass import getpass password = getpass("Password: "******"""initialize PiSi components""" # NB: command imports here or in the command class run fxns import pisi.api pisi.api.init(database, self.options) def finalize(self): """do cleanup work for PiSi components""" pass def get_name(self): return self.__class__.name def format_name(self): (name, shortname) = self.get_name() if shortname: return "%s (%s)" % (name, shortname) else: return name def help(self): """print help for the command""" ctx.ui.info(self.format_name() + ': ') print getattr(self, "__doc__") print self.parser.format_option_help() def die(self): """exit program""" print 'Program terminated abnormally.' sys.exit(-1)
class Command(object): """generic help string for any command""" # class variables cmd = [] cmd_dict = {} @staticmethod def commands_string(): s = '' list = [x.name[0] for x in Command.cmd] list.sort() for name in list: commandcls = Command.cmd_dict[name] trans = gettext.translation('pisi', fallback=True) summary = trans.ugettext(commandcls.__doc__).split('\n')[0] name = commandcls.name[0] if commandcls.name[1]: name += ' (%s)' % commandcls.name[1] s += '%21s - %s\n' % (name, summary) return s @staticmethod def get_command(cmd, fail=False, args=None): if Command.cmd_dict.has_key(cmd): return Command.cmd_dict[cmd](args) if fail: raise Error(_("Unrecognized command: %s") % cmd) else: return None # instance variabes def __init__(self, args=None): # now for the real parser import pisi self.comar = False self.parser = OptionParser(usage=getattr(self, "__doc__"), version="%prog " + pisi.__version__) self.options() self.commonopts() (self.options, self.args) = self.parser.parse_args(args) if self.args: self.args.pop(0) # exclude command arg self.process_opts() def commonopts(self): '''common options''' p = self.parser p.add_option("-D", "--destdir", action="store", default=None, help=_("change the system root for pisi commands")) p.add_option("-y", "--yes-all", action="store_true", default=False, help=_("assume yes in all yes/no queries")) p.add_option("-u", "--username", action="store") p.add_option("-p", "--password", action="store") p.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help=_("detailed output")) p.add_option("-d", "--debug", action="store_true", default=False, help=_("show debugging information")) p.add_option("-N", "--no-color", action="store_true", default=False, help=_("print like a man")) p.add_option("-L", "--bandwidth-limit", action="store", default=0, help=_("Keep bandwidth usage under specified KB's")) return p def options(self): """This is a fall back function. If the implementer module provides an options function it will be called""" pass def process_opts(self): self.check_auth_info() # make destdir absolute if self.options.destdir: dir = str(self.options.destdir) import os.path if not os.path.exists(dir): pisi.cli.printu( _('Destination directory %s does not exist. Creating directory.\n' ) % dir) os.makedirs(dir) self.options.destdir = os.path.realpath(dir) def check_auth_info(self): username = self.options.username password = self.options.password # TODO: We'll get the username, password pair from a configuration # file from users home directory. Currently we need user to # give it from the user interface. # if not username and not password: # if someauthconfig.username and someauthconfig.password: # self.authInfo = (someauthconfig.username, # someauthconfig.password) # return if username and password: self.options.authinfo = (username, password) return if username and not password: from getpass import getpass password = getpass(_("Password: "******"""initialize PiSi components""" # NB: command imports here or in the command class run fxns import pisi.api pisi.api.init(database=database, write=write, options=self.options, comar=self.comar) def finalize(self): """do cleanup work for PiSi components""" pisi.api.finalize() def get_name(self): return self.__class__.name def format_name(self): (name, shortname) = self.get_name() if shortname: return "%s (%s)" % (name, shortname) else: return name def help(self): """print help for the command""" print self.format_name() + ': ' trans = gettext.translation('pisi', fallback=True) print trans.ugettext(self.__doc__) + '\n' print self.parser.format_option_help() def die(self): """exit program""" #FIXME: not called from anywhere? ctx.ui.error(_('Command terminated abnormally.')) sys.exit(-1)
def main(): # 配置命令行参数 parser = OptionParser(version='%prog V1.0') parser.add_option("-t", "--type", action="store", type="string", dest="type", default="translate", help="TYPE: train/eval/translate") if len(sys.argv) > 1 and sys.argv[1] not in ['-t']: print('Error:no option ' + sys.argv[1]) print(parser.format_option_help()) (options, args) = parser.parse_args() if options.type == 'train': # 加载句子 en, ch = _pre.load_sentences(_config.path_to_train_file, _config.num_sentences) # 预处理句子 en = _pre.preprocess_sentences_en(en, mode=_config.en_tokenize_type) ch = _pre.preprocess_sentences_ch(ch, mode=_config.ch_tokenize_type) # 生成及保存字典 tokenizer_en, vocab_size_en = _pre.create_tokenizer( sentences=en, mode=_config.en_tokenize_type, save_path=_config.en_bpe_tokenizer_path) tokenizer_ch, vocab_size_ch = _pre.create_tokenizer( sentences=ch, mode=_config.ch_tokenize_type, save_path=_config.ch_tokenizer_path) print('vocab_size_en:%d' % vocab_size_en) print('vocab_size_ch:%d' % vocab_size_ch) # 编码句子 tensor_en, max_sequence_length_en = _pre.encode_sentences( sentences=en, tokenizer=tokenizer_en, mode=_config.en_tokenize_type) tensor_ch, max_sequence_length_ch = _pre.encode_sentences( sentences=ch, tokenizer=tokenizer_ch, mode=_config.ch_tokenize_type) # 创建模型及相关变量 optimizer, train_loss, train_accuracy, transformer = network.get_model( vocab_size_en, vocab_size_ch) # 开始训练 trainer.train(tensor_en, tensor_ch, transformer, optimizer, train_loss, train_accuracy) elif options.type == 'eval' or options.type == 'translate': if_ckpt = _pre.check_point() # 检测是否有检查点 if if_ckpt: # 加载中英文字典 tokenizer_en, vocab_size_en = _pre.get_tokenizer( path=_config.en_bpe_tokenizer_path, mode=_config.en_tokenize_type) tokenizer_ch, vocab_size_ch = _pre.get_tokenizer( path=_config.ch_tokenizer_path, mode=_config.ch_tokenize_type) print('vocab_size_en:%d' % vocab_size_en) print('vocab_size_ch:%d' % vocab_size_ch) # 创建模型及相关变量 optimizer, _, _, transformer = network.get_model( vocab_size_en, vocab_size_ch) # 加载检查点 network.load_checkpoint(transformer, optimizer) if options.type == 'eval': # 评估模式 print('-' * 30) print('可选择评价指标: 1.bleu指标 0.退出程序') eval_mode = input('请输入选择指标的序号:') if eval_mode == '1': eval.calc_bleu(_config.path_to_eval_file, transformer, tokenizer_en, tokenizer_ch) elif eval_mode == '0': print('感谢您的体验!') else: print('请输入正确序号') elif options.type == 'translate': # 翻译模式 while True: print('-' * 30) print('输入0可退出程序') sentence = input('请输入要翻译的句子 :') if sentence == '0': break else: print( '翻译结果:', translator.translate(sentence, transformer, tokenizer_en, tokenizer_ch)) else: print('请先训练才可使用其它功能...') elif len(sys.argv) > 2: print('Error:no TYPE ' + sys.argv[2]) print(parser.format_option_help())
class Command(object): """generic help string for any command""" # class variables cmd = [] cmd_dict = {} @staticmethod def commands_string(): s = '' list = [x.name[0] for x in Command.cmd] list.sort() for name in list: commandcls = Command.cmd_dict[name] trans = gettext.translation('pisi', fallback=True) summary = trans.ugettext(commandcls.__doc__).split('\n')[0] name = commandcls.name[0] if commandcls.name[1]: name += ' (%s)' % commandcls.name[1] s += '%21s - %s\n' % (name, summary) return s @staticmethod def get_command(cmd, fail=False, args=None): if Command.cmd_dict.has_key(cmd): return Command.cmd_dict[cmd](args) if fail: raise Error(_("Unrecognized command: %s") % cmd) else: return None # instance variabes def __init__(self, args = None): # now for the real parser import pisi self.comar = False self.parser = OptionParser(usage=getattr(self, "__doc__"), version="%prog " + pisi.__version__) self.options() self.commonopts() (self.options, self.args) = self.parser.parse_args(args) if self.args: self.args.pop(0) # exclude command arg self.process_opts() def commonopts(self): '''common options''' p = self.parser p.add_option("-D", "--destdir", action="store", default = None, help = _("change the system root for pisi commands")) p.add_option("-y", "--yes-all", action="store_true", default=False, help = _("assume yes in all yes/no queries")) p.add_option("-u", "--username", action="store") p.add_option("-p", "--password", action="store") p.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help=_("detailed output")) p.add_option("-d", "--debug", action="store_true", default=False, help=_("show debugging information")) p.add_option("-N", "--no-color", action="store_true", default=False, help = _("print like a man")) return p def options(self): """This is a fall back function. If the implementer module provides an options function it will be called""" pass def process_opts(self): self.check_auth_info() # make destdir absolute if self.options.destdir: dir = str(self.options.destdir) import os.path if not os.path.exists(dir): pisi.cli.printu(_('Destination directory %s does not exist. Creating directory.\n') % dir) os.makedirs(dir) self.options.destdir = os.path.realpath(dir) def check_auth_info(self): username = self.options.username password = self.options.password # TODO: We'll get the username, password pair from a configuration # file from users home directory. Currently we need user to # give it from the user interface. # if not username and not password: # if someauthconfig.username and someauthconfig.password: # self.authInfo = (someauthconfig.username, # someauthconfig.password) # return if username and password: self.options.authinfo = (username, password) return if username and not password: from getpass import getpass password = getpass(_("Password: "******"""initialize PiSi components""" # NB: command imports here or in the command class run fxns import pisi.api pisi.api.init(database = database, write = write, options = self.options, comar = self.comar) def finalize(self): """do cleanup work for PiSi components""" pisi.api.finalize() def get_name(self): return self.__class__.name def format_name(self): (name, shortname) = self.get_name() if shortname: return "%s (%s)" % (name, shortname) else: return name def help(self): """print help for the command""" print self.format_name() + ': ' trans = gettext.translation('pisi', fallback=True) print trans.ugettext(self.__doc__) + '\n' print self.parser.format_option_help() def die(self): """exit program""" #FIXME: not called from anywhere? ctx.ui.error(_('Command terminated abnormally.')) sys.exit(-1)
def format_option_help(self, formatter=None): """ Only report on the generic form of an argument, so to avoid repetition of the help string for a given argument set configured self.add_multi_option. """ # Go through the options list, adding the generic form of each to a # a list which will be consulted when displaying help output self.generic_arguments.append('--help') self.generic_arguments.append('--version') trimmed_options = [] for option in self.option_list: optstring = option.get_opt_string() # Store the automatic --help and --version options if optstring == '--version' or optstring == '--help': trimmed_options.append(option) continue # Construct generic form of the argument name generic_form = re.sub('[0-9]+$', '', optstring) if generic_form in self.generic_arguments: option.dest = re.sub('[0-9]+$', '', option.dest) # Store a generic form of the argument string, substituting an # N for an any trailing integer value, e.g. --ss1 -> --ssN for i in range(0, len(option._long_opts)): long_opt = option._long_opts[i] option._long_opts[i] = re.sub('[0-9]+$', 'N', long_opt) trimmed_options.append(option) self.generic_arguments.remove(generic_form) self.option_list = trimmed_options # Run parent class format_option_help method help_string = BasicOptionParser.format_option_help(self, formatter) # Now split the array into lines and locate the first option describing # a stream. Insert a label before that line, and append additional help # info the end of the array, then merge the array of lines back into a # string and return it. help_array = help_string.split('\n') str_label = "Streams, N in range 1-%d: " % self.ARGUMENT_LIMIT for i in range(0, len(help_array)): if re.search('--stN=', help_array[i]): help_array.insert(i, '\n' + str_label) break # Strip redundant arguments from help string. For example, the # help string --stN=ST becomes --st= # Store the index to the "Streams" help info as we'll be inserting # additional help info *before* this point firstI = -1 streamStrings = [] for i in range(0, len(help_array)): if re.search('stN=ST', help_array[i]): help_array[i] = re.sub('stN=ST\s*', 'stN= ', help_array[i]) if firstI < 0: firstI = i - 1 # Insert operator help strings into correct location operatorlist = list(OPERATORHELP) operatorlist.reverse() for help in operatorlist: help_array.insert(firstI, help) help_array.insert(firstI, '') # Add final blank line and return help_array.append('') return '\n'.join(help_array)
import dhcpdmanip import os usage = """\ python %prog [action] [options] action: add, remove, getleases, getreserved """ if __name__ == "__main__": parser = OptionParser() parser.add_option("-m", "--mac", action="store", dest="mac", help="mac address (12 hexadigits)") parser.add_option("-i", "--ip", action="store", dest="ip", help="IP address (x.x.x.x)") parser.add_option("-H", "--host", action="store", dest="name", help="host name") parser.add_option("-d", "--desc", action="store", dest="desc", help="host description") parser.set_usage(usage + parser.format_option_help()) (options, args) = parser.parse_args() if len(args) != 1: parser.error("wrong argument count. Action required.") logging.basicConfig(level=logging.INFO) action = args[0] manipulator = dhcpdmanip.Manipulator() def _render(): backfile = manipulator._dhcpd_conf_file + ".manip.back" os.rename(manipulator._dhcpd_conf_file, backfile) manipulator.render()
def main(argv): parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 0.4") parser.add_option("-s", "--sitepath", dest="site_path", help="Change the path of the site folder.") parser.add_option("-i", "--init", action='store_true', dest="init", default=False, help="Create a new hyde site.") parser.add_option("-f", "--force", action='store_true', dest="force_init", default=False, help="") parser.add_option("-t", "--template", dest="template", help="Choose which template you want to use.") parser.add_option("-g", "--generate", action="store_true", dest="generate", default=False, help="Generate the source for your hyde site.") parser.add_option("-k", "--keep_watching", action="store_true", dest="keep_watching", default=False, help="Start monitoring the source folder for changes.") parser.add_option("-d", "--deploy_to", dest="deploy_to", help="Change the path of the deploy folder.") parser.add_option("-w", "--webserve", action="store_true", dest="webserve", default=False, help="Start an instance of the CherryPy webserver.") parser.add_option("-p", "--port", dest="port", default=8080, type='int', help="Port webserver should listen on (8080).") parser.add_option("-a", "--address", dest="address", default='localhost', help="Address webserver should listen on (localhost).") (options, args) = parser.parse_args() if len(args): parser.error("Unexpected arguments encountered.") if not options.site_path: options.site_path = os.getcwdu() if options.deploy_to: options.deploy_to = os.path.abspath(options.deploy_to) if options.init: initializer = Initializer(options.site_path) initializer.initialize(PROG_ROOT, options.template, options.force_init) generator = None server = None def quit(*args, **kwargs): if server and server.alive: server.quit() if generator: generator.quit() if options.generate: generator = Generator(options.site_path) generator.generate(options.deploy_to, options.keep_watching, quit) if options.webserve: server = Server(options.site_path, address=options.address, port=options.port) server.serve(options.deploy_to, quit) if ((options.generate and options.keep_watching) or options.webserve): try: print "Letting the server and/or the generator do their thing..." if server: server.block() if generator: generator.quit() elif generator: generator.block() except: print sys.exc_info() quit() if argv == []: print parser.format_option_help()
) parser.add_option( '-H', '--host', action='store', dest='name', help='host name', ) parser.add_option( '-d', '--desc', action='store', dest='desc', help='host description', ) parser.set_usage(usage + parser.format_option_help()) (options, args) = parser.parse_args() if len(args) != 1: parser.error('wrong argument count. Action required.') logging.basicConfig(level=logging.INFO) action = args[0] manipulator = dhcpdmanip.Manipulator() def _render(): backfile = manipulator._dhcpd_conf_file + '.manip.back' os.rename(manipulator._dhcpd_conf_file, backfile) manipulator.render()
from optparse import OptionParser import keras import numpy from datasets import load_data_train from keras import backend as K import os # training script of s2s usage = 'USAGE: %python train_s2s.py model_outdir' parser = OptionParser(usage=usage) opts, args = parser.parse_args() if len(args) != 1: parser.usage += '\n\n' + parser.format_option_help() parser.error('Wrong number of arguments') model_dir = args[0] train_dataset = load_data_train() train_ip = train_dataset['calcium signal padded'] train_op = train_dataset['Gaussian spikes train'] inputFeatDim = train_ip.shape[1] def correlation_coefficient_loss(y_true, y_pred): x = y_true y = y_pred mx = K.mean(x, axis=1, keepdims=True) my = K.mean(y, axis=1, keepdims=True)
help="y maximum [default: %default]") parser.add_option("--no-title",dest="dotitle",action="store_false", default=True, help="do not draw axis title") parser.add_option("--no-raxis",dest="do_raxis",action="store_false",default=True) parser.add_option("--no-display",dest="doplot",action="store_false", default=True, help="do not actually draw") parser.add_option("--maxDiff",dest="maxDiff",default=8.0, help="Maximum allowed mass difference in groupped particles [GeV/c^2]") (options, args) = parser.parse_args() # Check arguments if options.input == None: parser.error('Input file is missing\n'+parser.format_option_help()) # Set some global variables verbose = options.verbose masses = dict() # Set input/output file names if options.output==None: options.output = re.sub(r'\..*$','.eps',options.input) if options.output.find('.eps') == -1: options.output += '.eps' print "Will store result in ", options.output scanFile(options.input,options.vars,masses) if verbose:
def format_option_help(self, formatter): rv = OptionParser.format_option_help(self, formatter) extra_help = self.__ctx.command._format_extra_help(self.__ctx) if extra_help: rv = '%s\n\n%s' % (extra_help, rv) return rv
def format_option_help(self, formatter=None): """ Only report on the generic form of an argument, so to avoid repetition of the help string for a given argument set configured self.add_multi_option. """ # Go through the options list, adding the generic form of each to a # a list which will be consulted when displaying help output self.generic_arguments.append('--help') self.generic_arguments.append('--version') trimmed_options = [] for option in self.option_list: optstring = option.get_opt_string() # Store the automatic --help and --version options if optstring == '--version' or optstring == '--help': trimmed_options.append(option) continue # Construct generic form of the argument name generic_form = re.sub('[0-9]+$', '', optstring) if generic_form in self.generic_arguments: option.dest = re.sub('[0-9]+$', '', option.dest) # Store a generic form of the argument string, substituting an # N for an any trailing integer value, e.g. --ss1 -> --ssN for i in range(0,len(option._long_opts)): long_opt = option._long_opts[i] option._long_opts[i] = re.sub('[0-9]+$', 'N', long_opt) trimmed_options.append(option) self.generic_arguments.remove(generic_form) self.option_list = trimmed_options # Run parent class format_option_help method help_string = BasicOptionParser.format_option_help(self, formatter) # Now split the array into lines and locate the first option describing # a stream. Insert a label before that line, and append additional help # info the end of the array, then merge the array of lines back into a # string and return it. help_array = help_string.split('\n') str_label = "Streams, N in range 1-%d: " % self.ARGUMENT_LIMIT for i in range(0, len(help_array)): if re.search('--stN=', help_array[i]): help_array.insert(i, '\n' + str_label) break # Strip redundant arguments from help string. For example, the # help string --stN=ST becomes --st= # Store the index to the "Streams" help info as we'll be inserting # additional help info *before* this point firstI = -1 streamStrings = [] for i in range(0, len(help_array)): if re.search('stN=ST', help_array[i]): help_array[i] = re.sub('stN=ST\s*', 'stN= ', help_array[i]) if firstI < 0: firstI = i-1 # Insert operator help strings into correct location operatorlist = list(OPERATORHELP) operatorlist.reverse() for help in operatorlist: help_array.insert(firstI, help) help_array.insert(firstI, '') # Add final blank line and return help_array.append('') return '\n'.join(help_array)
def format_option_help(self, formatter=None): if not formatter: formatter = self.formatter return '%s\n%s' % (formatter.format_commands(self.commands), OptionParser.format_option_help(self, formatter))