Skip to content

Commit 0ac72bd

Browse files
committed
Add AALogoPlot backend (checks, docu, tests are missing)
1 parent 87cc4d7 commit 0ac72bd

File tree

8 files changed

+450
-123
lines changed

8 files changed

+450
-123
lines changed

aaanalysis/_utils/utils_plot_parts.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def _add_part_bar(ax=None, start=1.0, len_part=40.0, color="blue", bar_height_fa
3232
ax.add_patch(bar)
3333

3434

35-
def _add_part_text(ax=None, text=None, start=1.0, len_part=10.0, fontsize=None, fontweight="normal"):
35+
def _add_part_text(ax=None, text=None, start=1.0, len_part=10.0, fontsize=None,
36+
fontweight="normal", height_factor=1.3):
3637
"""Place text marking for TMD and JMD sequence parts."""
3738
bar_height = _get_bar_height(ax=ax)
38-
y = _get_y(ax=ax, bar_height=bar_height, height_factor=1.3, reversed_weight=-1)
39+
y = _get_y(ax=ax, bar_height=bar_height, height_factor=height_factor, reversed_weight=-1)
3940
x = start + len_part / 2 # Middle of part
4041
ax.text(x, y, text,
4142
horizontalalignment='center',
@@ -88,14 +89,15 @@ def add_tmd_jmd_bar(ax=None, x_shift=0, jmd_color="blue", tmd_color="mediumsprin
8889

8990
def add_tmd_jmd_text(ax=None, x_shift=0, fontsize_tmd_jmd=None, weight_tmd_jmd="normal",
9091
name_tmd="TMD", name_jmd_n="JMD-N", name_jmd_c="JMD-C",
91-
tmd_len=20, jmd_n_len=10, jmd_c_len=10, start=1):
92+
tmd_len=20, jmd_n_len=10, jmd_c_len=10, start=1,
93+
height_factor=1.3):
9294
"""Add text labels for TMD and JMD regions."""
9395
pp = PlotPart(tmd_len=tmd_len, jmd_n_len=jmd_n_len, jmd_c_len=jmd_c_len, start=start)
9496
jmd_n_start, tmd_start, jmd_c_start = pp.get_starts(x_shift=x_shift)
9597
exists_jmd_n = jmd_n_len > 0
9698
exists_jmd_c = jmd_c_len > 0
9799
if fontsize_tmd_jmd is None or fontsize_tmd_jmd > 0:
98-
args = dict(ax=ax, fontsize=fontsize_tmd_jmd, fontweight=weight_tmd_jmd)
100+
args = dict(ax=ax, fontsize=fontsize_tmd_jmd, fontweight=weight_tmd_jmd, height_factor=height_factor)
99101
_add_part_text(start=tmd_start, len_part=tmd_len, text=name_tmd, **args)
100102
if exists_jmd_n:
101103
_add_part_text(start=jmd_n_start, text=name_jmd_n, len_part=jmd_n_len, **args)
@@ -131,11 +133,12 @@ def add_tmd_jmd_xticks(ax=None, x_shift=0, xtick_size=11.0, xtick_width=2.0, xti
131133

132134

133135
def highlight_tmd_area(ax=None, x_shift=0, tmd_color="mediumspringgreen", alpha=0.2,
134-
tmd_len=20, jmd_n_len=10, jmd_c_len=10, start=1):
136+
tmd_len=20, jmd_n_len=10, jmd_c_len=10, start=1, y_max=None):
135137
"""Highlight the TMD area in the plot."""
136138
pp = PlotPart(tmd_len=tmd_len, jmd_n_len=jmd_n_len, jmd_c_len=jmd_c_len, start=start)
137139
jmd_n_start, tmd_start, jmd_c_start = pp.get_starts(x_shift=x_shift)
138-
y_min, y_max = plt.ylim()
140+
y_min, _y_max = ax.get_ylim()
141+
y_max = _y_max if y_max is None else y_max
139142
height = abs(y_min) + y_max
140143
rect = mpl.patches.Rectangle((tmd_start, y_min), width=tmd_len, height=height, linewidth=0,
141144
color=tmd_color, zorder=0.1, clip_on=True, alpha=alpha)

aaanalysis/feature_engineering/_backend/cpp/cpp_plot_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def plot_profile(df_feat=None, df_cat=None, shap_plot=False,
127127
tmd_seq_color="black", jmd_seq_color="white",
128128
seq_size=None, fontsize_tmd_jmd=None, weight_tmd_jmd="normal",
129129
add_xticks_pos=False, highlight_tmd_area=True, highlight_alpha=0.15,
130-
add_legend_cat=True, dict_color=None,legend_kws=None,
130+
add_legend_cat=True, dict_color=None, legend_kws=None,
131131
bar_width=0.75, edge_color="none",
132132
grid_axis=None, ylim=None,
133133
xtick_size=11.0, xtick_width=2.0, xtick_length=5.0,

aaanalysis/feature_engineering/_backend/cpp/cpp_plot_ranking.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def _add_position_bars(ax=None, df_feat=None):
4040
for pos in positions:
4141
_add_pos_bars(ax=ax, x=pos - 1, y=y - 0.25)
4242

43+
4344
def _add_part_seq(ax=None, jmd_n_len=10, jmd_c_len=10, tmd_len=20, y=-0.75, height=0.2,
4445
tmd_color="mediumspringgreen", jmd_color="blue", alpha=1.0, start=0.0):
4546
"""Add colored box for sequence parts in figure"""
@@ -243,4 +244,4 @@ def plot_ranking(df_feat=None,
243244
ax.tick_params(which='major', axis="both", labelsize=fontsize_labels)
244245
if i > 0:
245246
ax.tick_params(which='major', axis="y", length=0, labelsize=0)
246-
return fig, axes
247+
return fig, axes

aaanalysis/feature_engineering/_cpp_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def profile(self,
701701
bar_width: Union[int, float] = 0.75,
702702
edge_color: Optional[str] = None,
703703
grid_axis: Optional[Literal['x', 'y', 'both']] = None,
704-
ylim: Tuple[float, float] = None,
704+
ylim: Optional[Tuple[float, float]] = None,
705705
xtick_size: Union[int, float] = 11.0,
706706
xtick_width: Union[int, float] = 2.0,
707707
xtick_length: Union[int, float] = 5.0,

aaanalysis/seq_analysis/_aalogo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ def _get_sequences(df_parts=None):
3333
return list_sequences
3434

3535

36+
# TODO refactor into backend, add checks, add docstring, tests
3637
# II Main function
3738
class AALogo:
3839
"""
3940
AALogo class for computing sequence logo matrices and conservation scores.
4041
"""
4142

42-
def __init__(self, logo_type="counts"):
43+
def __init__(self,
44+
logo_type: Literal["probability", "weight", "counts", "information"] = "counts"
45+
):
4346
list_to_type = ["probability", "weight", "counts", "information"]
4447
ut.check_str_options(name="to_type", val=logo_type, list_str_options=list_to_type)
4548
self._logo_type = logo_type

0 commit comments

Comments
 (0)