Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
byemaxx committed Sep 6, 2024
2 parents 99ce6ce + 62b0710 commit 9f5378e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 27 deletions.
6 changes: 6 additions & 0 deletions Docs/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version: 1.111.7
## Date: 2024-09-06
### Changes:
- Fix: Fixed the bug of when plot the heatmap of correlation, the rotation of x-axis and y-axis raise error.


# Version: 1.111.6
## Date: 2024-08-21
### Changes:
Expand Down
10 changes: 5 additions & 5 deletions metax/gui/main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4227,10 +4227,10 @@ def get_title_by_table_name(self, table_name):
if cluster:
df = self.delete_zero_columns(df)
self.show_message('Correlation is running, please wait...')
BasicPlot(self.tfa).plot_corr_sns(df=df, title_name=title_name, cluster= cluster,
BasicPlot(self.tfa, **self.heatmap_params_dict).plot_corr_sns(df=df, title_name=title_name, cluster= cluster,
width=width, height=height, font_size=font_size,
show_all_labels=show_all_labels, theme=theme, cmap=cmap,
rename_sample = rename_sample, **self.heatmap_params_dict)
rename_sample = rename_sample)

elif method == 'alpha_div':
self.show_message('Alpha diversity is running, please wait...')
Expand Down Expand Up @@ -5038,14 +5038,14 @@ def plot_co_expr(self, plot_type = 'network'):
self.checkBox_corr_hetatmap_show_all_labels_y.isChecked(),
)
cmap = self.comboBox_corr_hetatmap_cmap.currentText()
BasicPlot(self.tfa).plot_items_corr_heatmap(df=df,
BasicPlot(self.tfa, **self.heatmap_params_dict).plot_items_corr_heatmap(df=df,
title_name=f'Expression Correlation Heatmap({df_type})',
cluster=True,
cmap=cmap,
width=width, height=height,
font_size=font_size,
show_all_labels=show_all_labels,
**self.heatmap_params_dict)
show_all_labels=show_all_labels
)

except Exception as e:
error_message = traceback.format_exc()
Expand Down
5 changes: 3 additions & 2 deletions metax/peptide_annotator/pep_to_taxafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,16 @@ def proteins_to_taxa_func(self,protein_list: list ) -> dict:
pep_null = 'MGYG000000137_01815;MGYG000001639_01406;MGYG000000236_03945'
pep_no_species_level = "MGYG000000385;MGYG000002077;MGYG000003829"
pep_mag_level = 'MGYG000003142_02726;MGYG000003142_02725'
pep_t ='GCF_943193095.1-2283;concoct.103-megahit_28365_1'
### test data

if __name__ == '__main__':
import time
t1 = time.time()

db_path = 'C:/Users/Qing/Desktop/MetaX_Suite/metaX_dev_files/MetaX-human-gut_20231211.db'
db_path = 'metax_db.db'

pep2taxafunc = Pep2TaxaFunc(db_path = db_path, threshold = 1, genome_mode = True)
pep2taxafunc = Pep2TaxaFunc(db_path = db_path, threshold = 1, genome_mode = True, protein_genome_separator= "_")


# for i in [pep_no_species_level, pep_null, pep2, pep7, pep8, pep9, pep10, pep11]:
Expand Down
83 changes: 65 additions & 18 deletions metax/taxafunc_ploter/basic_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@
from .get_distinct_colors import GetDistinctColors

class BasicPlot:
def __init__(self, tfobj):
def __init__(self, tfobj,
linkage_method:str = 'average', distance_metric:str = 'correlation',
x_labels_rotation:int = 90, y_labels_rotation:int = 0):
self.tfa = tfobj
self.get_distinct_colors = GetDistinctColors().get_distinct_colors
self.assign_colors = GetDistinctColors().assign_colors
# for heatmap
self.linkage_method = linkage_method
self.distance_metric = distance_metric
self.x_labels_rotation = x_labels_rotation
self.y_labels_rotation = y_labels_rotation

# reset the style
plt.style.use('default')
sns.set_theme()



def plot_taxa_stats_pie(self, theme:str = 'Auto', res_type = 'pic', font_size = 12):
df = self.tfa.BasicStats.get_stats_peptide_num_in_taxa()

