Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize plots for paper #19

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added analysis/Python_scripts/boxplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added analysis/Python_scripts/boxplot_Benzenoids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 112 additions & 29 deletions analysis/Python_scripts/chemical_composition_boxplot.ipynb

Large diffs are not rendered by default.

Binary file modified analysis/Python_scripts/chemical_composition_boxplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified analysis/Python_scripts/chemical_composition_boxplot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified analysis/Python_scripts/chemical_composition_boxplot2_N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified analysis/Python_scripts/chemical_composition_boxplot_N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
418 changes: 418 additions & 0 deletions analysis/Python_scripts/classes_boxplot.ipynb

Large diffs are not rendered by default.

115 changes: 0 additions & 115 deletions analysis/Python_scripts/deprecated/classes_boxplot.ipynb

This file was deleted.

45 changes: 19 additions & 26 deletions analysis/Python_scripts/plotting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
Expand Down Expand Up @@ -83,56 +84,48 @@ def plot_histogram(x, xaxis_title='', title=''):
# Display the plot
fig.show()

def create_plot(df, path):
def create_plot(df, path, grouping_column):
sns.set_style(style='white')
plt.figure(figsize=(17, 5))

# Set the color palette
colors = ['yellow', 'deepskyblue']
sns.set_palette(sns.color_palette(colors))

