Skip to content

Commit

Permalink
Merge pull request #48 from AlexandrovLab/4608_text
Browse files Browse the repository at this point in the history
Upgrade v1.3.23: Update SBS4608 custom_text_upper, custom_text_lower,…
  • Loading branch information
mdbarnesUCSD authored May 10, 2024
2 parents 941e5d4 + 3b8618e commit dbe0f27
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 81 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def readme():
return f.read()


VERSION = "1.3.22"
VERSION = "1.3.23"


def write_version_py(filename="sigProfilerPlotting/version.py"):
Expand All @@ -23,7 +23,7 @@ def write_version_py(filename="sigProfilerPlotting/version.py"):
# THIS FILE IS GENERATED FROM SIGPROFILERPLOTTING SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
update = 'Upgrade v1.3.22: Update input_processing index.name handling to be more robust.'
update = 'Upgrade v1.3.23: Update SBS4608 custom_text_upper, custom_text_lower, custom_text_middle.'
"""
fh = open(filename, "w")
Expand Down
132 changes: 53 additions & 79 deletions sigProfilerPlotting/sigProfilerPlotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def process_input(matrix_path, plot_type):
data = data.set_index(MUTTYPE, drop=True)
# the first column is non-MUTTYPE and non-integer
elif not data.iloc[:, 0].apply(lambda x: isinstance(x, int)).all():
data.rename(columns={data.columns[0]: MUTTYPE}, inplace=True)
data = data.set_index(data.columns[0], drop=True)
data.rename(columns={data.columns[0]: MUTTYPE}, inplace=True)
data = data.set_index(data.columns[0], drop=True)
else:
data = data.reset_index()
data.rename(columns={data.columns[0]: MUTTYPE}, inplace=True)
Expand All @@ -198,7 +198,8 @@ def process_input(matrix_path, plot_type):
data.index = get_context_reference(plot_type)
else:
raise ValueError(
"ERROR: matrix_path requires pd.DataFrame, path to file, or np.ndarray, not " + f"{type(matrix_path)}."
"ERROR: matrix_path requires pd.DataFrame, path to file, or np.ndarray, not "
+ f"{type(matrix_path)}."
)

if data.isnull().values.any():
Expand Down Expand Up @@ -7024,86 +7025,59 @@ def plotSBS(
except:
custom_text_bottom = False

if custom_text_upper:
plot_custom_text = True
if len(custom_text_upper[sample_count]) > 40:
print(
"To add a custom text, please limit the string to <40 characters including spaces."
)
plot_custom_text = False
if custom_text_middle:
if len(custom_text_middle[sample_count]) > 40:
print(
"To add a custom text, please limit the string to <40 characters including spaces."
)
plot_custom_text = False
x_pos_custom = 0.85
y_pos_upper = 0.125
y_pos_middle = 0.10
y_pos_bottom = 0.075
zorder_value = 10

if plot_custom_text:
x_pos_custom = 0.94
if custom_text_upper and custom_text_middle:
custom_text_upper_plot = (
custom_text_upper[sample_count]
+ "\n"
+ custom_text_middle[sample_count]
)
if custom_text_bottom:
custom_text_upper_plot += (
"\n" + custom_text_bottom[sample_count]
)
fontsize_custom = 25
fontweight_custom = "bold"
fontcolor_custom = ("black")
fontname_custom = "Arial"
ha_custom = "left"

if custom_text_upper and not custom_text_middle:
custom_text_upper_plot = custom_text_upper[sample_count]
panel2.text(
x_pos_custom,
0.78,
custom_text_upper_plot,
fontsize=40,
weight="bold",
color="black",
fontname="Arial",
transform=plt.gcf().transFigure,
ha="right",
)
if custom_text_upper:
plt.text(
x_pos_custom,
y_pos_upper,
custom_text_upper[sample_count],
fontsize=fontsize_custom,
weight=fontweight_custom,
color=fontcolor_custom,
fontname=fontname_custom,
transform=plt.gcf().transFigure,
ha=ha_custom,
zorder=zorder_value,
)

elif custom_text_upper and custom_text_middle:
if not custom_text_bottom:
panel2.text(
x_pos_custom,
0.86,
custom_text_upper_plot,
fontsize=40,
weight="bold",
color="black",
fontname="Arial",
transform=plt.gcf().transFigure,
ha="right",
)
else:
panel2.text(
x_pos_custom,
0.835,
custom_text_upper_plot,
fontsize=40,
weight="bold",
color="black",
fontname="Arial",
transform=plt.gcf().transFigure,
ha="right",
)
if custom_text_middle:
plt.text(
x_pos_custom,
y_pos_middle,
custom_text_middle[sample_count],
fontsize=fontsize_custom,
weight=fontweight_custom,
color=fontcolor_custom,
fontname=fontname_custom,
transform=plt.gcf().transFigure,
ha=ha_custom,
zorder=zorder_value,
)

elif not custom_text_upper and custom_text_middle:
custom_text_upper_plot = custom_text_middle[sample_count]
panel2.text(
x_pos_custom,
0.78,
custom_text_upper_plot,
fontsize=40,
weight="bold",
color="black",
fontname="Arial",
transform=plt.gcf().transFigure,
ha="right",
)
if custom_text_bottom:
plt.text(
x_pos_custom,
y_pos_bottom,
custom_text_bottom[sample_count],
fontsize=fontsize_custom,
weight=fontweight_custom,
color=fontcolor_custom,
fontname=fontname_custom,
transform=plt.gcf().transFigure,
ha=ha_custom,
zorder=zorder_value,
)

# Plot the sample name in upper left corner of plot
if sig_probs:
Expand Down

0 comments on commit dbe0f27

Please sign in to comment.