Skip to content

Commit

Permalink
Refactor to draw_geneticmap_heatmap()
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Apr 29, 2024
1 parent 33e0ae8 commit fca4a39
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions jcvi/assembly/geneticmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,32 +377,11 @@ def read_subsampled_matrix(mstmap: str, subsample: int) -> Tuple[np.ndarray, str
return M, markerbedfile, nmarkers


def heatmap(args):
def draw_geneticmap_heatmap(root, ax, mstmap: str, subsample: int):
"""
%prog heatmap map
Calculate pairwise linkage disequilibrium given MSTmap.
Draw the heatmap of the genetic map.
"""
p = OptionParser(heatmap.__doc__)
p.add_option(
"--subsample",
default=1000,
type="int",
help="Subsample markers to speed up",
)
opts, args, iopts = p.set_image_options(args, figsize="8x8")

if len(args) != 1:
sys.exit(not p.print_help())

(mstmap,) = args
M, markerbedfile, nmarkers = read_subsampled_matrix(mstmap, opts.subsample)

plt.rcParams["axes.linewidth"] = 0

fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes((0, 0, 1, 1))
ax = fig.add_axes((0.1, 0.1, 0.8, 0.8)) # the heatmap
M, markerbedfile, nmarkers = read_subsampled_matrix(mstmap, subsample)

# Plot chromosomes breaks
bed = Bed(markerbedfile)
Expand Down Expand Up @@ -447,7 +426,37 @@ def heatmap(args):
root.set_ylim(0, 1)
root.set_axis_off()

image_name = m + ".subsample" + "." + iopts.format

def heatmap(args):
"""
%prog heatmap map
Calculate pairwise linkage disequilibrium given MSTmap.
"""
p = OptionParser(heatmap.__doc__)
p.add_option(
"--subsample",
default=1000,
type="int",
help="Subsample markers to speed up",
)
opts, args, iopts = p.set_image_options(args, figsize="8x8")

if len(args) != 1:
sys.exit(not p.print_help())

(mstmap,) = args

plt.rcParams["axes.linewidth"] = 0

fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes((0, 0, 1, 1))
ax = fig.add_axes((0.1, 0.1, 0.8, 0.8)) # the heatmap

draw_geneticmap_heatmap(root, ax, mstmap, opts.subsample)

pf = mstmap.split(".")[0]
image_name = pf + ".subsample" + "." + iopts.format
savefig(image_name, dpi=iopts.dpi, iopts=iopts)


Expand Down

0 comments on commit fca4a39

Please sign in to comment.