Skip to content

Commit

Permalink
Merge pull request #72 from Eeeeelias/master
Browse files Browse the repository at this point in the history
Improve output visualisations
  • Loading branch information
Eeeeelias authored Sep 30, 2024
2 parents d06bdfa + d1bdaed commit ea38381
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
42 changes: 35 additions & 7 deletions container/domain/Process/nease_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,53 @@ def visualise_path(events, pathway, k):


def create_plot(terms, pvalues, cut_off, filename):
# plt.style.use('ggplot')
plt.barh(terms[::-1], pvalues[::-1])
plt.axvline(x=cut_off, color='r', linestyle='--')
plt.xlabel('-log10(adjusted p-value)')
plt.ylabel('Terms')
# explain the red line in the legend
plt.legend(['Cut-off', 'Adjusted p-value'])
# add line break to terms that are longer than 50 characters
terms = cut_long_terms(terms)

colors = ['#344552', '#355871', '#366B91', '#377DB0', '#448FC5', '#5E9FCD', '#78B0D5', '#92C0DD']
plt.figure(figsize=(12, 5))
plt.grid(color='#D2D2D2', linestyle='-', zorder=0)

plt.barh(terms[::-1], pvalues[::-1], color=colors[::-1], zorder=3)
plt.axvline(x=cut_off, color='red', linestyle='--', linewidth=1.5, zorder=5)
plt.ylabel("Terms", fontsize=12)
plt.xlabel("-log10(adjusted p-value)", fontsize=12)

plt.legend(['Cut-off', 'Adjusted p-value'], fontsize=10, frameon=True)

# Edit the spines for a cleaner look
ax = plt.gca()
ax.tick_params(bottom=False)
ax.tick_params(left=False)
ax.spines[['left', 'bottom']].set_color('#D2D2D2')
ax.spines[['left', 'bottom']].set_linewidth(2)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

plt.tight_layout()

plt.savefig(f"{filename}_thumb.jpg", bbox_inches='tight')
plt.savefig(f"{filename}.jpg", bbox_inches='tight', dpi=1200)
# flush the plot
plt.clf()
plt.close()


def cut_long_terms(terms):
cut_terms = []
for term in terms:
if len(term) > 50:
# find the first space after the 50th character
space_index = term.find(' ', 50)
if space_index == -1:
cut_terms.append(term)
else:
cut_terms.append(term[:space_index] + '\n' + term[space_index + 1:])
else:
cut_terms.append(term)
return cut_terms


def change_save_timing(run_id, days):
mapping = NeaseSaveLocationMapping.objects.get(run_id=run_id)
current_days_folder = mapping.get_number_of_saved_for_days()
Expand Down
23 changes: 16 additions & 7 deletions container/domain/nease/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,27 +522,36 @@ def stats_domains(affecting_percentage,
# pie chart parameters
ratios_pie = [affecting_percentage, 1 - affecting_percentage]
labels_pie = ['Affecting protein features', 'Not affecting any feature']
pie_colors = ['#1f78b4', '#fe7f0e']
pie_colors = ['#377DB0', '#E68A00']

ax1.set_facecolor('white')
ax1.pie(ratios_pie, labels=labels_pie, autopct='%1.1f%%', startangle=0, wedgeprops={'edgecolor': 'white'},
colors=pie_colors)
ax1.set_title("Genes with AS affecting protein features")
colors=pie_colors, textprops={'fontsize': 12, 'color': 'black'}) # Set font size and color for percentages
ax1.set_title("Genes with AS affecting protein features", fontsize=14)

ratios_bar = [round(elm_number / number_of_features, 2) * 100, round(pdb_number / number_of_features, 2) * 100,
round(domain_number / number_of_features, 2) * 100]

labels_bar = ['Linear motifs', 'Residues', 'Domains']

colors = ['#2ba8fc', '#2284c6', '#15547e']
colors = ['#344552', '#377DB0', '#92C0DD'][::-1]

ax2.set_facecolor('white')
ax2.barh(labels_bar, ratios_bar, color=colors)
ax2.set_xlim(0, 100)
ax2.set_title('Affected features')
ax2.set_title('Affected features', fontsize=14)

# Remove unnecessary spines and ticks, while keeping the clean look
ax2.tick_params(bottom=False)
ax2.tick_params(left=False)
ax2.spines[['left', 'bottom']].set_color('#D2D2D2')
ax2.spines[['left', 'bottom']].set_linewidth(2)
ax2.spines['right'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.grid(False)
ax2.yaxis.set_ticks_position('none')
ax2.spines[['right', 'top']].set_visible(False)
ax2.spines[['left', 'bottom']].set_visible(True)
ax2.xaxis.set_visible(False)

for i, v in enumerate(ratios_bar):
ax2.text(v + 1, i, f"{v:.1f}%", va='center', color='black', fontweight='bold')
Expand Down

0 comments on commit ea38381

Please sign in to comment.