diff --git a/jcvi/graphics/landscape.py b/jcvi/graphics/landscape.py index b4657a7f..e2bbc909 100644 --- a/jcvi/graphics/landscape.py +++ b/jcvi/graphics/landscape.py @@ -25,6 +25,7 @@ from .base import ( CirclePolygon, Colormap, + Extent, Rectangle, adjust_extent, adjust_spines, @@ -822,9 +823,10 @@ def multilineplot(args): savefig(image_name, dpi=iopts.dpi, iopts=iopts) -def draw_heatmap( +def draw_heatmaps( fig, root, + root_extent: Extent, fastafile: str, chr: str, stacks: List[str], @@ -865,7 +867,9 @@ def draw_heatmap( cc = ca[0].upper() + cb root.add_patch(Rectangle((xx, yy), xlen, yinterval - inner, color=gray)) - ax = fig.add_axes((xx, yy, xlen, yinterval - inner)) + extent = (xx, yy, xlen, yinterval - inner) + adjusted = adjust_extent(extent, root_extent) + ax = fig.add_axes(adjusted) nbins, _ = get_nbins(clen, shift) @@ -875,7 +879,7 @@ def draw_heatmap( stackplot(ax, stackbins, nbins, palette, chr, window, shift) ax.text( - 0.1, + 0.05, 0.9, cc, va="top", @@ -966,11 +970,13 @@ def heatmap(args): heatmaps = opts.heatmaps.split(",") fig = plt.figure(1, (iopts.w, iopts.h)) - root = fig.add_axes((0, 0, 1, 1)) + root_extent = (0, 0, 1, 1) + root = fig.add_axes(root_extent) - draw_heatmap( + draw_heatmaps( fig, root, + root_extent, fastafile, chr, stacks, @@ -1088,10 +1094,10 @@ def stackplot( ax.set_axis_off() -def draw_stack( +def draw_stacks( fig, root, - root_extent, + root_extent: Extent, stacks: List[str], fastafile: str, window: int, @@ -1192,7 +1198,7 @@ def stack(args): root_extent = (0, 0, 1, 1) root = fig.add_axes(root_extent) - draw_stack( + draw_stacks( fig, root, root_extent, diff --git a/jcvi/projects/jcvi.py b/jcvi/projects/jcvi.py index 80003a4e..d9360700 100644 --- a/jcvi/projects/jcvi.py +++ b/jcvi/projects/jcvi.py @@ -14,9 +14,9 @@ from ..assembly.hic import draw_hic_heatmap from ..assembly.kmer import draw_ks_histogram from ..compara.pedigree import Pedigree, calculate_inbreeding -from ..graphics.base import load_image, normalize_axes, panel_labels, plt, savefig +from ..graphics.base import cm, load_image, normalize_axes, panel_labels, plt, savefig from ..graphics.chromosome import draw_chromosomes -from ..graphics.landscape import draw_multi_depth, draw_stack +from ..graphics.landscape import draw_multi_depth, draw_heatmaps, draw_stacks def diversity(args): @@ -116,7 +116,7 @@ def landscape(args): ax1_root = fig.add_axes((0, 1 / 4, 0.4, 0.5 * aspect_ratio)) ax2_root_extent = (0.4, 0.5, 0.6, 0.47) ax2_root = fig.add_axes(ax2_root_extent) - ax3_root_extent = (0.4, 0, 0.6, 0.47) + ax3_root_extent = (0.41, 0, 0.6, 0.47) ax3_root = fig.add_axes(ax3_root_extent) # Panel A @@ -136,16 +136,32 @@ def landscape(args): # Panel B logger.info("Plotting landscape of genomic features across the genome") - draw_stack( + stacks = ["Repeats", "Exons"] + heatmaps = ["Copia", "Gypsy", "Helitron", "hAT", "Exons"] + window = 250000 + shift = 50000 + draw_stacks( fig, ax2_root, ax2_root_extent, - ["Repeats", "Exons"], + stacks, fastafile, - window=250000, - shift=50000, + window, + shift, top=5, ) + draw_heatmaps( + fig, + ax3_root, + ax3_root_extent, + fastafile, + "Chr2", + stacks, + heatmaps, + window, + shift, + cmap=cm.viridis, + ) ax2_root.set_axis_off() ax3_root.set_axis_off() diff --git a/jcvi/utils/cbook.py b/jcvi/utils/cbook.py index ecf16ab3..66a09817 100644 --- a/jcvi/utils/cbook.py +++ b/jcvi/utils/cbook.py @@ -260,7 +260,7 @@ def human_size(size, a_kilobyte_is_1024_bytes=False, precision=1, target=None): return "{0:.{1}f}{2}".format(size, precision, suffix) -def autoscale(bp: int, optimal: int = 8): +def autoscale(bp: int, optimal: int = 6): """ Autoscale the basepair length to a more human readable number. The optimal is the number of ticks we want to see on the axis.