def create_opts(sample_type, chp_path, gradient_color_by, barchart_categories): """Create a dict of options for processing functions Parameters ---------- sample_type : str, {fecal, oral, skin} The sample type. chp_path : str The path to the current processing chapter. gradient_color_by : str The taxon to color by for the gradient PCoA. barchart_categories : Iterable of str The relevant barchart categories to use. Returns ------- dict The paths and desired options. """ opts = {k: agu.get_path(v) for k, v in agenv.paths.items()} opts['sample_type'] = sample_type opts['gradient_color_by'] = gradient_color_by opts['chp-path'] = chp_path opts['rarefaction-depth'] = agenv.get_rarefaction_depth() barchart_map = { 'diet': 'DIET_TYPE', 'sex': 'SEX', 'age': 'AGE_CAT', 'bmi': 'BMI_CAT', 'flossing': 'FLOSSING_FREQUENCY', 'cosmetics': 'COSMETICS_FREQUENCY', 'hand': 'DOMINANT_HAND' } fmt = [] for cat in barchart_categories: if cat not in barchart_map: raise KeyError("%s is not known" % cat) cat_path = opts['ag-100nt-1k-%s-%s-biom' % (sample_type, cat)] fmt.append("%s:%s" % (barchart_map[cat], cat_path)) opts['barchart_categories'] = '"%s"' % ', '.join(fmt) return opts
def create_opts(sample_type, chp_path, gradient_color_by, barchart_categories): """Create a dict of options for processing functions Parameters ---------- sample_type : str, {fecal, oral, skin} The sample type. chp_path : str The path to the current processing chapter. gradient_color_by : str The taxon to color by for the gradient PCoA. barchart_categories : Iterable of str The relevant barchart categories to use. Returns ------- dict The paths and desired options. """ opts = {k: agu.get_path(v) for k, v in agenv.paths.items()} opts['sample_type'] = sample_type opts['gradient_color_by'] = gradient_color_by opts['chp-path'] = chp_path opts['rarefaction-depth'] = agenv.get_rarefaction_depth() barchart_map = {'diet': 'DIET_TYPE', 'sex': 'SEX', 'age': 'AGE_CAT', 'bmi': 'BMI_CAT', 'flossing': 'FLOSSING_FREQUENCY', 'cosmetics': 'COSMETICS_FREQUENCY', 'hand': 'DOMINANT_HAND'} fmt = [] for cat in barchart_categories: if cat not in barchart_map: raise KeyError("%s is not known" % cat) cat_path = opts['ag-100nt-1k-%s-%s-biom' % (sample_type, cat)] fmt.append("%s:%s" % (barchart_map[cat], cat_path)) opts['barchart_categories'] = '"%s"' % ', '.join(fmt) return opts
def create_opts(sample_type, chp_path, gradient_color_by, barchart_categories): """Create a dict of options for processing functions Parameters ---------- sample_type : str, {fecal, oral, skin} The sample type. chp_path : str The path to the current processing chapter. gradient_color_by : str The taxon to color by for the gradient PCoA. barchart_categories : Iterable of str The relevant barchart categories to use. Returns ------- dict The paths and desired options. """ def attach_dict(d, items): return [(d, i) for i in items] opts = {} queue = attach_dict(opts, agenv.paths.items()) while queue: d, (key, value) = queue.pop() if isinstance(value, dict): # get the relevant dict or a new dict nested_d = d.get(key, {}) d[key] = nested_d queue.extend(attach_dict(nested_d, value.items())) else: d[key] = agu.get_path(value) opts['sample_type'] = sample_type opts['gradient_color_by'] = gradient_color_by opts['chp-path'] = chp_path opts['rarefaction-depth'] = int(agenv.get_rarefaction_depth()[0]) barchart_map = {'diet': 'DIET_TYPE', 'sex': 'SEX', 'age': 'AGE_CAT', 'bmi': 'BMI_CAT', 'flossing': 'FLOSSING_FREQUENCY', 'cosmetics': 'COSMETICS_FREQUENCY', 'hand': 'DOMINANT_HAND'} fmt = [] for cat in barchart_categories: if cat not in barchart_map: raise KeyError("%s is not known" % cat) table_key = 'ag-%s-%s-biom' % (sample_type, cat) cat_path = opts['collapsed']['100nt']['1k'][table_key] fmt.append("%s:%s" % (barchart_map[cat], cat_path)) opts['barchart_categories'] = '"%s"' % ', '.join(fmt) return opts
def create_opts(sample_type, chp_path, gradient_color_by, barchart_categories): """Create a dict of options for processing functions Parameters ---------- sample_type : str, {fecal, oral, skin} The sample type. chp_path : str The path to the current processing chapter. gradient_color_by : str The taxon to color by for the gradient PCoA. barchart_categories : Iterable of str The relevant barchart categories to use. Returns ------- dict The paths and desired options. """ def attach_dict(d, items): return [(d, i) for i in items] opts = {} queue = attach_dict(opts, agenv.paths.items()) while queue: d, (key, value) = queue.pop() if isinstance(value, dict): # get the relevant dict or a new dict nested_d = d.get(key, {}) d[key] = nested_d queue.extend(attach_dict(nested_d, value.items())) else: d[key] = agu.get_path(value) opts['sample_type'] = sample_type opts['gradient_color_by'] = gradient_color_by opts['chp-path'] = chp_path opts['rarefaction-depth'] = int(agenv.get_rarefaction_depth()[0]) barchart_map = { 'diet': 'DIET_TYPE', 'sex': 'SEX', 'age': 'AGE_CAT', 'bmi': 'BMI_CAT', 'flossing': 'FLOSSING_FREQUENCY', 'cosmetics': 'COSMETICS_FREQUENCY', 'hand': 'DOMINANT_HAND' } fmt = [] for cat in barchart_categories: if cat not in barchart_map: raise KeyError("%s is not known" % cat) table_key = 'ag-%s-%s-biom' % (sample_type, cat) cat_path = opts['collapsed']['100nt']['1k'][table_key] fmt.append("%s:%s" % (barchart_map[cat], cat_path)) opts['barchart_categories'] = '"%s"' % ', '.join(fmt) return opts