Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] clear to eol in notify(...) and error(...) #351

Merged
merged 9 commits into from
Mar 12, 2018
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
23 changes: 15 additions & 8 deletions sourmash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def compute(args):
error('bad ksizes: {}', ", ".join(bad_ksizes))
sys.exit(-1)

notify('Computing a total of {} signatures.', num_sigs)
notify('Computing a total of {} signature(s).', num_sigs)

if num_sigs == 0:
error('...nothing to calculate!? Exiting!')
Expand Down Expand Up @@ -235,8 +235,8 @@ def save_siglist(siglist, output_fp, filename=None):

siglist += build_siglist(Elist, filename, name=record.name)

notify('calculated {} signatures for {} sequences in {}'.\
format(len(siglist), n + 1, filename))
notify('calculated {} signatures for {} sequences in {}',
len(siglist), n + 1, filename)
else:
# make minhashes for the whole file
Elist = make_minhashes()
Expand All @@ -253,16 +253,17 @@ def save_siglist(siglist, output_fp, filename=None):

add_seq(Elist, record.sequence,
args.input_is_protein, args.check_sequence)
notify('')

notify('...{} {} sequences', filename, n, end='')

sigs = build_siglist(Elist, filename, name)
if args.output:
siglist += sigs
else:
siglist = sigs

notify('calculated {} signatures for {} sequences in {}'.\
format(len(siglist), n + 1, filename))
notify('calculated {} signatures for {} sequences in {}',
len(sigs), n + 1, filename)

if not args.output:
save_siglist(siglist, args.output, sigfile)
Expand All @@ -273,19 +274,25 @@ def save_siglist(siglist, output_fp, filename=None):
# make minhashes for the whole file
Elist = make_minhashes()

total_seq = 0
for filename in args.filenames:
# consume & calculate signatures
notify('... reading sequences from {}', filename)

for n, record in enumerate(screed.open(filename)):
if n % 10000 == 0 and n:
notify('\r... {} {}', filename, n, end='')

add_seq(Elist, record.sequence,
args.input_is_protein, args.check_sequence)
notify('... {} {} sequences', filename, n + 1)

total_seq += n + 1

siglist = build_siglist(Elist, filename, name=args.merge)
notify('calculated {} signatures for {} sequences taken from {}'.\
format(len(siglist), n + 1, " ".join(args.filenames)))
notify('calculated {} signatures for {} sequences taken from {} files',
len(siglist), total_seq, len(args.filenames))

# at end, save!
save_siglist(siglist, args.output)

Expand Down
2 changes: 2 additions & 0 deletions sourmash/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def notify(s, *args, **kwargs):
if _quiet:
return

print(u'\r\033[K', end=u'', file=sys.stderr)
print(s.format(*args, **kwargs), file=sys.stderr,
end=kwargs.get('end', u'\n'))
if kwargs.get('flush'):
Expand All @@ -29,6 +30,7 @@ def notify(s, *args, **kwargs):

def error(s, *args, **kwargs):
"A simple error logging function => stderr."
print(u'\r\033[K', end=u'', file=sys.stderr)
print(s.format(*args, **kwargs), file=sys.stderr)
if kwargs.get('flush'):
sys.stderr.flush()
Expand Down
1 change: 1 addition & 0 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_do_sourmash_compute_output_and_name_valid_file():
in_directory=location)

assert os.path.exists(sigfile)
assert 'calculated 1 signatures for 4 sequences taken from 3 files' in err

# is it valid json?
import json
Expand Down