Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions redbiom/commands/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,20 @@ def fetch_sample_metadata(from_, samples, all_columns, context, output,
help=("Resolve ambiguities that may be present in the samples "
"which can arise from, for example, technical "
"replicates."))
@click.option('--skip-taxonomy', is_flag=True, default=False, required=False,
help=("Do not resolve taxonomy on fetch. Setting this flag can "
"reduce the time required to complete a fetch"))
@click.argument('features', nargs=-1)
def fetch_samples_from_obserations(features, exact, from_, output,
context, md5, resolve_ambiguities):
context, md5, resolve_ambiguities,
skip_taxonomy):
"""Fetch sample data containing features."""
import redbiom.util
iterable = redbiom.util.from_or_nargs(from_, features)

import redbiom.fetch
tab, map_ = redbiom.fetch.data_from_features(context, iterable, exact)
tab, map_ = redbiom.fetch.data_from_features(context, iterable, exact,
skip_taxonomy=skip_taxonomy)

if md5:
tab, new_ids = redbiom.util.convert_biom_ids_to_md5(tab)
Expand Down Expand Up @@ -184,15 +189,19 @@ def fetch_samples_from_obserations(features, exact, from_, output,
help=("Resolve ambiguities that may be present in the samples "
"which can arise from, for example, technical "
"replicates."))
@click.option('--skip-taxonomy', is_flag=True, default=False, required=False,
help=("Do not resolve taxonomy on fetch. Setting this flag can "
"reduce the time required to complete a fetch"))
@click.argument('samples', nargs=-1)
def fetch_samples_from_samples(samples, from_, output, context, md5,
resolve_ambiguities):
resolve_ambiguities, skip_taxonomy):
"""Fetch sample data."""
import redbiom.util
iterable = redbiom.util.from_or_nargs(from_, samples)

import redbiom.fetch
table, ambig = redbiom.fetch.data_from_samples(context, iterable)
table, ambig = redbiom.fetch.data_from_samples(context, iterable,
skip_taxonomy=skip_taxonomy)

if md5:
table, new_ids = redbiom.util.convert_biom_ids_to_md5(table)
Expand Down
28 changes: 21 additions & 7 deletions redbiom/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def sample_metadata(samples, common=True, context=None, restrict_to=None,
return md, ambig_map


def data_from_features(context, features, exact):
def data_from_features(context, features, exact, skip_taxonomy=False):
"""Fetch sample data from an iterable of features.

Parameters
Expand All @@ -254,6 +254,9 @@ def data_from_features(context, features, exact):
exact : bool
If True, only samples in which all features exist are obtained.
Otherwise, all samples with at least one feature are obtained.
skip_taxonomy : bool, optional
If true, do not resolve taxonomy. This greatly reduces fetch time.
Default is false.

Returns
-------
Expand All @@ -275,10 +278,11 @@ def data_from_features(context, features, exact):
# determine the samples which contain the features of interest
samples = redbiom.util.ids_from(features, exact, 'feature', [context])

return _biom_from_samples(context, iter(samples), get=get)
return _biom_from_samples(context, iter(samples), get=get,
skip_taxonomy=skip_taxonomy)


def data_from_samples(context, samples):
def data_from_samples(context, samples, skip_taxonomy=False):
"""Fetch sample data from an iterable of samples.

Paramters
Expand All @@ -287,6 +291,9 @@ def data_from_samples(context, samples):
The name of the context to retrieve sample data from.
samples : Iterable of str
The samples of interest.
skip_taxonomy : bool, optional
If true, do not resolve taxonomy. This greatly reduces fetch time.
Default is false.

Returns
-------
Expand All @@ -296,10 +303,11 @@ def data_from_samples(context, samples):
A map of {sample_id_in_table: original_id}. This map can be used to
identify what samples are ambiguous based off their original IDs.
"""
return _biom_from_samples(context, samples)
return _biom_from_samples(context, samples, skip_taxonomy=skip_taxonomy)


def _biom_from_samples(context, samples, get=None, normalize_taxonomy=None):
def _biom_from_samples(context, samples, get=None, normalize_taxonomy=None,
skip_taxonomy=False):
"""Create a BIOM table from an iterable of samples

Parameters
Expand All @@ -312,6 +320,9 @@ def _biom_from_samples(context, samples, get=None, normalize_taxonomy=None):
A constructed get method.
normalize_taxonomy : list, optional
The ranks to normalize a lineage too (e.g., [k, p, c, o, f, g, s])
skip_taxonomy : bool, optional
If true, do not resolve taxonomy. This greatly reduces fetch time.
Default is false.

Returns
-------
Expand Down Expand Up @@ -374,8 +385,11 @@ def _biom_from_samples(context, samples, get=None, normalize_taxonomy=None):
for obs_id, value in col_data.items():
mat[unique_indices_map[obs_id], col] = value

lineages = taxon_ancestors(context, obs_ids, get,
normalize=normalize_taxonomy)
if skip_taxonomy:
lineages = None
else:
lineages = taxon_ancestors(context, obs_ids, get,
normalize=normalize_taxonomy)

if lineages is not None:
obs_md = [{'taxonomy': lineage} for lineage in lineages]
Expand Down