def __init__(self, client=None, version=2): super(SC2BSubmissions, self).__init__(client=client, name="SC2B") self.version = version from hpn import HPNAdmin self.hpn = HPNAdmin(client=self.client) # download missing file automatically if needed. from dreamtools import Challenge c = Challenge('D8C1') c._download_data('experimental.zip', 'syn1920412')
def __init__(self, client=None, version=2): super(SC2BSubmissions, self).__init__(client=client, name="SC2B") self.version = version from .hpn import HPNAdmin self.hpn = HPNAdmin(client=self.client) # download missing file automatically if needed. from dreamtools import Challenge c = Challenge('D8C1') c._download_data('experimental.zip', 'syn1920412')
def _generic_download(name, mode): c = Challenge(name) class_inst = c.import_scoring_class() if mode == 'template': if len(class_inst.sub_challenges) == 0: class_inst.download_template() else: for subname in class_inst.sub_challenges: class_inst.download_template(subname) elif mode == 'gs': if len(class_inst.sub_challenges) == 0: class_inst.download_goldstandard() else: for subname in class_inst.sub_challenges: class_inst.download_goldstandard(subname)
def get_challenge(challenge_name): """Test validity of the challenge and returns an instance :param challenge_name: a valid name e.g. D5C3, D9dot5C1 :return: instance of the challenge """ try: c = Challenge(challenge_name) except: txt = "The challenge %s could not be found. " % challenge_name txt += "See --help for valid names" print_color(txt, red) sys.exit() return c
def scoring(args=None): """This function is used by the standalone application called dreamscoring :: dreamscoring --help """ d = DevTools() if args is None: args = sys.argv[:] user_options = Options(prog="dreamtools") if len(args) == 1: user_options.parse_args(["prog", "--help"]) else: options = user_options.parse_args(args[1:]) if options.version is True: print("%s" % dreamtools.version) sys.exit() # Check on the challenge name if options.challenge is None: print_color('--challenge must be provided', red) sys.exit() else: options.challenge = options.challenge.upper() options.challenge = options.challenge.replace('DOT', 'dot') from dreamtools.admin.download_data import get_challenge_list if options.challenge not in get_challenge_list(): print_color( "This challenge %s is not registered in dreamtools." % options.challenge, red) print("Here is the list of registered challenges: " + ", ".join(get_challenge_list())) sys.exit() # Check that the challenge can be loaded class_inst = get_challenge(options.challenge) try: this = class_inst.import_scoring_class() except NotImplementedError as err: print("\n" + str(err)) sys.exit() else: # User may just request some information about the challenge. if options.info is True: print(this) sys.exit() elif options.onweb is True: this.onweb() sys.exit() # Checks name of the sub-challenges subchallenges = get_subchallenges(options.challenge) if len(subchallenges) and options.sub_challenge is None: txt = "This challenge requires a sub challenge name. " txt += "Please use --sub-challenge followed by one value in %s " % subchallenges print_color(txt, red) sys.exit(0) if options.sub_challenge is not None and len(subchallenges) != 0: try: d.check_param_in_list(options.sub_challenge, subchallenges) except ValueError as err: txt = "DREAMTools error: unknown sub challenge or not implemented" txt += "--->" + str(err) print_color(txt, red) sys.exit() # maybe users just need a template if options.download_template is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_template()) else: print(class_inst.download_template(options.sub_challenge)) return # similary for the GS if options.download_goldstandard is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_goldstandard()) else: print(class_inst.download_goldstandard(options.sub_challenge)) return # finally, we need a submission if options.filename is None: txt = "---> filename not provided. You must provide a filename with correct format\n" txt += "You may get a template using --download-template \n" txt += "Alternatively, you can user either --info or --onweb option to get information about the challenge.\n" txt += "https://github.com/dreamtools/dreamtools, or http://dreamchallenges.org\n" print_color(txt, red) sys.exit() # filename # filename in general is a single string but could be a list of filenames # Because on the parser, we must convert the string into a single string # if the list haa a length of 1 for filename in options.filename: if os.path.exists(filename) is False: raise IOError("file %s does not seem to exists" % filename) if len(options.filename) == 1: options.filename = options.filename[0] print_color("DREAMTools scoring", purple, underline=True) print('Challenge %s (sub challenge %s)\n\n' % (options.challenge, options.sub_challenge)) res = generic_scoring(options.challenge, options.filename, subname=options.sub_challenge, goldstandard=options.goldstandard) txt = "Solution for %s in challenge %s" % (options.filename, options.challenge) if options.sub_challenge is not None: txt += " (sub-challenge %s)" % options.sub_challenge txt += " is :\n" for k in sorted(res.keys()): txt += darkgreen(" %s:\n %s\n" % (k, res[k])) print(txt)
def scoring(args=None): """This function is used by the standalone application called dreamscoring :: dreamscoring --help """ d = DevTools() if args is None: args = sys.argv[:] user_options = Options(prog="dreamtools") if len(args) == 1: user_options.parse_args(["prog", "--help"]) else: options = user_options.parse_args(args[1:]) if options.version is True: print("%s" % dreamtools.version) sys.exit() # Check on the challenge name if options.challenge is None: print_color('--challenge must be provided', red) sys.exit() else: options.challenge = options.challenge.upper() options.challenge = options.challenge.replace('DOT', 'dot') from dreamtools.admin.download_data import get_challenge_list if options.challenge not in get_challenge_list(): print_color("This challenge %s is not registered in dreamtools." % options.challenge, red) print("Here is the list of registered challenges: " + ", ".join(get_challenge_list())) sys.exit() # Check that the challenge can be loaded class_inst = get_challenge(options.challenge) try: this = class_inst.import_scoring_class() except NotImplementedError as err: print("\n"+str(err)) sys.exit() else: # User may just request some information about the challenge. if options.info is True: print(this) sys.exit() elif options.onweb is True: this.onweb() sys.exit() # Checks name of the sub-challenges subchallenges = get_subchallenges(options.challenge) if len(subchallenges) and options.sub_challenge is None: txt = "This challenge requires a sub challenge name. " txt += "Please use --sub-challenge followed by one value in %s " % subchallenges print_color(txt, red) sys.exit(0) if options.sub_challenge is not None and len(subchallenges) != 0: try: d.check_param_in_list(options.sub_challenge, subchallenges) except ValueError as err: txt = "DREAMTools error: unknown sub challenge or not implemented" txt += "--->" + str(err) print_color(txt, red) sys.exit() # maybe users just need a template if options.download_template is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_template()) else: print(class_inst.download_template(options.sub_challenge)) return # similary for the GS if options.download_goldstandard is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_goldstandard()) else: print(class_inst.download_goldstandard(options.sub_challenge)) return # finally, we need a submission if options.filename is None: txt = "---> filename not provided. You must provide a filename with correct format\n" txt += "You may get a template using --download-template \n" txt += "Alternatively, you can user either --info or --onweb option to get information about the challenge.\n" txt += "https://github.com/dreamtools/dreamtools, or http://dreamchallenges.org\n" print_color(txt, red) sys.exit() # filename # filename in general is a single string but could be a list of filenames # Because on the parser, we must convert the string into a single string # if the list haa a length of 1 for filename in options.filename: if os.path.exists(filename) is False: raise IOError("file %s does not seem to exists" % filename) if len(options.filename) == 1: options.filename = options.filename[0] print_color("DREAMTools scoring", purple, underline=True) print('Challenge %s (sub challenge %s)\n\n' % (options.challenge, options.sub_challenge)) res = generic_scoring(options.challenge, options.filename, subname=options.sub_challenge, goldstandard=options.goldstandard) txt = "Solution for %s in challenge %s" % (options.filename, options.challenge) if options.sub_challenge is not None: txt += " (sub-challenge %s)" % options.sub_challenge txt += " is :\n" for k in sorted(res.keys()): txt += darkgreen(" %s:\n %s\n" %(k, res[k])) print(txt)
def scoring(args=None): """This function is used by the standalone application called dreamscoring :: dreamscoring --help """ d = DevTools() if args == None: args = sys.argv[:] user_options = Options(prog="dreamtools") if len(args) == 1: user_options.parse_args(["prog", "--help"]) else: options = user_options.parse_args(args[1:]) # Check on the challenge name if options.challenge is None: print_color("--challenge and --sub-challenge must be provided", red) sys.exit() else: options.challenge = options.challenge.upper() options.challenge = options.challenge.replace("DOT", "dot") # Check that the challenge can be loaded class_inst = get_challenge(options.challenge) try: class_inst.import_scoring_class() except NotImplementedError as err: print("\n" + err.message) sys.exit() # Checks name of the sub-challenges subchallenges = get_subchallenges(options.challenge) if len(subchallenges) and options.sub_challenge is None: txt = "This challenge requires a sub challenge name." txt += "Please provide one amongst %s " % subchallenges print_color(txt, red) sys.exit(0) if options.sub_challenge is not None and len(subchallenges) != 0: try: d.check_param_in_list(options.sub_challenge, subchallenges) except ValueError as err: txt = "DreamTools error: unknown sub challenge or not implemented" txt += "--->" + err.message print_color(txt, red) sys.exit() if options.download_template is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_template()) else: print(class_inst.download_template(options.sub_challenge)) return # similary for the GS if options.download_goldstandard is True: c = Challenge(options.challenge) class_inst = c.import_scoring_class() if options.sub_challenge is None: print(class_inst.download_goldstandard()) else: print(class_inst.download_goldstandard(options.sub_challenge)) return if options.filename is None: txt = "---> filename not provided. You must provide a filename with correct format\n" txt += "You may get a template using --download-template option\n" txt += "https://github.com/dreamtools/dreamtools, or http://dreamchallenges.org\n" print_color(txt, red) sys.exit() # filename # filename in general is a single string but could be a list of filenames # Because on the parser, we must convert the string into a single string # if the list haa a length of 1 for filename in options.filename: if os.path.exists(filename) is False: raise IOError("file %s does not seem to exists" % filename) if len(options.filename) == 1: options.filename = options.filename[0] print_color("Dreamtools scoring", purple, underline=True) print("Challenge %s (sub challenge %s)\n\n" % (options.challenge, options.sub_challenge)) res = "??" if options.challenge == "D8C1": if options.sub_challenge == "sc1a": res = d8c1_sc1a(options.filename, verbose=options.verbose) elif options.sub_challenge == "sc1b": res = d8c1_sc1b(options.filename, verbose=options.verbose) elif options.sub_challenge == "sc2a": res = d8c1_sc2a(options.filename, verbose=options.verbose) elif options.sub_challenge == "sc2b": res = d8c1_sc2b(options.filename, verbose=options.verbose) else: res = generic_scoring( options.challenge, options.filename, subname=options.sub_challenge, goldstandard=options.goldstandard ) txt = "Solution for %s in challenge %s" % (options.filename, options.challenge) if options.sub_challenge is not None: txt += " (sub-challenge %s)" % options.sub_challenge txt += " is :\n" for k in sorted(res.keys()): txt += darkgreen(" %s:\n %s\n" % (k, res[k])) print(txt)
def test_challenge(): c = Challenge("D0C0")