Makie - Multi Sequence Alignment Scatterplot

Because you want your figure’s size to depend on the amount of data being shown, and also no “squishing” of the cells, that means your nucleotide cells should have a fixed size. That’s why it’s best to start from there, pick a size, and calculate the axis size that’s needed to contain that data in unsquished form. The function resize_to_layout! can correctly pick up this size to calculate the figure size so there’s no whitespace. Note that autolimitaspect and aspect have a different behavior, check this page https://makie.juliaplots.org/stable/tutorials/aspect-tutorial/ for reference.

msa_matrix = permutedims([
    '-' 'G' 'G' '-' 'C' 'T' 'T' 'G' 'C' 'T' 'T' 'A' 'T' 'T' 'G' 'T' '-' '-' 'G' 'T'
    '-' 'G' 'G' 'C' 'T' 'T' 'G' 'C' 'T' 'T' 'A' 'T' 'T' 'G' 'T' 'G' 'T' 'G' 'G' 'T'
    'C' 'G' 'G' '-' 'T' 'T' 'G' 'C' 'T' 'T' 'A' 'T' 'T' 'G' 'T' 'G' '-' '-' '-' 'T'
    'C' 'G' 'G' '-' 'T' 'T' 'G' 'C' 'T' 'T' 'A' 'T' 'T' 'G' 'T' 'G' '-' '-' 'T' '-'
])

levels = Dict(
    'A' => 1,
    'C' => 2,
    'G' => 3,
    'T' => 4,
    '-' => 5,
)

colormap = tuple.([:yellow, :blue, :green, :red, :magenta], 0.5)

cellsize = (20, 20)

f = Figure(fontsize = 12, backgroundcolor = :gray95)

axis_size = size(msa_matrix) .* cellsize

ax = Axis(
    f[1, 1],
    xgridvisible = false,
    ygridvisible = false,
    xticks = 1:size(msa_matrix, 1),
    yticks = (1:size(msa_matrix, 2), ["a", "b", "c", "d"]),
    yticksvisible = false,
    yreversed = true,
    width = axis_size[1],
    height = axis_size[2],
)

hidespines!(ax)

heatmap!(ax, [levels[m] for m in msa_matrix], colormap = colormap)
text!(ax, vec(string.(msa_matrix)),
    position = vec(Point2f.(Tuple.(CartesianIndices(msa_matrix)))),
    align = (:center, :center),
    textsize = 12,
)

resize_to_layout!(f)

f

And if I increase the size of the dataset:

The apparent text size difference is just due to scaling on this website.

7 Likes