Skip to content

Commit

Permalink
Merge pull request #39 from RECETOX/fontsize
Browse files Browse the repository at this point in the history
Updated plotting library
  • Loading branch information
hechth authored Jul 19, 2024
2 parents c635372 + fb25636 commit aa5d174
Show file tree
Hide file tree
Showing 23 changed files with 88,088 additions and 1,195 deletions.
15 changes: 12 additions & 3 deletions analysis/Python_scripts/Fig3_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from plotting import *

matchms_scores = load_matchms_scores()
_, _, label_fontsize, tick_fontsize, text_width, _ = init()

df = normalize_df(matchms_scores, matches_norm_col=None)
del df['peak_comments']
Expand Down Expand Up @@ -36,12 +37,20 @@
corr = df[properties].corr().round(2)

plt.figure(figsize=(24, 20))
cax = sns.heatmap(corr, annot=True, cmap='coolwarm', center=0, vmin=-1, vmax=1,annot_kws={"size": 20})
cax = sns.heatmap(
corr,
annot=True,
cmap='coolwarm',
center=0,
vmin=-1,
vmax=1,
annot_kws={"size": label_fontsize}
)
# plt.title('Pearson Correlations')
plt.tick_params(axis='both', which='major', labelsize=20)
plt.tick_params(axis='both', which='major', labelsize=tick_fontsize)
# Get the colorbar from the HeatMap and set the fontsize for its tick labels
cbar = cax.collections[0].colorbar
cbar.ax.tick_params(labelsize=20)
cbar.ax.tick_params(labelsize=tick_fontsize)

plt.savefig("paper_plots/Fig3_correlations.png", bbox_inches='tight')
# plot name in the manuscript:
Expand Down
29 changes: 14 additions & 15 deletions analysis/Python_scripts/Fig4_superclass_histograms.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import pandas as pd
import os
import numpy as np
import math
from matplotlib import pyplot as plt
from rdkit import Chem
import plotly.graph_objs as go
from plotly.subplots import make_subplots

from utils import *
from plotting import *

_, _, label_fontsize, tick_fontsize, text_width, _ = init()

matchms_scores = load_matchms_scores()

matchms_scores_superclass = preprocess_data(normalize_df(matchms_scores.copy()), ["superclass"])
Expand All @@ -21,11 +17,13 @@
plt.clf()
plt.set_cmap('viridis')
plt.hist2d(matches_normalized * 100, matchms_scores['scores'] * 1000, bins=(5, 5), range=[[0, 100], [0, 1000]])
plt.colorbar()
cbar = plt.colorbar()
cbar.ax.tick_params(labelsize=tick_fontsize)

plt.clim(0, 70)
plt.xlabel('ions matching reference (%)', fontsize=20)
plt.ylabel('scores', fontsize=20)
plt.tick_params(labelsize=13)
plt.xlabel('ions matching reference (%)', fontsize=label_fontsize)
plt.ylabel('scores', fontsize=label_fontsize)
plt.tick_params(labelsize=tick_fontsize)
plt.gcf().set_size_inches(8, 6)
plt.savefig("paper_plots/Fig4a_superclasses_histogram.png", bbox_inches='tight')

Expand All @@ -43,12 +41,13 @@

plt.clf()
plt.set_cmap('viridis')
plt.hist2d(matchms_scores_top5['matches'], matchms_scores_top5['scores'] * 1000, bins=([0,1,2,3,4,5], 5))
plt.colorbar()
plt.hist2d(matchms_scores_top5['matches'], matchms_scores_top5['scores'] * 1000, bins=([0,1,2,3,4,5], 5), range=[[0, 5], [0, 1000]])
cbar = plt.colorbar()
cbar.ax.tick_params(labelsize=tick_fontsize)
plt.clim(0, 70)

plt.xlabel('ion matches', fontsize=20)
plt.ylabel('scores', fontsize=20)
plt.tick_params(labelsize=13)
plt.xlabel('ion matches', fontsize=label_fontsize)
plt.ylabel('scores', fontsize=label_fontsize)
plt.tick_params(labelsize=tick_fontsize)
plt.gcf().set_size_inches(8, 6)
plt.savefig("paper_plots/Fig4b_superclasses_histogram.png", bbox_inches='tight')
2 changes: 1 addition & 1 deletion analysis/Python_scripts/Fig6_benzene_subclasses_boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
for group in grouped_class.groups:
grp = grouped_class.get_group(group).groupby(grouping).filter(lambda x: len(x) > 6)
if len(grp) > 0 and group == "Benzene and substituted derivatives":
fig = create_plot(grp, grouping, showlegend=False, hide_labels=True)
fig = create_plot(grp, grouping, showlegend=False, hide_labels=False)
fig.savefig(f"paper_plots/Fig6_benzene_subclasses.png", bbox_inches='tight')
46 changes: 46 additions & 0 deletions analysis/Python_scripts/Fig9_comparisons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pandas as pd

from utils import *
from plotting import make_simple_boxplot

wang_db = pd.read_csv("../data/reference/13321_2020_470_MOESM1_ESM.csv")
wang_db_tms = pd.read_csv("../data/reference/wang2022_TMS_annotated.tsv", sep="\t", decimal=",")
df = normalize_df(load_matchms_scores())

wang_db["study"] = "Wang et al.$^{27}$"
wang_db_tms["study"] = "Wang et al.$^{28}$"
df["study"] = "This study"
cols = ["study", "Dot"]

combined = pd.concat([df.rename(columns={"scores": "Dot"})[cols], wang_db[cols], wang_db_tms[cols]])

make_simple_boxplot(combined, "study", "Dot", text_width=60).savefig("paper_plots/Fig9a_studies.png", bbox_inches='tight')


df_wang2020_db_with_classes = load_sdf_into_df("../data/reference/wang2020/3411.sdf")
wang_db_merged = df_wang2020_db_with_classes.set_index("inchikey").join(wang_db.set_index("Inchikey "))[["superclass","class","subclass","Dot"]].dropna()
order = [
"Lipids and lipid-like molecules",
"Organoheterocyclic compounds",
"Organic oxygen compounds",
"Organic acids and derivatives",
"Organic nitrogen compounds",
"Hydrocarbons"
]

make_simple_boxplot(wang_db_merged, x="superclass", y="Dot", order=order).savefig("paper_plots/Fig9b_wang2020.png", bbox_inches='tight')

df_wang2022_db_tms_with_classes = load_sdf_into_df("../data/reference/wang2022/3412.sdf")
wang_db_tms_merged = df_wang2022_db_tms_with_classes.set_index("inchikey").join(wang_db_tms.set_index("inchikey")["Dot"])[["superclass","class","subclass","Dot"]].dropna()
order = [
"Benzenoids",
"Lipids and lipid-like molecules",
"Organoheterocyclic compounds",
"Phenylpropanoids and polyketides",
"Organic oxygen compounds",
"Organic acids and derivatives",
"Organic nitrogen compounds",
"Organosulfur compounds",
"Organometallic compounds"
]
make_simple_boxplot(wang_db_tms_merged, x="superclass", y="Dot", order = order).savefig("paper_plots/Fig9c_wang2022.png", bbox_inches='tight')
954 changes: 929 additions & 25 deletions analysis/Python_scripts/comparisons.ipynb

Large diffs are not rendered by default.

43 changes: 17 additions & 26 deletions analysis/Python_scripts/entropy_plots.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit aa5d174

Please sign in to comment.