ax = sns.boxplot(x="true_names", y="value", hue="Number",
ax = sns.boxplot(x=grouping_column, y="value", hue="Number",
data=df, hue_order=['CosineHungarian_0.01_0.0_1.0_matches',np.nan],
medianprops={'color': 'darkgreen', 'linewidth': 4.0},
flierprops={'marker': 'o', 'markersize': 10, 'markerfacecolor': 'none'}) # RUN PLOT
ax2 = ax.twinx()

sns.boxplot(ax=ax2,x='true_names', y='value', hue='Number',
sns.boxplot(ax=ax2,x=grouping_column, y='value', hue='Number',
data=df, hue_order=[np.nan, 'CosineHungarian_0.01_0.0_1.0_scores'],
medianprops={'color': 'b', 'linewidth': 4.0},
flierprops={'marker': 'o', 'markersize': 10, 'markerfacecolor': 'none'})

ax.legend_.remove()
ax.set_ylim([0, 5]) # Set y-axis limits
ax.yaxis.set_major_locator(plt.MultipleLocator(1)) # Set major tick marks
ax.set_ylabel('Match values') # Set y-axis label
ax.yaxis.label.set_size(20) # Set font size of y-axis label
# ax.set_ylim([0, 5]) # Set y-axis limits
# ax.yaxis.set_major_locator(plt.MultipleLocator(1)) # Set major tick marks
ax.set_ylabel('Match values', fontsize=20) # Set y-axis label
ax.set_xlabel('Chemical composition', fontsize=20) # Set x-axis label and font size
ax.tick_params(axis='x', labelsize=13) # Set font size of x-axis tick labels
ax.tick_params(axis='y', labelsize=13) # Set font size of y-axis tick labels
ax.yaxis.labelpad = 10
ax.xaxis.labelpad = 10
# ax.tick_params(axis='y', labelsize=13) # Set font size of y-axis tick labels
# ax.yaxis.labelpad = 10

# Create a count for each x-axis label
count_data = df['true_names'].value_counts().reset_index()
count_data.columns = ['true_names', 'count']
count_data = count_data.sort_values(by=['true_names'])
count_data['count'] = count_data['count'] // 2
count_data = df[grouping_column].value_counts()

# Remove the original x-axis labels
ax.set_xticklabels([])

# Add the count labels to the x-axis
ax.set_xticks(np.arange(len(count_data)))
ax.set_xticklabels(count_data['true_names'] + ' (' + count_data['count'].astype(str) + ')', rotation=45, ha='right')
# # Add the count labels to the x-axis
xlabels = [label.get_text() for label in ax.get_xticklabels()]
xlabels = ['\n'.join(textwrap.wrap(label + ' (' + str((count_data.loc[label] //2 )) + ')', width=25)) for label in xlabels]
ax.set_xticklabels(xlabels, rotation=45, ha='right')

ax2.legend_.remove()
ax2.set_ylim([0, 1]) # Set y-axis limits
ax2.yaxis.set_major_locator(plt.MultipleLocator(0.2)) # Set major tick marks
ax2.set_ylabel('Score values') # Set y-axis label
ax2.yaxis.label.set_size(20) # Set font size of y-axis label
ax2.tick_params(axis='y', labelsize=12) # Set font size of y-axis tick labels
ax2.yaxis.labelpad = 10
# ax2.set_ylim([0, 1]) # Set y-axis limits
# ax2.yaxis.set_major_locator(plt.MultipleLocator(0.2)) # Set major tick marks
ax2.set_ylabel('Score values', fontsize=20) # Set y-axis label
ax2.tick_params(axis='y', labelsize=13) # Set font size of y-axis tick labels
# ax2.yaxis.labelpad = 10

# Change the legend labels
handles, labels = ax.get_legend_handles_labels()
Expand Down
Binary file modified analysis/Python_scripts/scatter_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
980 changes: 656 additions & 324 deletions analysis/Python_scripts/scatterplot.ipynb

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions analysis/Python_scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def has_atom(mol, atom):
def has_organic_atoms(mol):
# Check if the molecule contains any halogen atoms
for atom in mol.GetAtoms():
if atom.GetSymbol() in ['C', 'O', 'N', 'H']:
if atom.GetSymbol() in ['C', 'O', 'H']:
return True

return False
Expand All @@ -47,7 +47,7 @@ def append_classes(df, left_on):
"S": [has_atom(m, 'S') for m in molecules],
"P": [has_atom(m, 'P') for m in molecules],
"Si": [has_atom(m, 'Si') for m in molecules],
"C,O,N,H": [has_organic_atoms(m) for m in molecules],
"C,O,N,H": [has_organic_atoms(m) or has_atom(m, 'N') for m in molecules],
"N": [has_atom(m, 'N') for m in molecules],
})
merged_df = pd.merge(df, class_names, left_on=left_on, right_on='molname')
Expand Down Expand Up @@ -81,21 +81,23 @@ def generate_combinations(df, column_name):

return pd.DataFrame(new_rows).reset_index(drop=True)

def preprocess_data(merged_top5_same):
def preprocess_data(merged_top5_same, cols_to_keep):
key_cols = ['query', 'reference'] + cols_to_keep
# Concatenate the DataFrames in df1_list and add a 'value' column with the value 'matches'.
df1 = merged_top5_same[['query', 'reference', 'true_names', 'CosineHungarian_0.01_0.0_1.0_matches']].copy()
df1 = merged_top5_same[key_cols + ['CosineHungarian_0.01_0.0_1.0_matches']].copy()

# Concatenate the DataFrames in df2_list and add a 'value' column with the value 'scores'.
df2 = merged_top5_same[['query', 'reference', 'true_names', 'CosineHungarian_0.01_0.0_1.0_scores']].copy()
df2 = merged_top5_same[key_cols + ['CosineHungarian_0.01_0.0_1.0_scores']].copy()

# Concatenate df1 and df2 into a single DataFrame.
df_cat = pd.concat([df1, df2])

mdf = pd.melt(df_cat, id_vars=['query', 'reference', 'true_names'], var_name=['Number']) # MELT
mdf = pd.melt(df_cat, id_vars=key_cols, var_name='Number') # MELT
mdf = mdf.dropna()
return mdf

#cleaning data
def clean_chemical_composition_data(mdf):
mdf = split_and_add_rows(mdf, 'true_names', split_by=', C,O,N,H')
mdf['true_names'] = mdf['true_names'].replace('', np.nan)
mdf = mdf.dropna(subset=['value', 'true_names'])

mdf = mdf.dropna()
return mdf