Expand Down Expand Up @@ -361,8 +368,6 @@ def plot_corr_sns(
theme: str = None,
cmap: str = "Auto",
rename_sample: bool = False,
linkage_method: str = "average",
distance_metric: str = "euclidean",
):
dft= df.copy()
if rename_sample:
Expand All @@ -387,17 +392,29 @@ def plot_corr_sns(
sns_params = {"linewidths":.01, "cmap":cmap, "cbar_kws":{ "shrink": 0.5},
'col_cluster':True if cluster else False,
'row_cluster':True if cluster else False,
'method':linkage_method,
'metric':distance_metric,
'method':self.linkage_method,
'metric':self.distance_metric,
"linecolor":(0/255, 0/255, 0/255, 0.01), "dendrogram_ratio":(.1, .2),"col_colors":color_list,
"figsize":(width, height), "xticklabels":True if show_all_labels[0] else "auto",
"yticklabels":True if show_all_labels[1] else 'auto'}
fig = sns.clustermap(corr, **sns_params)

fig.ax_col_dendrogram.set_title(f'Correlation of {title_name}', fontsize=font_size+2, fontweight='bold')
ax = fig.ax_heatmap
ax.set_xticklabels(ax.get_xticklabels(), fontsize=font_size, rotation=90)
ax.set_yticklabels(ax.get_yticklabels(), fontsize=font_size, rotation=0)

fig.ax_heatmap.set_xticklabels(
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = self.get_y_labels_va()
)

fig.ax_col_dendrogram.set_title(f'Correlation of {title_name}', fontsize=font_size+2, fontweight='bold')

cbar = fig.ax_heatmap.collections[0].colorbar
cbar.set_label('Intensity', rotation=90, labelpad=1)
Expand Down Expand Up @@ -594,8 +611,6 @@ def plot_items_corr_heatmap(
height=8,
font_size=10,
show_all_labels=(False, False),
linkage_method: str = "average",
distance_metric: str = "euclidean",
):
corr = df.copy()
# mask = np.triu(np.ones_like(corr, dtype=bool))
Expand All @@ -609,17 +624,33 @@ def plot_items_corr_heatmap(
sns_params = {"linewidths":.01, "cmap":cmap, "cbar_kws":{ "shrink": 0.5},
'col_cluster':True if cluster else False,
'row_cluster':True if cluster else False,
'method':linkage_method,
'metric':distance_metric,
'method':self.linkage_method,
'metric':self.distance_metric,
"linecolor":(0/255, 0/255, 0/255, 0.01), "dendrogram_ratio":(.1, .2),
"figsize":(width, height), "xticklabels":True if show_all_labels[0] else "auto",
"yticklabels":True if show_all_labels[1] else 'auto'}
fig = sns.clustermap(corr, **sns_params)

fig.ax_col_dendrogram.set_title(f'Correlation of {title_name}', fontsize=font_size+2, fontweight='bold')
ax = fig.ax_heatmap
ax.set_xticklabels(ax.get_xticklabels(), fontsize=font_size, rotation=90)
ax.set_yticklabels(ax.get_yticklabels(), fontsize=font_size, rotation=0)


fig.ax_col_dendrogram.set_title(f'Correlation of {title_name}', fontsize=font_size+2, fontweight='bold')
fig.ax_heatmap.set_xticklabels(
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = self.get_y_labels_va()
)

# hiend the x and y labels
fig.ax_heatmap.set_xlabel('')
fig.ax_heatmap.set_ylabel('')

cbar = fig.ax_heatmap.collections[0].colorbar
cbar.set_label("Correlation", rotation=90, labelpad=1)
Expand All @@ -634,3 +665,19 @@ def plot_items_corr_heatmap(
except Exception as e:
plt.close('all')
raise e


def get_x_labels_ha(self):
x_rotation = self.x_labels_rotation
if x_rotation > 0:
return 'right'
elif x_rotation < 0:
return 'left'
else:
return 'center'
def get_y_labels_va(self):
y_rotation = self.y_labels_rotation
if y_rotation >= 0:
return 'baseline'
else:
return 'top'
2 changes: 1 addition & 1 deletion metax/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.111.6'
__version__ = '1.111.7'
API_version = '2'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "MetaXTools"
version = "1.111.6"
version = "1.111.7"
description = "MetaXTools is a novel tool for linking peptide sequences with taxonomic and functional information in Metaproteomics."
readme = "README_PyPi.md"
license = { text = "NorthOmics" }
Expand Down

0 comments on commit 9f5378e

Please sign in to comment.