def main(argv=None): if argv is None: argv = sys.argv else: argv.extend(sys.argv) parser = ArgumentParser() parser.add_argument( 'imagespec', help="Container image tag, e.g. repository/imagename:version") parser.add_argument('--cleanup', default=False, help="Delete project hierarchy only. Do not scan") parser.add_argument( '--rescan-layer', default=0, type=int, help="Rescan specific layer in case of failure, 0 - scan as usual") args = parser.parse_args() print(args) hub = HubInstance() if args.cleanup: clean_container_project(args.imagespec) else: if args.rescan_layer == 0: clean_container_project(args.imagespec) scan_container_image(args.imagespec) else: scan_container_image(args.imagespec, args.rescan_layer)
def set_argument_value(self, name, value, scope=None): value = str(value) if scope: arg_name = "--{scope}_{name}".format(scope=scope, name=name) else: arg_name = "--{name}".format(name=name) sysargv.extend([arg_name, value])
def manage(): if len(argv) == 1: argv.extend(["runserver", "-r", "-d"]) manager = Manager(make_app( debug='-D' not in argv and '--no-debug' not in argv)) manager.add_command("runserver", Server(host="0.0.0.0", port=8080)) return manager.run()
def manage(): if len(argv) == 1: argv.extend(["runserver", "-r", "-d"]) manager = Manager(make_app( debug='-D' not in argv and '--no-debug' not in argv)) manager.add_command("runserver", Server(host="localhost", port=8080)) return manager.run()
def setup_environment(): """ Setup a temporary environment, returning the directory name. """ # A temporary directory which will be destoryed when the script exists dir = tempdir() # Create the environment argv[0] = 'pyols' argv.extend(['-c', dir]) try: cmdline.run() except SystemExit: pass return dir
def main(argv=None): if argv is None: argv = sys.argv else: argv.extend(sys.argv) parser = ArgumentParser() parser.add_argument( 'imagespec', help="Container image tag, e.g. repository/imagename:version") parser.add_argument( '--grouping', default=None, type=str, help= "Group layers into user defined provect versions (can't be used with --base-image)" ) parser.add_argument( '--base-image', default=None, type=str, help= "Use base image spec to determine base image/layers (can't be used with --grouping or --dockerfile)" ) parser.add_argument( '--dockerfile', default=None, type=str, help= "Use Dockerfile to determine base image/layers (can't be used with --grouping or ---base-image)" ) args = parser.parse_args() print(args) if not args.imagespec: parser.print_help(sys.stdout) sys.exit(1) if args.dockerfile and args.base_image: parser.print_help(sys.stdout) sys.exit(1) if args.grouping and (args.dockerfile and args.base_image): parser.print_help(sys.stdout) sys.exit(1) scan_container_image(args.imagespec, args.grouping, args.base_image, args.dockerfile)
def launch(module, includes ,files, out = None, multiple = None): import sys from sys import argv from copy import copy, deepcopy del argv[1:] argv.extend(default_defines) argv.extend(map(lambda include : '-I%s' % include, includes)) argv.append('--module=%s' % module) if out == None: out = module argv.append('--out=%s' % out) if multiple: argv.append('--multiple') argv_saved = copy(argv) argv.extend(files) print argv from os import system def makecmd(): import string return ('python -c "from Pyste import pyste; pyste.main()" ' + string.join(argv[1:], ' ')) system(makecmd()) argv = argv_saved if multiple: argv.append('--generate-main') argv.extend(files) print 'generating main' system(makecmd())
def launch(module, includes, files, out=None, multiple=None): import sys from sys import argv from copy import copy, deepcopy del argv[1:] argv.extend(default_defines) argv.extend(map(lambda include: '-I%s' % include, includes)) argv.append('--module=%s' % module) if out == None: out = module argv.append('--out=%s' % out) if multiple: argv.append('--multiple') argv_saved = copy(argv) argv.extend(files) print argv from os import system def makecmd(): import string return ('python -c "from Pyste import pyste; pyste.main()" ' + string.join(argv[1:], ' ')) system(makecmd()) argv = argv_saved if multiple: argv.append('--generate-main') argv.extend(files) print 'generating main' system(makecmd())
def main(argv=None): if argv is None: argv = sys.argv else: argv.extend(sys.argv) parser = ArgumentParser() parser.add_argument( 'imagespec', help="Container image tag, e.g. repository/imagename:version") parser.add_argument('--cleanup', default=False, help="Delete project hierarchy only. Do not scan") args = parser.parse_args() hub = HubInstance() clean_container_project(args.imagespec) if not args.cleanup: scan_container_image(args.imagespec)
# command line argument CMD_ARGS = ['build_ext', '--inplace'] # setup. from sys import argv argv.extend(CMD_ARGS) from distutils.core import setup from Cython.Build import cythonize setup( name = 'dijkstra', ext_modules = cythonize(['dijkstra1.pyx', 'dijkstra2.pyx']), ) print '\n%s Completed successfully!!!\n' % ('-' * 10) import test test.test()
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) try: program_shortdesc = __import__('__main__').__doc__.split("\n")[1] except: program_shortdesc = __import__('__main__').__doc__ program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-n", "--num-est", type=int, default=700, action='store', dest="nest", help="number of Random Forest estimators") parser.add_argument("-j", "--jobs", type=int, default=-1, action='store', dest="njobs", help="number of jobs") parser.add_argument("-f", "--cv-fold", type=int, default=5, action='store', dest="nfolds", help="number of cross-validation folds") parser.add_argument("--clf-params", type=str, default="{}", action='store', dest="clf_params", help="classifier parameters subset to override defaults") parser.add_argument("-G", "--cv-grid", type=str, default="{}", action='store', dest="cv_grid", help="cross-validation grid params (used if NFOLDS > 0)") parser.add_argument("-E", "--estimator", action='store', dest="estimator", default='XGBClassifier', type=str,# choices=['mean', 'median', 'most_frequent'], help="Estimator class to use") parser.add_argument("-H", "--hyperopt", action='store_true', dest="do_hyperopt", help="Do hyperopt exploration") # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work(args.estimator, args.nest, args.njobs, args.nfolds, eval(args.cv_grid), eval(args.clf_params), args.do_hyperopt) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise(e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) program_shortdesc = __import__('__main__').__doc__.split("\n")[1] program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout, stdin # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-i", "--in-hdf5-file", action='store', dest="in_h5", type=str, help="input HDF5 file with contest data") parser.add_argument("-n", "--num-est", type=int, default=50, action='store', dest="nest", help="number of Random Forest estimators") parser.add_argument("-j", "--jobs", type=int, default=2, action='store', dest="njobs", help="number of Random Forest jobs") parser.add_argument("-o", "--out-csv", action='store', dest="out_csv_file", default=stdout, type=FileType('w'), help="output CSV file name") """ parser.add_argument("--in-test-csv", action='store', dest="in_test_csv", default='test.csv', type=str, help="input CSV with test data zipped inside IN_TEST_ARCH") parser.add_argument("-o", "--out-h5", action='store', dest="out_h5", default='raw-data.h5', type=str, help="output HDF5 filename for data") """ # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work(args.in_h5, args.out_csv_file, args.nest, args.njobs) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise (e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
def __str__(self): return "RNN_{}-{}"\ .format(self.hidden_size, self.num_layers) #%% if __name__ == "__main__": from matching.utils.data_utils import open_file, confusion from sys import argv, platform if platform == "darwin": argv.extend(["abo", 1, 100, .5, np.random.randint(1e8)]) #if len(argv) > 1: print("Creating new RNN") env_type = argv[1] num_layers = int(argv[2]) hidden_size = int(argv[3]) c = float(argv[4]) s = str(argv[5]) input_size = {"abo": 24, "optn": 294} net = RNN(input_size=input_size[env_type], hidden_size=hidden_size, num_layers=num_layers, bidirectional=True, class_weights=[1, 100 * c])
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) try: program_shortdesc = __import__('__main__').__doc__.split("\n")[1] except: program_shortdesc = __import__('__main__').__doc__ program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-n", "--num-est", type=int, default=700, action='store', dest="nest", help="number of Random Forest estimators") parser.add_argument("-j", "--jobs", type=int, default=-1, action='store', dest="njobs", help="number of jobs") parser.add_argument("-f", "--cv-fold", type=int, default=0, action='store', dest="nfolds", help="number of cross-validation folds") parser.add_argument("--int-fold", type=int, default=6, action='store', dest="int_fold", help="internal fold for PrudentialRegressorCVO2FO") parser.add_argument("-b", "--n-buckets", type=int, default=8, action='store', dest="nbuckets", help="number of buckets for digitizer") parser.add_argument("-o", "--out-csv", action='store', dest="out_csv_file", default=stdout, type=FileType('w'), help="output CSV file name") parser.add_argument("-m", "--minimizer", action='store', dest="minimizer", default='BFGS', type=str, choices=['Powell', 'CG', 'BFGS'], help="minimizer method for scipy.optimize.minimize") parser.add_argument("-M", "--mvector", action='store', dest="mvector", default=[-1.5, -2.6, -3.6, -1.2, -0.8, 0.04, 0.7, 3.6], type=float, nargs='*', help="minimizer's initial params vector") parser.add_argument("-I", "--imputer", action='store', dest="imputer", default=None, type=str, choices=['mean', 'median', 'most_frequent'], help="Imputer strategy, None is -1") parser.add_argument("--clf-params", type=str, default="{}", action='store', dest="clf_params", help="classifier parameters subset to override defaults") parser.add_argument("-G", "--cv-grid", type=str, default="{}", action='store', dest="cv_grid", help="cross-validation grid params (used if NFOLDS > 0)") parser.add_argument("-E", "--estimator", action='store', dest="estimator", default='PrudentialRegressor', type=str,# choices=['mean', 'median', 'most_frequent'], help="Estimator class to use") # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work(args.out_csv_file, args.estimator, args.nest, args.njobs, args.nfolds, eval(args.cv_grid), args.minimizer, args.nbuckets, args.mvector, args.imputer, eval(args.clf_params), args.int_fold) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise(e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
from sys import argv user = raw_input("Write your user_name:") argv.extend([user]) script, user_name = argv prompt = '> ' print "Hi %s, I'm the %s script." % (user_name, script) print "I'd like to ask you a few questions?." print "Do you like me %s?" % user_name likes = raw_input(prompt) print "Where do you live %s?" % user_name lives = raw_input(prompt) print "What kind of computer do you have?" computer = raw_input(prompt) print """ Alright, so you said %r about liking me. You live in %r. Not sure where that is. And you have a %r computer. Nice. """ % (likes, lives, computer)
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) try: program_shortdesc = __import__('__main__').__doc__.split("\n")[1] except: program_shortdesc = __import__('__main__').__doc__ program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) # parser.add_argument("-n", "--num-est", # type=int, default=700, action='store', dest="nest", # help="number of Random Forest estimators") # # parser.add_argument("-j", "--jobs", # type=int, default=-1, action='store', dest="njobs", # help="number of jobs") # # parser.add_argument("-f", "--cv-fold", # type=int, default=5, action='store', dest="nfolds", # help="number of cross-validation folds") # # parser.add_argument("--clf-params", # type=str, default="{}", action='store', dest="clf_params", # help="classifier parameters subset to override defaults") # # parser.add_argument("-G", "--cv-grid", # type=str, default="{}", action='store', dest="cv_grid", # help="cross-validation grid params (used if NFOLDS > 0)") # # parser.add_argument("-E", "--estimator", # action='store', dest="estimator", default='XGBClassifier', # type=str,# choices=['mean', 'median', 'most_frequent'], # help="Estimator class to use") # # parser.add_argument("-H", "--hyperopt", # action='store_true', dest="do_hyperopt", # help="Do hyperopt exploration") # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work() return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise (e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
def __str__(self): return "RNN_{}-{}"\ .format(self.hidden_size, self.num_layers) #%% if __name__ == "__main__": from matching.utils.data_utils import open_file, confusion, confusion1d from sys import argv, platform if platform == "darwin": argv.extend(["abo", 3, 50, 1, np.random.randint(1e8)]) #if len(argv) > 1: print("Creating new RNN") env_type = argv[1] num_layers = int(argv[2]) hidden_size = int(argv[3]) c = float(argv[4]) s = str(argv[5]) input_size = {"abo": 24, "optn": 294} net = RNN(input_size=input_size[env_type], hidden_size=hidden_size, num_layers=num_layers, logit_class_weights=[1, 100 * c], count_class_weights=[1, 3])
from sys import argv entrada = raw_input("What is your name:") argv.extend(['first', 'second', 'third', entrada]) script, first, second, third, name = argv print "The script is called:", script print "Your first variable is:", first print "Your second variable is:", second print "Your third variable is:", third print "Your name is:", name
def __lt__(self, other): return self.latlon < other.latlon def __eq__(self, other): return self.latlon == other.latlon def __hash__(self): return hash(self.latlon) if __name__ == "__main__": from argparse import ArgumentParser from limic.util import set_option, parse_config from importlib import import_module from sys import argv import sys sys.path.append("../BP2_TSP/") if len(argv) == 1: argv.extend(["serve", "auto", "europe_denmark"]) parser = ArgumentParser(description="Powerlines as drone highways.") parse_config(CONFIG, parser, []) args = parser.parse_args() set_option('verbosity', args.verbosity) set_option('md5sum', not args.md5sum) set_option('overwrite', args.overwrite) set_option('parser', parser) module = import_module(args.mod) func = vars(module)[args.func] del args.verbosity, args.md5sum, args.overwrite, args.mod, args.func, args.command func(**vars(args))
from sys import argv from os.path import exists fileOne = 'test.txt' fileTwo = 'new_file.txt' argv.extend([fileOne, fileTwo]) script, from_file, to_file = argv in_file = open(from_file, 'w') text = raw_input("Write your text here:\n\t>>>") in_file.write(text) print "Copying from %s to %s" % (from_file, to_file) # We could do these two on one line too, how? in_file = open(from_file) indata = in_file.read() print "The input file is %d bytes long" % len(indata) print "Does the output file exist? %r" % exists(to_file) print "Ready, hit RETURN to continue, CTRL-C to abort." raw_input() out_file = open(to_file, 'w') out_file.write(indata) print "alright, all one" out_file.close() in_file.close()
def main(argv=None): if argv is None: argv = sys.argv else: argv.extend(sys.argv) parser = ArgumentParser() parser.add_argument( 'imagespec', help="Container image tag, e.g. repository/imagename:version") parser.add_argument('--cleanup', default=False, help="Delete project hierarchy only. Do not scan") parser.add_argument( '--rescan-layer', default=0, type=int, help="Rescan specific layer in case of failure, 0 - scan as usual") parser.add_argument( '--dockerfile', default=None, type=str, help= "Specify dockerfile used to build this container(experimantal), can't use with --base-image" ) parser.add_argument( '--base-image', default=None, type=str, help= "Specify base image used to build this container(experimantal), can't use with --dockerfile" ) parser.add_argument( '--omit-base-layers', default=False, type=bool, help="Omit base layer (requires --dockerfile or --base-image)") args = parser.parse_args() print(args) if not args.imagespec: parser.print_help(sys.stdout) sys.exit(1) if args.dockerfile and args.base_image: parser.print_help(sys.stdout) sys.exit(1) if args.omit_base_layers and not (args.dockerfile or args.base_image): parser.print_help(sys.stdout) sys.exit(1) if args.cleanup: clean_container_project(args.imagespec) sys.exit(1) if args.dockerfile or args.base_image: clean_container_project(args.imagespec) scan_container_image_with_dockerfile(args.imagespec, args.dockerfile, args.base_image, args.omit_base_layers) else: if args.rescan_layer == 0: clean_container_project(args.imagespec) scan_container_image(args.imagespec) else: scan_container_image(args.imagespec, args.rescan_layer)
from sys import argv # Define an varible with the name of archive archivo = 'ex15_sample.txt' # Add the argument to argv argv.extend([archivo]) # Define variables to use argv script, filename = argv # Open the file txt = open(filename) # Prints out the filename print "Here's your file %r:" % filename # Read the filename print txt.read() print "Type the filename again:" file_again = raw_input("> ") txt_again = open(file_again) print txt_again.read() txt.close()
def main(argv=None): if argv is None: argv = sys.argv else: argv.extend(sys.argv) parser = ArgumentParser() parser.add_argument( 'imagespec', help="Container image tag, e.g. repository/imagename:version") parser.add_argument( '--grouping', default=None, type=str, help= "Group layers into user defined provect versions (can't be used with --base-image)" ) parser.add_argument( '--base-image', default=None, type=str, help= "Use base image spec to determine base image/layers (can't be used with --grouping or --dockerfile)" ) parser.add_argument( '--dockerfile', default=None, type=str, help= "Use Dockerfile to determine base image/layers (can't be used with --grouping or ---base-image)" ) parser.add_argument( '--project-name', default=None, type=str, help="Specify project name (default is container image spec)") parser.add_argument( '--project-version', default=None, type=str, help="Specify project version (default is container image tag/version)" ) parser.add_argument( '--detect-options', default=None, type=str, help="Extra detect options to be passed directlyto the detect") args = parser.parse_args() print(args) if not args.imagespec: parser.print_help(sys.stdout) sys.exit(1) if args.dockerfile and args.base_image: parser.print_help(sys.stdout) sys.exit(1) if args.grouping and (args.dockerfile and args.base_image): parser.print_help(sys.stdout) sys.exit(1) scan_container_image(args.imagespec, args.grouping, args.base_image, args.dockerfile, args.project_name, args.project_version, args.detect_options)
for quality in (get_record_quality(r) for r in records): for i, q in enumerate(quality): mean_qualities[i] += q real_max_read_length = max(len(quality), real_max_read_length) reads += 1 mean_qualities = mean_qualities[:real_max_read_length] mean_qualities = [q * 1.0 / reads for q in mean_qualities] probabilities = score_to_probabilites(mean_qualities) plt.plot(range(0, len(probabilities)), probabilities) plt.ylabel('Error probability') plt.xlabel('Base') plt.axis([0, len(probabilities), 0, max(probabilities)]) plt.savefig(result_file('nucleotide_error_probability.png')) plt.clf() if __name__ == '__main__': make_result_dir() argv = argv[1:] if len(argv) == 0: argv.extend(DEFAULT_INPUT) for filename in argv: preprocess_file(filename) with open(filename) as input_file: records = get_records(input_file) get_gc_content(records) with open(filename) as input_file: records = get_records(input_file) get_quality_distribution(records)
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) try: program_shortdesc = __import__('__main__').__doc__.split("\n")[1] except: program_shortdesc = __import__('__main__').__doc__ program_license = '''%s Created by Wojciech Migda on %s. Copyright 2019 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout, stdin # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-N", "--neval", type=int, default=30, action='store', dest="neval", help="Number of hyper-parameter sets evaluations") parser.add_argument("-F", "--nfolds", type=int, default=5, action='store', dest="nfolds", help="Number of cross-validation folds") parser.add_argument( "--cv-jobs", type=int, default=1, action='store', dest="ncvjobs", help="Number of cross-validation (cross_val_score) jobs") parser.add_argument("-j", "--jobs", type=int, default=1, action='store', dest="njobs", help="Model: number of jobs") parser.add_argument("-s", "--seed", type=int, default=1, action='store', dest="seed", help="Model: RNG seed value") parser.add_argument( "--number_of_pos_neg_clauses_per_label", type=int, default=5, action='store', dest="number_of_pos_neg_clauses_per_label", help= "Model: number of either positive or negative clauses per label") parser.add_argument("--nepochs", type=int, default=30, action='store', dest="nepochs", help="Model: number of epochs") parser.add_argument("--states-range", type=str, default="500,2000,20", action='store', dest="states_range", help="Model: number of states, 'min,max,step'") parser.add_argument("--threshold-range", type=str, default="5,20,1", action='store', dest="threshold_range", help="Model: threshold, 'min,max,step'") parser.add_argument("--s-range", type=str, default="1.0,6.0", action='store', dest="s_range", help="Model: s, 'min,max'") # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass from cv_core import work work(args.neval, args.nfolds, args.ncvjobs, args.njobs, args.seed, args.number_of_pos_neg_clauses_per_label, args.nepochs, args.states_range, args.threshold_range, args.s_range) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise (e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
from sys import argv as dbg_sys_argv dbg_sys_argv.extend([ '--cfg_file_path', 's3://slf-ca-dev-glue/amp/test/testing_schema/config.json' ]) from urllib.parse import urlparse import boto3 from awsglue.transforms import * import random import os from pyspark.sql.functions import col, lit, when from datetime import date, datetime from pyspark.sql.functions import col, lit, to_date from awsglue.context import GlueContext from awsglue.transforms import * from pyspark.context import SparkContext from pyspark.sql import SQLContext from awsglue.dynamicframe import DynamicFrame from awsglue.utils import getResolvedOptions import sys import json import time from pyspark.sql.window import Window from pyspark.sql.types import StringType import pyspark.sql.functions as func class generate_testdata(): def __init__(self):
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) program_shortdesc = __import__('__main__').__doc__.split("\n")[1] program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout,stdin # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-i", "--in-hdf5-file", action='store', dest="in_h5", type=str, help="input HDF5 file with contest data") parser.add_argument("-n", "--num-est", type=int, default=50, action='store', dest="nest", help="number of Random Forest estimators") parser.add_argument("-j", "--jobs", type=int, default=2, action='store', dest="njobs", help="number of Random Forest jobs") parser.add_argument("-o", "--out-csv", action='store', dest="out_csv_file", default=stdout, type=FileType('w'), help="output CSV file name") """ parser.add_argument("--in-test-csv", action='store', dest="in_test_csv", default='test.csv', type=str, help="input CSV with test data zipped inside IN_TEST_ARCH") parser.add_argument("-o", "--out-h5", action='store', dest="out_h5", default='raw-data.h5', type=str, help="output HDF5 filename for data") """ # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work(args.in_h5, args.out_csv_file, args.nest, args.njobs) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise(e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
from sys import argv user_in = raw_input("Write something.") argv.extend(user_in) #argv = raw_input("Give me some arguments ") print argv
if not (len(argv) == 2 and argv[1] in ('--help', '--version', installer)): argv.pop(0) argv.sort() contparam = len(argv) else: contparam = 1 else: contparam = 0 if contparam in range(2, 4): argv.sort() if argv[-2] in ('0', '1'): aux = [argv[-1], argv[-2]] argv = argv[:-2] argv.extend(aux) elif contparam > 3: err(3) if contparam > 0: validado = validar(argv) if contparam == 1: if validado[0] == 'a': paramHorizontal = validado[1] elif validado[0] == 'f': paramFecha = validado[1] elif validado[0] == 'c': paramColor = validado[1] elif contparam == 2: if validado[0] == 'af':
def main(argv=None): # IGNORE:C0111 '''Command line options.''' from sys import argv as Argv if argv is None: argv = Argv pass else: Argv.extend(argv) pass from os.path import basename program_name = basename(Argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date) try: program_shortdesc = __import__('__main__').__doc__.split("\n")[1] except: program_shortdesc = __import__('__main__').__doc__ program_license = '''%s Created by Wojciech Migda on %s. Copyright 2016 Wojciech Migda. All rights reserved. Licensed under the MIT License Distributed on an "AS IS" basis without warranties or conditions of any kind, either express or implied. USAGE ''' % (program_shortdesc, str(__date__)) try: from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter from argparse import FileType from sys import stdout # Setup argument parser parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-n", "--num-est", type=int, default=700, action='store', dest="nest", help="number of Random Forest estimators") parser.add_argument("-j", "--jobs", type=int, default=-1, action='store', dest="njobs", help="number of jobs") parser.add_argument("-f", "--cv-fold", type=int, default=0, action='store', dest="nfolds", help="number of cross-validation folds") parser.add_argument("--int-fold", type=int, default=6, action='store', dest="int_fold", help="internal fold for PrudentialRegressorCVO2FO") parser.add_argument("-b", "--n-buckets", type=int, default=8, action='store', dest="nbuckets", help="number of buckets for digitizer") parser.add_argument("-o", "--out-csv", action='store', dest="out_csv_file", default=stdout, type=FileType('w'), help="output CSV file name") parser.add_argument( "-m", "--minimizer", action='store', dest="minimizer", default='BFGS', type=str, choices=['Powell', 'CG', 'BFGS'], help="minimizer method for scipy.optimize.minimize") parser.add_argument( "-M", "--mvector", action='store', dest="mvector", default=[-1.5, -2.6, -3.6, -1.2, -0.8, 0.04, 0.7, 3.6], type=float, nargs='*', help="minimizer's initial params vector") parser.add_argument("-I", "--imputer", action='store', dest="imputer", default=None, type=str, choices=['mean', 'median', 'most_frequent'], help="Imputer strategy, None is -1") parser.add_argument( "--clf-params", type=str, default="{}", action='store', dest="clf_params", help="classifier parameters subset to override defaults") parser.add_argument( "-G", "--cv-grid", type=str, default="{}", action='store', dest="cv_grid", help="cross-validation grid params (used if NFOLDS > 0)") parser.add_argument( "-E", "--estimator", action='store', dest="estimator", default='PrudentialRegressor', type=str, # choices=['mean', 'median', 'most_frequent'], help="Estimator class to use") # Process arguments args = parser.parse_args() for k, v in args.__dict__.items(): print(str(k) + ' => ' + str(v)) pass work(args.out_csv_file, args.estimator, args.nest, args.njobs, args.nfolds, eval(args.cv_grid), args.minimizer, args.nbuckets, args.mvector, args.imputer, eval(args.clf_params), args.int_fold) return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise (e) pass indent = len(program_name) * " " from sys import stderr stderr.write(program_name + ": " + repr(e) + "\n") stderr.write(indent + " for help use --help") return 2 pass
from sys import argv archivo = 'ex16_sample.txt' argv.extend([archivo]) script, filename = argv print "We're going to erase %r." % filename print "If you don't want that, hit CTRL-C (^C)." print "If you do want that, hit RETURN." raw_input("?") print "Opening the file..." target = open(filename, 'w') print "Truncating the file. GoodBye!." target.truncate() print "Now I`m going to ask you for three lines." line1 = raw_input("line 1: ") line2 = raw_input("line 2: ") line3 = raw_input("line 3: ") print "I`m going to write these to the file." target.write(line1) target.write("\n") target.write(line2) target.write("\n") target.write(line3) target.write("\n")
def main(): parser = argparse.ArgumentParser( prog=os.path.basename(__file__), description="Computes the mean structure of a trajectory file") parser.add_argument('trajectory', type=str, nargs=1, help='the trajectory file you wish to analyze') parser.add_argument('-p', metavar='num_cpus', nargs=1, type=int, dest='parallel', help="(optional) How many cores to use") parser.add_argument('-o', '--output', metavar='output_file', nargs=1, help='The filename to save the mean structure to') parser.add_argument( '-f', '--format', metavar='<json/oxDNA/both>', nargs=1, help= 'Output format for the mean file. Defaults to json. Options are \"json\", \"oxdna/oxDNA\", and \"both\"' ) parser.add_argument( '-d', '--deviations', metavar='deviation_file', nargs=1, help='Immediatley run compute_deviations.py from the output') parser.add_argument( '-i', metavar='index_file', dest='index_file', nargs=1, help= 'Compute mean structure of a subset of particles from a space-separated list in the provided file' ) parser.add_argument( '-a', '--align', metavar='alignment_configuration', nargs=1, help='The id of the configuration to align to, otherwise random') args = parser.parse_args() from oxDNA_analysis_tools.config import check_dependencies check_dependencies(["python", "Bio", "numpy"]) #get file names traj_file = args.trajectory[0] parallel = args.parallel if parallel: from oxDNA_analysis_tools.UTILS import parallelize_erik_onefile n_cpus = args.parallel[0] #-f defines the format of the output file outjson = False outoxdna = False if args.format: if "json" in args.format: outjson = True if "oxDNA" in args.format or "oxdna" in args.format: outoxdna = True if "both" in args.format: outjson = True outoxdna = True if outjson == outoxdna == False: print( "ERROR: unrecognized output format\nAccepted formats are \"json\", \"oxDNA/oxdna\", and \"both\"", file=stderr) exit(1) else: print("INFO: No output format specified, defaulting to oxDNA", file=stderr) outoxdna = True #-o names the output file if args.output: outfile = args.output[0] else: if outjson and not outoxdna: ext = ".json" elif outjson and outoxdna: ext = ".json/.dat" elif outoxdna and not outjson: ext = ".dat" outfile = "mean{}".format(ext) print("INFO: No outfile name provided, defaulting to \"{}\"".format( outfile), file=stderr) #-d will run compute_deviations.py when this script is completed. dev_file = None if args.deviations: dev_file = args.deviations[0] #-i will make it only run on a subset of nucleotides. #The index file is a space-separated list of particle IDs if args.index_file: index_file = args.index_file[0] with open(index_file, 'r') as f: indexes = f.readline().split() try: indexes = [int(i) for i in indexes] except: print( "ERROR: The index file must be a space-seperated list of particles. These can be generated using oxView by clicking the \"Download Selected Base List\" button" ) else: with ErikReader(traj_file) as r: indexes = list(range(len(r.read().positions))) # The reference configuration which is used to define alignment align_conf = [] #calculate the number of configurations in the trajectory num_confs = cal_confs(traj_file) # if we have no align_conf we need to chose one # and realign its cms to be @ 0,0,0 if align_conf == []: align = None if args.align: align = args.align[0] align_conf_id, align_poses = pick_starting_configuration( traj_file, num_confs, align) # we are just interested in the nucleotide positions align_conf = align_poses.positions[indexes] #Actually compute mean structure if not parallel: print( "INFO: Computing mean of {} configurations with an alignment of {} particles using 1 core." .format(num_confs, len(align_conf)), file=stderr) r = ErikReader(traj_file) mean_pos_storage, mean_a1_storage, mean_a3_storage, intermediate_mean_structures, processed_frames = compute_mean( r, align_conf, indexes, num_confs) #If parallel, the trajectory is split into a number of chunks equal to the number of CPUs available. #Each of those chunks is then calculated seperatley and the result is summed. if parallel: print( "INFO: Computing mean of {} configurations with an alignment of {} particles using {} cores." .format(num_confs, len(align_conf), n_cpus), file=stderr) out = parallelize_erik_onefile.fire_multiprocess( traj_file, compute_mean, num_confs, n_cpus, align_conf, indexes) mean_pos_storage = np.sum(np.array([i[0] for i in out]), axis=0) mean_a1_storage = np.sum(np.array([i[1] for i in out]), axis=0) mean_a3_storage = np.sum(np.array([i[2] for i in out]), axis=0) intermediate_mean_structures = [] [intermediate_mean_structures.extend(i[3]) for i in out] processed_frames = sum((i[4] for i in out)) # finished task entry print("INFO: processed frames total: {}".format(processed_frames), file=stderr) #Convert mean structure to a json file mean_file = dumps({ "i_means": intermediate_mean_structures, "g_mean": prep_pos_for_json(mean_pos_storage / processed_frames), "a1_mean": prep_pos_for_json( [normalize(v) for v in (mean_a1_storage / processed_frames)]), "a3_mean": prep_pos_for_json( [normalize(v) for v in (mean_a3_storage / processed_frames)]), "p_frames": processed_frames, "ini_conf": { "conf": prep_pos_for_json(align_conf), "id": align_conf_id } }) #Save the mean structure to the specified output file. if outjson or dev_file: #save output as json format if outoxdna == True: #if making both outputs, automatically set file extensions. jsonfile = outfile.split(".")[0] + ".json" else: jsonfile = outfile print("INFO: Writing mean configuration to", jsonfile, file=stderr) with open(jsonfile, "w") as file: file.write(mean_file) if outoxdna: #save output as oxDNA .dat format if outjson == True: #if making both outputs, automatically set file extensions. outname = outfile.split(".")[0] + ".dat" else: outname = outfile from oxDNA_analysis_tools.mean2dat import make_dat make_dat(loads(mean_file), outname) #If requested, run compute_deviations.py using the output from this script. if dev_file: print("INFO: launching compute_deviations.py", file=stderr) #this is probably horrible practice, but to maintain the ability to call things from the command line, I cannot pass arguments between main() calls. #so instead we're gonna spoof a global variable to make it look like compute_deviations was called explicitally argv.clear() argv.extend([ 'compute_deviations.py', '-o', dev_file, "-r", dev_file.split('.')[0] + "_rmsd.png", "-d", dev_file.split('.')[0] + "_rmsd_data.json" ]) if args.index_file: argv.append("-i") argv.append(index_file) if parallel: argv.append("-p") argv.append(str(n_cpus)) argv.append(jsonfile) argv.append(traj_file) from oxDNA_analysis_tools import compute_deviations from sys import executable print(executable) print(argv) compute_deviations.main() #compute_deviations needs the json meanfile, but its not useful for visualization #so we dump it if not outjson: print("INFO: deleting {}".format(jsonfile), file=stderr) from os import remove remove(jsonfile) print(time.time() - start_t)