Skip to content

Commit 820057b

Browse files
committed
Fix import; add option to show enrichment in plotpup.py
1 parent 24f67f4 commit 820057b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

coolpuppy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from .coolpup import *
2+
from .plotpup import *

coolpuppy/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ def plotpuppy():
420420
parser.add_argument('--row_names', type=str,
421421
required=False,
422422
help="""A comma separated list of row names""")
423+
parser.add_argument("--enrichment", type=int,
424+
required=False, default=1,
425+
help="""Whether to show the level of enrichment in the
426+
central pixels. 0 to not show, odd positive number to
427+
define the size of the central square which values are
428+
averaged.""")
423429
# parser.add_argument("--n_rows", type=int, default=0,
424430
# required=False,
425431
# help="""How many rows to use for plotting the data""")
@@ -461,6 +467,10 @@ def plotpuppy():
461467
raise ValueError("""Number of row names is not equal to number of
462468
rows!""")
463469

470+
if args.enrichment %2 == 0 and args.enrichment > 0:
471+
raise ValueError("""Side of the square to calculate enrichment has
472+
to be an odd number""")
473+
464474
f, axarr = plt.subplots(n_rows, n_cols, sharex=True, sharey=True,# similar to subplot(111)
465475
figsize=(max(3.5, n_cols+0.5), max(3, n_rows)),
466476
dpi=300, squeeze=False,
@@ -485,6 +495,11 @@ def plotpuppy():
485495
cmap=args.cmap)
486496
ax.set_xticks([])
487497
ax.set_yticks([])
498+
if args.enrichment > 0:
499+
enr = get_enrichment(pups[n], args.enrichment, 2)
500+
ax.text(s=enr, y=0.95, x=0.05, ha='left', va='top',
501+
size='x-small',
502+
transform = ax.transAxes)
488503
else:
489504
axarr[i, j].axis('off')
490505

coolpuppy/plotpup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
def normCis(amap, i=3):
88
return amap/np.nanmean((amap[0:i, 0:i]+amap[-i:, -i:]))*2
99

10-
def get_enrichment(amap, n):
10+
def get_enrichment(amap, n, dec=2):
1111
c = int(np.floor(amap.shape[0]/2))
12-
return np.nanmean(amap[c-n//2:c+n//2+1, c-n//2:c+n//2+1])
12+
return np.round(np.nanmean(amap[c-n//2:c+n//2+1, c-n//2:c+n//2+1]),
13+
decimals=dec)
1314

1415
def auto_rows_cols(n):
1516
rows = int(np.ceil(np.sqrt(n)))

0 commit comments

Comments
 (0)