def anova_one_drug(anova, options): """Analyse one specific drug""" from gdsctools import ANOVAReport anova.set_cancer_type(options.tissue) if options.feature: anova.feature_names = options.features results = anova.anova_one_drug(options.drug) print("\nFound %s associations" % len(results)) if len(results)==0: print(red("\nPlease try with another drug or no --drug option")) return # ?? is this required ? N = len(results) results.df.insert(0, 'ASSOC_ID', range(1, N+1)) if options.no_html is True: return r = ANOVAReport(anova, results=results) print(darkgreen("\nCreating all figure and html documents in %s" % r.settings.directory)) r.create_html_pages(onweb=options.onweb)
def anova_one_drug(anova, options): """Analyse one specific drug""" from gdsctools import ANOVAReport anova.set_cancer_type(options.tissue) if options.feature: anova.feature_names = options.features results = anova.anova_one_drug(options.drug) print("\nFound %s associations" % len(results)) if len(results) == 0: print(red("\nPlease try with another drug or no --drug option")) return # ?? is this required ? N = len(results) results.df.insert(0, 'ASSOC_ID', range(1, N + 1)) if options.no_html is True: return r = ANOVAReport(anova, results=results) print( darkgreen("\nCreating all figure and html documents in %s" % r.settings.directory)) r.create_html_pages(onweb=options.onweb)
def anova_all(anova, options): """Analyse the entire data set. May be restricted to one feature""" from gdsctools import ANOVAReport if options.feature: anova.feature_names = [options.feature] # The analysis print(darkgreen("Starting the analysis")) df = anova.anova_all() if len(df) == 0: print("Found no valid association ? Check your input files") return # HTML report if options.no_html is True: return r = ANOVAReport(anova, results=df) print(darkgreen("Creating all figure and html documents in %s" % r.settings.directory)) r.create_html_pages(onweb=options.onweb)
def anova_pipeline(args=None): """This function is used by the standalone application called **gdsctools_anova** Type:: gdsctools_anova --help to get some help. """ msg = "Welcome to GDSCTools standalone" print_color(msg, purple, underline=True) # Keep the argument args as None by default to # allow testing e.g., in nosetests if args is None: args = sys.argv[:] elif len(args) == 1: args += ['--help'] user_options = ANOVAOptions(prog="gdsctools_anova") try: options = user_options.parse_args(args[1:]) except SystemExit: return # ----------------------------------------------------------------- # ---------------------------------------- options without analysis # ----------------------------------------------------------------- if options.version is True: print("This is version %s of gdsctools_anova" % gdsctools.version) return if options.testing is True: print('Testing mode:') from gdsctools import ANOVA, ic50_test an = ANOVA(ic50_test) df = an.anova_one_drug_one_feature('Drug_1047_IC50', 'TP53_mut') assert df.loc[1,'N_FEATURE_pos'] == 554, \ "N_feature_pos must be equal to 554" print(df.T) print(darkgreen("\nGDSCTools seems to be installed properly")) return if options.save_settings: from gdsctools import ANOVA, ic50_test an = ANOVA(ic50_test) an.settings.to_json(options.save_settings) print('Save a default parameter set in %s' % options.save_settings) return if options.license is True: print(gdsctools.license) return if options.summary is True: from gdsctools import anova an = anova.ANOVA(options.input_ic50, options.input_features) print(an) return if options.print_tissues is True: from gdsctools import anova an = anova.ANOVA(options.input_ic50, options.input_features) tissues = an.tissue_factor try: tissues = tissues.sort_values('Tissue Factor').unique() except: tissues = tissues.sort(inplace=False).unique() for name in tissues: print(name) return if options.print_drugs is True: from gdsctools import anova gdsc = anova.ANOVA(options.input_ic50, options.input_features) import textwrap print("\n".join(textwrap.wrap(" , ".join(gdsc.drugIds)))) return if options.print_features is True: from gdsctools import anova gdsc = anova.ANOVA(options.input_ic50, options.input_features) import textwrap print("\n".join(textwrap.wrap(" , ".join(gdsc.feature_names)))) return # ----------------------------------------------------------------- # --------------------------------------------------- real analysis # ----------------------------------------------------------------- # dispatcher to the functions according to the user parameters from gdsctools import ANOVA, ANOVAReport anova = ANOVA(options.input_ic50, options.input_features, options.input_drug, low_memory=not options.fast) anova = _set_settings(anova, options) if options.drug and options.drug not in anova.ic50.df.columns: print(red("Invalid Drug. Try --print-drug-names")) sys.exit(1) if options.drug is not None and options.feature is not None: print_color("ODOF mode", purple) anova_one_drug_one_feature(anova, options) elif options.drug is not None: print_color("ODAF mode", purple) anova_one_drug(anova, options) else: # analyse everything if options.feature is None: print_color("ADAF mode", purple) else: print_color("ADOF mode", purple) anova_all(anova, options) if options.onweb is False and options.no_html is False: msg = "\nNote that a directory {} was created and files saved into it" print(purple(msg.format(options.directory))) return
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-scoring --help """ d = easydev.DevTools() if args == None: args = sys.argv[:] user_options = Options(prog="dreamtools-scoring") if len(args) == 1: user_options.parse_args(["prog", "--help"]) else: options = user_options.parse_args(args[1:]) if options.challenge is None or options.sub_challenge is None: print_color('--challenge and --sub-challenge must be provided', red) sys.exit() try: d.check_param_in_list(options.challenge, registered.keys()) except ValueError as err: txt = "DreamScoring error: unknown challenge name (%s) or not yet implemented\n" % options.challenge txt += "--->" + err.message print_color(txt, red) sys.exit() try: d.check_param_in_list(options.sub_challenge, registered[options.challenge]) except ValueError as err: print("DreamScoring error: unknown sub challenge or not yet implemented") print("--->" + err.message) sys.exit() if options.filename is None: txt = "---> filename not provided. You must provide a filename with correct format\n" txt += "Format are explained on DreamTools website or Synapse website\n" txt += "https://github.com/dreamtools/dreamtools, or http://www.synapse.org\n" print_color(txt, red) sys.exit() if os.path.exists(options.filename) is False: raise IOError("file %s does not seem to exists" % options.filename) print_color("Dreamtools scoring", purple, underline=True) print('Challenge %s (sub challenge %s)\n\n' % (options.challenge, options.sub_challenge)) res = '??' if options.challenge not in registered.keys(): raise ValueError('Invalid challenge name. Choose one of %s' % registered.keys()) 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) elif options.challenge == 'd8c2': if options.sub_challenge == 'sc1': res = d8c2_sc1(options.filename, verbose=options.verbose) if options.sub_challenge == 'sc2': res = d8c2_sc2(options.filename, verbose=options.verbose) 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: %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)