Skip to content

Commit

Permalink
ok I think this works
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Sep 28, 2023
1 parent cb34d7b commit ee70f5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/sourmash/cli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def subparser(subparsers):
help='output PDF; default is PNG'
)
subparser.add_argument(
'--labels', action='store_true', default=False,
'--labels', action='store_true', default=None,
help='show sample labels on dendrogram/matrix'
)
subparser.add_argument(
Expand All @@ -22,7 +22,7 @@ def subparser(subparsers):
help='filename containing list of labels (overrides signature names); implies --labels'
)
subparser.add_argument(
'--indices', action='store_true', default=True,
'--indices', action='store_true', default=None,
help='show sample indices but not labels; overridden by --labels'
)
subparser.add_argument(
Expand Down
25 changes: 18 additions & 7 deletions src/sourmash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,22 @@ def plot(args):
# not sure how to change this to use f-strings
notify('...got {} x {} matrix.', *D.shape)

if args.labels or args.labeltext:
# see sourmash#2790 for details :)
if args.labeltext or args.labels:
display_labels = True
args.labels = True # override => labels always true
elif args.labels is None and not args.indices:
# default to labels
args.labels = True
display_labels = True
elif args.indices or (not args.labels and args.indices is None):
# turn on indices only, not label names
args.indices = True
display_labels = True

Check warning on line 266 in src/sourmash/commands.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/commands.py#L265-L266

Added lines #L265 - L266 were not covered by tests
else:
display_labels = False

Check warning on line 268 in src/sourmash/commands.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/commands.py#L268

Added line #L268 was not covered by tests

if args.labels:
if args.labeltext:
labelfilename = args.labeltext
else:
Expand All @@ -268,11 +282,8 @@ def plot(args):
elif args.indices:
# construct integer labels
labeltext = [str(i) for i in range(D.shape[0])]
args.labels = True
else:
assert not args.labels
assert not args.indices
assert not args.labeltext
assert not display_labels
labeltext = [""] * D.shape[0]

Check warning on line 287 in src/sourmash/commands.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/commands.py#L286-L287

Added lines #L286 - L287 were not covered by tests

if args.pdf:
Expand Down Expand Up @@ -320,13 +331,13 @@ def plot(args):
### do clustering
Y = sch.linkage(D, method='single')
sch.dendrogram(Y, orientation='right', labels=labeltext,
no_labels=not args.labels)
no_labels=not display_labels)
fig.savefig(dendrogram_out)
notify(f'wrote dendrogram to: {dendrogram_out}')

### make the dendrogram+matrix:
(fig, rlabels, rmat) = sourmash_fig.plot_composite_matrix(D, labeltext,
show_labels=args.labels,
show_labels=display_labels,
vmin=args.vmin,
vmax=args.vmax,
force=args.force)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ def test_plot_reordered_labels_csv(runtmp):
c.run_sourmash('compare', '-k', '31', '-o', 'cmp', ss2, ss47, ss63)
c.run_sourmash('plot', 'cmp', '--csv', 'neworder.csv')

print(open(c.output('neworder.csv'), 'rt').read())

with open(c.output('neworder.csv'), newline="") as fp:
r = csv.DictReader(fp)

Expand Down

0 comments on commit ee70f5f

Please sign in to comment.