-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmp3.jl
271 lines (184 loc) · 7.18 KB
/
tmp3.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
using Plots
using PlotPWM
#=
by
=#
function plt2chk(coords; xlim=(-60,60), ylim=(-0,2), arr_ratio=0.5)
_coords_ = deepcopy(coords)
total_width = xlim[2] - xlim[1]
adjusted_width = arr_ratio * total_width
# scale_width!(_coords_, adjusted_width)
# scale_height!(_coords_, arr_ratio * 1.0) # 1.0 is the original height
p = nothing
for i in eachindex(_coords_)
if i == 1
p = plot(_coords_[1].x, _coords_[1].y, seriestype = :shape, fillalpha=0.5, ylim=ylim, xlim=xlim,
legends=false,
size=(PlotPWM._width_factor_(12)*12, 220), fillcolor=:darkgray, linecolor=:black)
else
plot!(p, _coords_[i].x, _coords_[i].y, seriestype = :shape, fillalpha=0.5, fillcolor=:darkgray, linecolor=:black)
end
end
display(p)
end
function plot_shape(_coords_; xlim=(0, 10), ylim=(0,2))
p = nothing
for i in eachindex(_coords_)
if i == 1
p = plot(_coords_[1].x, _coords_[1].y, seriestype = :shape, fillalpha=0.5, ylim=ylim, xlim=xlim,
legends=false,
size=(PlotPWM._width_factor_(12)*12, 220), fillcolor=:darkgray, linecolor=:black)
else
plot!(p, _coords_[i].x, _coords_[i].y, seriestype = :shape, fillalpha=0.5, fillcolor=:darkgray, linecolor=:black)
end
end
return p
end
#=
Initially, coords initlized as Vector{shape};
It lies within the range of 0 and 2 in the y axis,
and lies within the range of 0 to some arbitrary point in the x axis
Note:
By default, make_in_between_basic makes a logo such that its hieght is in between 0 and 2
=#
mutable struct coords_matrix
# each column is a set of arrow-shapes that represented mode of distances between the pfms
coords_mat::Matrix{Vector{shape}} # Matrix of arrow-shapes;
function coords_matrix(mat::Matrix{T}, weights::AbstractVector) where T <: Real
@assert size(mat, 1) == length(weights) "The number of rows in mat should be equal to the length of weights"
coords_mat = map(x->make_in_between_basic(x; arrow_line_scale=log(x)), mat)
# TODO use weights to scale the inner height of the arrow-shapes in each column
# TODO also needs to translate it upwards (for "shorter" ones)
# TODO center align each arrow-shape in each column
# TODO place each column of arrow-shapes in the right positions
new(coords_mat)
end
end
coords = make_in_between_basic(11; arrow_line_scale=1.25)
# get_height(coords)
# scale_width!(coords, 45.0)
# scale_height!(coords, 2.0)
# scale_height!(coords, 2.0)
# scale_width!(coords, 2.0)
# y_substract!.(coords, 0.5)
# coords[1].y[1] = 22
# coords[1].y
# coords[2].y
# y_substract!(coords, 0.5)
# min_max_normalize_y!(coords)
# plt2chk(coords)
######################################
ds_mats = [12 6; 32 6]
weights = [0.7, 0.3]
#=
dist_cols:
=#
function make_arrow_shapes(ds_mats, weights, dist_cols::Int, pfms;
arrow_shape_scale_ratio=0.8, height_top=2.0)
coords_mat = map(x->make_in_between_basic(x; arrow_line_scale=1.0), ds_mats)
# scale the width of each arrow-shapes and
# get the number of columns for each "column"
num_cols_each = num_col_each_col!(coords_mat, dist_cols)
pfm_starts, d_starts = obtain_pfm_regions_and_dstarts(pfms, num_cols_each)
# shift heights
scaled_heights = weights .* height_top
scale_height!.(coords_mat, scaled_heights)
# centering
center_pts_x_orig = get_center_point_x.(coords_mat)
center_pts_y_orig = get_center_point_y.(coords_mat)
max_center_x = maximum(center_pts_x_orig, dims=1)
scale_width_height_by_proportion!.(coords_mat, arrow_shape_scale_ratio)
center_pts_x = get_center_point_x.(coords_mat)
center_pts_y = get_center_point_y.(coords_mat)
right_shift_pts = max_center_x .- center_pts_x
up_shift_pts = center_pts_y_orig .- center_pts_y
coords_mat = shift_right.(coords_mat, right_shift_pts)
coords_mat = shift_up.(coords_mat, up_shift_pts)
# shift the arrow-shapes upwards
height_increments = get_height_increments(scaled_heights)
for i in axes(coords_mat, 1)
for j in axes(coords_mat, 2)
coords_mat[i,j] = shift_up.(coords_mat[i,j], height_increments[i])
end
end
# shift right the arrow-shapes
for (ind, right_inc) in enumerate(d_starts)
coords_mat[:,ind] .= shift_right.((coords_mat[:,ind]), right_inc)
end
total_pfm_cols = size.(pfms,2) |> sum
total_d_cols = num_cols_each |> sum
return coords_mat, pfm_starts, total_pfm_cols, total_d_cols
end
using PlotPWM
pfm1 = [0.02 1.0 0.98 0.0 0.0 0.0 0.98 0.0 0.18 1.0
0.98 0.0 0.02 0.19 0.0 0.96 0.01 0.89 0.03 0.0
0.0 0.0 0.0 0.77 0.01 0.0 0.0 0.0 0.56 0.0
0.0 0.0 0.0 0.04 0.99 0.04 0.01 0.11 0.23 0.0]
pfm2 = [0.02 1.0 0.98 0.0 0.0 0.0 0.98 0.0 0.18 1.0
0.98 0.0 0.02 0.19 0.0 0.96 0.01 0.89 0.03 0.0
0.0 0.0 0.0 0.77 0.01 0.0 0.0 0.0 0.56 0.0
0.0 0.0 0.0 0.04 0.99 0.04 0.01 0.11 0.23 0.0]
pfm3 = [0.02 1.0 0.98 0.0 0.0 0.0 0.98 0.0 0.18 1.0
0.98 0.0 0.02 0.19 0.0 0.96 0.01 0.89 0.03 0.0
0.0 0.0 0.0 0.77 0.01 0.0 0.0 0.0 0.56 0.0
0.0 0.0 0.0 0.04 0.99 0.04 0.01 0.11 0.23 0.0]
pfms = [pfm1, pfm2, pfm3]
ds_mats = Float64.([12 6; 32 6; 35 14; 356 4])
weights = [0.3, 0.2, 0.3, 0.2]
ds_mats = [0 0; 1 1; 2 14]
weights = [0.5, 0.2, 0.3]
pfms = [pfm1, pfm2]
weights = [1.0]
ds_mats = [0.0;;]
using Plots
p = logoplot_with_arrow_gaps(pfms, ds_mats, weights)
savefig(p, "test.png")
save_logo_w_arrows(pfms, ds_mats, weights, "test.png")
pfms = [pfm1, pfm2]
ds_mats = zeros(1,1)
ds_mats[1,1] = 12
weights = [1.0]
p = logoplot_with_arrow_gaps(pfms, ds_mats, weights)
ds_mats = [12 6; 32 6; 35 14]
weights = [0.5, 0.2, 0.3]
ds_mats = [12 6; 32 6; 35 14; 356 4]
weights = [0.3, 0.2, 0.3, 0.2]
inds_sorted = sortperm(weights)
weights = weights[inds_sorted]
ds_mats = @view ds_mats[inds_sorted, :]
coords_mat, pfm_starts, total_pfm_cols, total_d_cols =
make_arrow_shapes(ds_mats, weights, 15, pfms;
arrow_shape_scale_ratio=0.7, height_top=1.7)
p = nothinglogo(total_pfm_cols + total_d_cols);
for (ind, pfm) in enumerate(pfms)
logo_x_offset = pfm_starts[ind]
logoplot!(p, pfm, PlotPWM.bg;
dpi=65,
setup_off=true,
logo_x_offset=logo_x_offset)
end
for col in eachcol(coords_mat)
arrowplot!(p, col)
end
p
# plot_shape(coords_mat[1,1]; xlim=(0, 10))
# plot_shape(coords_mat[2,1]; xlim=(0, 10))
# p1 = plot_shape(coords_mat[1,1]; xlim=(0, 100));
# p2 = plot_shape(coords_mat[2,1]; xlim=(0, 100));
# plot(p1)
# plot!(p2)
# # get the number of columns for each column
# scaled_heights
# sh = [1,5,3]
# cumsum(reverse(scaled_heights))
# plot_shape(coords_mat[1,1]; xlim=(0, 100))
# plot_shape(coords_mat[2,1]; xlim=(0, 100))
# #=
# get
# =#
# scale_height!(coords, 0.5)
# input_pfms = [pfm1, pfm2, pfm3]
# sum_num_columns(input_pfms) = size.(input_pfms, 2) |> sum
# ncols = sum_num_columns(input_pfms)
# given_len = ncols
# p = nothinglogo(2*ncols)