diff --git a/src/sourmash/cli/plot.py b/src/sourmash/cli/plot.py index 0156d0f64..a548683c3 100644 --- a/src/sourmash/cli/plot.py +++ b/src/sourmash/cli/plot.py @@ -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( @@ -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( diff --git a/src/sourmash/commands.py b/src/sourmash/commands.py index 5bbcf818d..a1256e08e 100644 --- a/src/sourmash/commands.py +++ b/src/sourmash/commands.py @@ -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 + else: + display_labels = False + + if args.labels: if args.labeltext: labelfilename = args.labeltext else: @@ -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] if args.pdf: @@ -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) diff --git a/tests/test_sourmash.py b/tests/test_sourmash.py index 9d113a3c6..353837076 100644 --- a/tests/test_sourmash.py +++ b/tests/test_sourmash.py @@ -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)