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

upate #3

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![banner](assets/FBMN-STATS-GUIed_logo2.png)

[![Open in Statistics App!](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://metabolomics-statistics.streamlit.app/)
[![Open in Statistics App!](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://fbmn-stats.streamlit.app/)

A web app implementation of the [statistics notebooks](https://github.com/Functional-Metabolomics-Lab/Statistical-analysis-of-non-targeted-LC-MSMS-data) for metabolomics by the [Functional Metabolomics Lab](https://github.com/Functional-Metabolomics-Lab). These notebooks are developed by the Virtual Multi Omics Lab ([VMOL](https://vmol.org/)).

Expand Down
2 changes: 1 addition & 1 deletion pages/4_Hierarchical_Clustering_&_Heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
with st.expander("📖 About"):
st.markdown(
"""
Hierarchical clustering analysis (HCA) is a popular unsupervised machine learning technique used for grouping data points based on their similarities. In this method, the data is organized in a tree-like structure or dendrogram, where each branch represents a cluster of data points with similar features. The clustering process starts with each data point being considered as a separate cluster, and then iteratively combines similar clusters until all the data points are in a single cluster.
Hierarchical clustering analysis (HCA) is a popular unsupervised technique used for grouping data points based on their similarities. In this method, the data is organized in a tree-like structure or dendrogram, where each branch represents a cluster of data points with similar features. The clustering process starts with each data point being considered as a separate cluster, and then iteratively combines similar clusters until all the data points are in a single cluster.

The clustering relies on a distance matrix 'distm', calculated from the feature quantification table (submitted during the data preparation stage), using a specific distance metric (e.g., Euclidean, Canberra). By default, we use Euclidean distance. Another important factor is the linkage method, which measures the distance between these clusters (e.g., complete, single, average). Our default choice uses the 'complete' method, it calculates the maximum distance between clusters before merging them. Currently, users do not have the option to adjust the distance metric or linkage method. Following HCA, a dendrogram is produced, showing the distances (or 'heights') at which clusters merge or split along the y-axis. The dendrogram offers insights into the clustering process and the relationships between data points. There are a lot of [good videos](https://www.youtube.com/watch?v=7xHsRkOdVwo) and resources out there explaining very well the principle behind clustering.

Expand Down
8 changes: 4 additions & 4 deletions pages/6_Parametric_assumptions_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
help="Select two options.",
)
if st.session_state.test_attribute and len(st.session_state.test_options) == 2:
tabs = st.tabs(["📊 Normal distribution", "📊 Equal variance"])
tabs = st.tabs(["📊 Normal distribution (Shapiro-Wilk test)", "📊 Equal variance (Levene test)"])
with tabs[0]:
fig = test_normal_distribution(st.session_state.test_attribute, st.session_state.test_options)
fig = test_normal_distribution(st.session_state.test_attribute, st.session_state.test_options, corrections_map[st.session_state.p_value_correction])
if fig:
show_fig(fig, "test-normal-distribution")
with tabs[1]:
fig = test_equal_variance(st.session_state.test_attribute, st.session_state.test_options)
fig = test_equal_variance(st.session_state.test_attribute, st.session_state.test_options, corrections_map[st.session_state.p_value_correction])
show_fig(fig, "test-equal-variance")

st.info(
"""💡 **Interpretation**

In both tests low p-values indicate that data points for a feature are **NOT** normal distributed or have similar variance.
To meet **parametric** criteria the p-values in the histograms should be equally distributed between 0 and 1.
To meet **parametric** criteria the p-values in the histograms should not be smaller than 0.05.
When a larger number of data points indicate low p-values, it would be advisable to opt for a **non-parametric** statistical test.
"""
)
Expand Down
2 changes: 1 addition & 1 deletion src/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def normalization(feature_df, meta_data_df, normalization_method):
# normalized = PQN_normalization(feature_df ,ref_norm = "median" , verbose=False)

elif normalization_method == "Total Ion Current (TIC) or sample-centric normalization":
normalized = feature_df.apply(lambda x: x/np.sum(x), axis=0)
normalized = feature_df.apply(lambda x: x/np.sum(x), axis=1)

else:
return md_samples, feature_df
Expand Down
34 changes: 17 additions & 17 deletions src/testparametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import pandas as pd
import plotly.express as px
import scipy.stats as stats
import pingouin as pg


@st.cache_data
def test_equal_variance(attribute, between):
def test_equal_variance(attribute, between, correction):
# test for equal variance
data = pd.concat([st.session_state.data, st.session_state.md], axis=1)
variance = pd.DataFrame(
{
f"{between[0]} - {between[1]}": [
f"{between[0]} - {between[1]}": pg.multicomp([
stats.levene(
data.loc[
(data[attribute] == between[0]),
Expand All @@ -22,19 +23,19 @@ def test_equal_variance(attribute, between):
],
)[1]
for f in st.session_state.data.columns
]
], method=correction)[1]
}
)
fig = px.histogram(
variance,
nbins=100,
nbins=20,
template="plotly_white",
range_x=[-0.025, 1.025],
)
fig.update_traces(marker_color="#696880")
fig.update_layout(
bargap=0.2,
font={"color": "grey", "size": 12, "family": "Sans"},
title={"text": f"TEST FOR EQUAL VARIANCE", "font_color": "#3E3D53"},
title={"text": f"TEST FOR EQUAL VARIANCE (LEVENE)", "font_color": "#3E3D53"},
xaxis_title="p-value",
yaxis_title="count",
showlegend=False
Expand All @@ -43,7 +44,7 @@ def test_equal_variance(attribute, between):


@st.cache_data
def test_normal_distribution(attribute, between):
def test_normal_distribution(attribute, between, correction):
# test for normal distribution
data = pd.concat([st.session_state.data, st.session_state.md], axis=1)
for b in between:
Expand All @@ -52,34 +53,33 @@ def test_normal_distribution(attribute, between):
return None
normality = pd.DataFrame(
{
f"{b}": [
f"{b}": pg.multicomp([
stats.shapiro(
data.loc[
(data[attribute] == between[0]),
(data[attribute] == b),
f,
]
)[1]
for f in st.session_state.data.columns
]
], method = correction)[1]
for b in between
}
)

fig = px.histogram(
normality.iloc[:, 1],
nbins=100,
normality,
nbins=20,
template="plotly_white",
color_discrete_sequence=["#696880", "#ef553b"],
opacity=0.8,
range_x=[-0.025, 1.025],
barmode="group",
)
fig.update_traces(marker_color="#696880")

fig.update_layout(
bargap=0.2,
font={"color": "grey", "size": 12, "family": "Sans"},
title={"text": f"TEST FOR NORMALITY", "font_color": "#3E3D53"},
title={"text": f"TEST FOR NORMALITY (SHAPIRO-WILK)", "font_color": "#3E3D53"},
xaxis_title="p-value",
yaxis_title="count",
showlegend=False
showlegend=True
)
return fig
Loading