From 9dfbf264a81610661c22ce37dc12ae28ef5ceb79 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Thu, 31 Oct 2019 10:22:24 -0700 Subject: [PATCH 1/2] MAINT: allow extracting specific metadata columns --- redbiom/commands/fetch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/redbiom/commands/fetch.py b/redbiom/commands/fetch.py index df11b45..a9a264b 100644 --- a/redbiom/commands/fetch.py +++ b/redbiom/commands/fetch.py @@ -62,16 +62,23 @@ def fetch_features_contained(context): @click.option('--tagged', is_flag=True, default=False, help=("Obtain the tag specific metadata (e.g., preparation " "information).")) +@click.option('--force-category', type=str, required=False, multiple=True, + help=("Force the output to include specific metadata variables " + "if the metadata variable was observed in any of the " + "samples. This can be specified mulitple times for " + "multiple categories.")) @click.argument('samples', nargs=-1) def fetch_sample_metadata(from_, samples, all_columns, context, output, - tagged): + tagged, force_category): """Retreive sample metadata.""" import redbiom.util iterator = redbiom.util.from_or_nargs(from_, samples) import redbiom.fetch + md, map_ = redbiom.fetch.sample_metadata(iterator, context=context, common=not all_columns, + restrict_to=force_category, tagged=tagged) md.to_csv(output, sep='\t', header=True, index=False, encoding='utf-8') From d4640cc6e5fb8770a6bfb7372249d5a84fc69d38 Mon Sep 17 00:00:00 2001 From: Daniel McDonald Date: Thu, 31 Oct 2019 10:35:57 -0700 Subject: [PATCH 2/2] Empty list to None --- redbiom/commands/fetch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/redbiom/commands/fetch.py b/redbiom/commands/fetch.py index a9a264b..27dbf6b 100644 --- a/redbiom/commands/fetch.py +++ b/redbiom/commands/fetch.py @@ -76,6 +76,9 @@ def fetch_sample_metadata(from_, samples, all_columns, context, output, import redbiom.fetch + if not force_category: + force_category = None + md, map_ = redbiom.fetch.sample_metadata(iterator, context=context, common=not all_columns, restrict_to=force_category,