def subsetWells(df_mapping_dict, criteria, hypothesis, verbose=False): ''' Tag wells that meet user-passed criteria. Args: df (pandas.DataFrame) must have Plate_IDs and Well as columns criteria (dictionary) with mapping variables (str) as keys and accepted instances (str) as values hypothesis (dictionary) verbose (boolean) Returns: df (pandas.DataFrame) ''' if (len(criteria) == 0): smartPrint('No subsetting was requested.\n', verbose) return df_mapping_dict, None for plate_id, mapping_df in df_mapping_dict.items(): # subsetting on number-based criteria does not match hits due to type mismatch (str vs int/float) mapping_df_str = mapping_df.astype(str) remove_boolean = ~(mapping_df_str.isin(criteria).sum(1) == len(criteria)).values # list of booleans remove_idx = mapping_df_str.index[remove_boolean] mapping_df.loc[remove_idx, 'Subset'] = [0] * len(remove_idx) msg = 'The following criteria were used to subset data:\n' msg += tidyDictPrint(criteria) smartPrint(msg, verbose) return df_mapping_dict, msg
def flagWells(df, flags, verbose=False, drop=False): ''' Passes plate-well-specific flags from user into mapping dataframes. Args: df (dictionary of pandas.DataFrame) must have Plate_IDs and Well as columns flags (dictionary) with Plate_IDs (str) as keys and Wells (stR) as vlaues verbose (boolean) Returns: df (pandas.DataFrame) ''' if (len(flags) == 0): smartPrint('No wells were flagged.\n', verbose) return df for plate, wells in flags.items(): if plate in df.keys(): df[plate].loc[wells, 'Flag'] = [1] * len(wells) if drop: df[plate] = df[plate][df[plate].Flag == 0] smartPrint('The following flags were detected:\n', verbose) smartPrint(tidyDictPrint(flags), verbose) return df
def print_arguments(args): msg = '\n' msg += tidyMessage('User provided the following command-line arguments:') msg += '\n' msg += tidyDictPrint(vars(args)) print(msg)
def print_defaults(self): parser = argparse.ArgumentParser( description= 'Print in terminal default values stored in libs/config.py') msg = '\nDefault settings for select variables. ' msg += 'You can adjust these values in "amiga/libs/config.py". \n\n' msg += tidyDictPrint(config) sys.exit(msg)
def parseCommand(): ''' Interprets the arguments passed by the user to AMiGA. Note: Function is AMiGA-specific and should not be used verbatim for other apps. Returns: args (dict): a dictionary with keys as suggested variable names and keys as the user-passed and argparse-interpreted arguments. ''' args_dict = {} # parse arguments parser = argparse.ArgumentParser() parser.add_argument('-i', '--input', required=True) parser.add_argument('-o', '--output', required=True) parser.add_argument('-s', '--subset', required=False) parser.add_argument('-v', '--value', required=True) parser.add_argument('-x', '--x-variable', required=True) parser.add_argument('-y', '--y-variable', required=True) parser.add_argument('-p', '--operation', required=False) parser.add_argument('-f', '--filter', required=False) parser.add_argument('-t', '--title', required=False) parser.add_argument('--kwargs', required=False) parser.add_argument('--verbose', action='store_true', default=False) # pass arguments to local variables args = parser.parse_args() args_dict['fi'] = args.input # File path provided by user args_dict['fo'] = args.output args_dict['s'] = args.subset args_dict['x'] = args.x_variable args_dict['y'] = args.y_variable args_dict['v'] = args.value args_dict['p'] = args.operation args_dict['f'] = args.filter args_dict['t'] = args.title args_dict['kwargs'] = args.kwargs args_dict['verbose'] = args.verbose # summarize command-line artguments and print if args_dict['verbose']: msg = '\n' msg += tidyMessage( 'User provided the following command-line arguments:') msg += '\n' msg += tidyDictPrint(args_dict) print(msg) return args_dict
def interpretParameters(files, args, verbose=False): ''' Checks specific directories for their existence and makes sure data was provided by user. It will also compose and can print a message that can communicate with user the results of this validation. Args: files (dict): keys are parameter names and values are file paths args (dict): keys are parameter names and values are corresponding command-line arguments Returns: params_dict (dict): dictionary where keys are variables and values instances ''' # params_settings defines parameters for interpreting parameter files or argument calls # # each item is a 3-tuple where: # 1. parameter name which matches both input argument and text file name (str) # 2. delimitor that separates values of a variable of the parameter (str) # 3. integerize: whether to convert values of a variable to integers (boolean) params_settings = [('interval', ',', True), ('subset', ',', False), ('flag', ',', False), ('hypo', '\+|,', False)] # initialize all parameters based on their settings params_dict = {} for pp, sep, integerize in params_settings: params_dict[pp] = initializeParameter(files[pp], args[pp], sep=sep, integerize=integerize) smartPrint(tidyDictPrint(params_dict), verbose) # if user requests any subsetting, summary results must be merged if params_dict['subset']: args['merges'] = True msg = 'WARNING: Because user has requested subsetting of data, ' msg += 'results will be merged into single summary and/or data file.\n' smartPrint(msg, verbose) return params_dict, args
def parseCommand(config): ''' Interprets the arguments passed by the user to AMiGA. If the verobse argument is set to True, argumentParser will also print a message summarizing the the user-passed command-line arguments. Note: Function is AMiGA-specific and should not be used verbatim for other apps. Args: config (dictionary): variables saved in config.py where key is variable and value is value Returns: args (dict): a dictionary with keys as suggested variable names and keys as the user-passed and argparse-interpreted arguments. ''' args_dict = {} # parse arguments parser = argparse.ArgumentParser() # defining input/output parser.add_argument('-i', '--input', required=True) parser.add_argument('-o', '--output', required=False) # reducing data parser.add_argument('-f', '--flag', required=False) parser.add_argument('-s', '--subset', required=False) # selecting time points parser.add_argument('-tss', '--time-step-size', action='store', type=int, default=1) #11 parser.add_argument('-sfn', '--skip-first-n', action='store', type=int, default=0) parser.add_argument('-t', '--interval', required=False) # hypothesis testing parser.add_argument('-y', '--hypothesis', required=False) parser.add_argument('-fdr', '--false-discovery-rate', action='store', type=int, default=10) parser.add_argument('-np', '--number-permutations', action='store', type=int, default=0) parser.add_argument('--subtract-control', action='store_true', default=False) # pooling and normalizations parser.add_argument('--normalize-parameters', action='store_true', default=False) parser.add_argument('--pool-by', required=False) parser.add_argument('--normalize-by', required=False) # plotting parser.add_argument('--plot', action='store_true', default=False) parser.add_argument('--plot-derivative', action='store_true', default=False) parser.add_argument('--plot-delta-od', action='store_true', default=True) parser.add_argument('--dont-plot', action='store_true', default=False) ## saving tables parser.add_argument('--save-cleaned-data', action='store_true', default=False) parser.add_argument('--save-gp-data', action='store_true', default=False) parser.add_argument('--save-mapping-tables', action='store_true', default=False) parser.add_argument('--merge-summary', action='store_true', default=False) ## model preferences parser.add_argument('--fix-noise', action='store_true', default=False) parser.add_argument('--sample-posterior', action='store_true', default=False) parser.add_argument('--include-gaussian-noise', action='store_true', default=False) ## user communication parser.add_argument('--only-basic-summary', action='store_true', default=False) parser.add_argument('--only-print-defaults', action='store_true', default=False) parser.add_argument('-v', '--verbose', action='store_true', default=False) # pass arguments to local variables args = parser.parse_args() args_dict['fpath'] = args.input # File path provided by user args_dict['flag'] = args.flag args_dict['subset'] = args.subset args_dict['hypo'] = args.hypothesis args_dict['interval'] = args.interval args_dict['plot'] = args.plot args_dict['verbose'] = args.verbose args_dict['nperm'] = args.number_permutations args_dict['nthin'] = args.time_step_size args_dict['nskip'] = args.skip_first_n args_dict['fdr'] = args.false_discovery_rate args_dict['pool'] = [1 if args.pool_by is not None else 0 ][0] #: args.pool_replicates args_dict['merges'] = args.merge_summary args_dict['norm'] = args.normalize_parameters args_dict['pd'] = args.plot_derivative args_dict['pdo'] = args.plot_delta_od args_dict['obs'] = args.only_basic_summary args_dict['scd'] = args.save_cleaned_data args_dict['sgd'] = args.save_gp_data args_dict['smt'] = args.save_mapping_tables args_dict['opd'] = args.only_print_defaults args_dict['sc'] = args.subtract_control args_dict['dp'] = args.dont_plot args_dict['fout'] = args.output args_dict['pb'] = args.pool_by args_dict['nb'] = args.normalize_by args_dict['fn'] = args.fix_noise args_dict['slf'] = args.sample_posterior args_dict['noise'] = args.include_gaussian_noise # logical argument definitions # if normalizing parameters passed, if args_dict['nb']: args_dict['norm'] = True # if subsetting, then merge summary if args_dict['subset']: args_dict['merges'] = True # summarize command-line artguments and print if args_dict['verbose']: msg = '\n' msg += tidyMessage( 'User provided the following command-line arguments:') msg += '\n' msg += tidyDictPrint(args_dict) print(msg) # print default settings for select variables if prompted by user if args_dict['opd']: msg = '\nDefault settings for select variables. ' msg += 'You can adjust these values in amiga/libs/config.py. \n\n' msg += tidyDictPrint(config) sys.exit(msg) # if user requests any subsetting, summary results must be merged if args_dict['subset'] is not None: args_dict['merges'] = True return args_dict