Skip to content

Commit b1bb6b0

Browse files
authored
MRG: support red, green, blue on ANI plot; fix upset stuff; bump version (#47)
* support red, green, blue on ANI plot; fix upset stuff; bump version * typo
1 parent a3a97aa commit b1bb6b0

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "sourmash_plugin_betterplot"
33
description = "sourmash plugin for improved plotting/viz and cluster examination."
44
readme = "README.md"
55
requires-python = ">=3.10"
6-
version = "0.4.3"
6+
version = "0.4.4"
77

88
dependencies = ["sourmash>=4.8.8,<5", "sourmash_utils>=0.2",
99
"matplotlib", "numpy", "scipy", "scikit-learn",

src/sourmash_plugin_betterplot.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import argparse
1010
import os
1111
import csv
12-
from collections import defaultdict
12+
from collections import defaultdict, Counter
1313
from itertools import chain, combinations
1414
import pickle
1515

@@ -1018,6 +1018,15 @@ def powerset(iterable, *, start=2):
10181018

10191019
notify(f"Loaded {len(siglist)} signatures & downsampled to scaled={scaled}")
10201020

1021+
names_check = [ ss.name for ss in siglist ]
1022+
if len(set(names_check)) != len(names_check):
1023+
notify("ERROR: duplicate names or sketches; please fix!!")
1024+
cnt = Counter(names_check)
1025+
for k, v in cnt.most_common():
1026+
if v > 1:
1027+
print(f"\t* {k} shows up {v} times")
1028+
sys.exit(-1)
1029+
10211030
# @CTB: check scaled, ksize, etc.
10221031

10231032
if not siglist:
@@ -1041,6 +1050,7 @@ def powerset(iterable, *, start=2):
10411050
truncate_name = lambda x: x[:truncate_at-3] + '...' if len(x) >= truncate_at else x
10421051
get_name = lambda x: [ truncate_name(ss.name) for ss in x ]
10431052
names = [ get_name(combo) for combo in pset ]
1053+
10441054
notify(f"powerset of distinct combinations: {len(pset)}")
10451055

10461056
# CTB: maybe turn the intersection code below into a class?
@@ -1511,6 +1521,12 @@ def __init__(self, subparser):
15111521
default=True)
15121522
subparser.add_argument('--ani', dest='detection',
15131523
action="store_false")
1524+
subparser.add_argument('--green-color',
1525+
help="color genomes with matching names green")
1526+
subparser.add_argument('--red-color',
1527+
help="color genomes with matching names red")
1528+
subparser.add_argument('--blue-color',
1529+
help="color genomes with matching names blue")
15141530

15151531
def main(self, args):
15161532
df = pd.read_csv(args.gather_csv)
@@ -1525,9 +1541,35 @@ def main(self, args):
15251541
notify(f"filtered down to {len(df)} rows with unique_intersect_bp >= {threshold}")
15261542

15271543
if args.detection:
1528-
plt.plot(df.f_match_orig, df.average_abund, '.')
1544+
plt.plot(df.f_match_orig, df.average_abund, 'k.')
15291545
else:
1530-
plt.plot(df.match_containment_ani, df.average_abund, '.')
1546+
plt.plot(df.match_containment_ani, df.average_abund, 'k.')
1547+
1548+
dfs = []
1549+
colors = []
1550+
if args.green_color:
1551+
df2 = df[df['match_name'].str.contains(args.green_color)]
1552+
notify(f"{len(df2)} matches to {args.green_color} => green circles")
1553+
dfs.append(df2)
1554+
colors.append('go')
1555+
if args.red_color:
1556+
df2 = df[df['match_name'].str.contains(args.red_color)]
1557+
notify(f"{len(df2)} matches to {args.red_color} => red crosses")
1558+
1559+
dfs.append(df2)
1560+
colors.append('r+')
1561+
if args.blue_color:
1562+
df2 = df[df['match_name'].str.contains(args.blue_color)]
1563+
notify(f"{len(df2)} matches to {args.blue_color} => blue triangles")
1564+
dfs.append(df2)
1565+
colors.append('bv')
1566+
1567+
for (df2, color) in zip(dfs, colors):
1568+
if args.detection:
1569+
plt.plot(df2.f_match_orig, df2.average_abund, color)
1570+
else:
1571+
plt.plot(df2.match_containment_ani, df2.average_abund, color)
1572+
15311573
ax = plt.gca()
15321574
ax.set_ylabel('number of copies')
15331575
ax.set_yscale('log')

0 commit comments

Comments
 (0)