Skip to content

Commit

Permalink
Merge pull request #112 from wasade/release_items
Browse files Browse the repository at this point in the history
Release items
  • Loading branch information
wasade authored Oct 1, 2021
2 parents be8f87c + b263de0 commit edca791
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion redbiom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# adapted from biom-format

__version__ = '0.3.5'
__version__ = '0.3.6'

# db version follows macro/minor/micro expectations where a micro change should
# be backwards compatible, a minor change introduces some backwards
Expand Down
23 changes: 13 additions & 10 deletions redbiom/commands/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def fetch_sample_metadata(from_, samples, all_columns, context, output,
if resolve_ambiguities and tagged:
click.echo("Cannot resolve ambiguities and fetch tagged metadata",
err=True)
click.exit(1)
import sys
sys.exit(1)

import redbiom.util
import redbiom.fetch
Expand Down Expand Up @@ -155,9 +156,9 @@ def fetch_samples_from_obserations(features, exact, from_, output,
f.write('\n'.join(['\t'.join(x) for x in new_ids.items()]))

if resolve_ambiguities == 'merge':
tab = redbiom.fetch._ambiguity_keep_most_reads(tab, map_)
elif resolve_ambiguities == 'most-reads':
tab = redbiom.fetch._ambiguity_merge(tab, map_)
elif resolve_ambiguities == 'most-reads':
tab = redbiom.fetch._ambiguity_keep_most_reads(tab, map_)

import h5py
with h5py.File(output, 'w') as fp:
Expand Down Expand Up @@ -199,25 +200,27 @@ def fetch_samples_from_samples(samples, from_, output, context, md5,
f.write('\n'.join(['\t'.join(x) for x in new_ids.items()]))

if resolve_ambiguities == 'merge':
table = redbiom.fetch._ambiguity_keep_most_reads(table, ambig)
elif resolve_ambiguities == 'most-reads':
table = redbiom.fetch._ambiguity_merge(table, ambig)
elif resolve_ambiguities == 'most-reads':
table = redbiom.fetch._ambiguity_keep_most_reads(table, ambig)

import h5py
with h5py.File(output, 'w') as fp:
table.to_hdf5(fp, 'redbiom')

_write_ambig(ambig, output)


def _write_ambig(map_, output):
has_ambig = {len(v) for v in map_.values()}
from collections import defaultdict
ambig = defaultdict(list)
for k, v in map_.items():
ambig[v].append(k)
ambig = {k: v for k, v in ambig.items() if len(v) > 1}

if has_ambig and has_ambig != set([1]):
if len(ambig) > 1:
import json
ambig = {k: v for k, v in map_.items() if len(v) > 1}
click.echo("%d sample ambiguities observed. Writing ambiguity "
"mappings to: %s" % (len(ambig), output + '.ambiguities'),
err=True)
with open(output + '.ambiguities', 'w') as fp:
fp.write(json.dumps(ambig))
fp.write(json.dumps(ambig, indent=2))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='redbiom',
version='0.3.5',
version='0.3.6',
license='BSD-3-Clause',
author='Daniel McDonald',
author_email='[email protected]',
Expand Down

0 comments on commit edca791

Please sign in to comment.