Skip to content

Commit

Permalink
Removed umap correlation
Browse files Browse the repository at this point in the history
  • Loading branch information
Soorya19Pradeep committed Sep 25, 2024
1 parent a9a4ab8 commit 3e215b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 81 deletions.
41 changes: 6 additions & 35 deletions applications/contrastive_phenotyping/evaluation/PC_vs_CF.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# %%
from pathlib import Path
import sys
import os

sys.path.append("/hpc/mydata/soorya.pradeep/scratch/viscy_infection_phenotyping/VisCy")

Expand Down Expand Up @@ -50,19 +51,8 @@
embedding_dataset = read_embedding_dataset(features_path)
embedding_dataset

# %% umap analsis of the features

# load all unprojected features:
features = embedding_dataset["features"]
scaled_features = StandardScaler().fit_transform(features.values)

umap = UMAP()
embedding = umap.fit_transform(features.values)
features = (
features.assign_coords(UMAP1=("sample", embedding[:, 0]))
.assign_coords(UMAP2=("sample", embedding[:, 1]))
.set_index(sample=["UMAP1", "UMAP2"], append=True)
)

# %% PCA analysis of the features

Expand Down Expand Up @@ -325,14 +315,14 @@
# %% plot PCA vs set of computed features

set_features = [
"Sensor Area",
"Fluor radial profile",
"Contrast Fluor",
"Phase radial profile",
"Phase Standard Deviation",
"Phase IQR",
"Homogeneity Phase",
"Phase IQR",
"Phase Standard Deviation",
"Sensor Area",
"Homogeneity Fluor",
"Contrast Fluor",
"Phase radial profile",
]

plt.figure(figsize=(8, 10))
Expand All @@ -349,27 +339,8 @@
"/hpc/projects/comp.micro/infected_cell_imaging/Single_cell_phenotyping/ContrastiveLearning/Figure_panels/cell_division/PC_vs_CF_2chan_pca_setfeatures.svg"
)

# %% display UMAP correlation as a heatmap

plt.figure(figsize=(20, 5))
sns.heatmap(
correlation.drop(columns=["UMAP1", "UMAP2"]).loc["UMAP1":"UMAP2", :],
annot=True,
cmap="coolwarm",
fmt=".2f",
)
plt.title("Correlation between UMAP features and computed features")
plt.xlabel("Computed Features")
plt.ylabel("UMAP Features")
plt.savefig(
"/hpc/projects/comp.micro/infected_cell_imaging/Single_cell_phenotyping/ContrastiveLearning/Figure_panels/cell_division/PC_vs_CF_2chan.svg"
)

# %% find the cell patches with the highest and lowest value in each feature

import os


def save_patches(fov_name, track_id):
data_path = Path(
"/hpc/projects/intracellular_dashboard/viral-sensor/2024_02_04_A549_DENV_ZIKV_timelapse/8-train-test-split/registered_test.zarr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,8 @@
embedding_dataset = read_embedding_dataset(features_path)
embedding_dataset

# %% umap analsis of the features

# load all unprojected features:
features = embedding_dataset["features"]
scaled_features = StandardScaler().fit_transform(features.values)

umap = UMAP()
embedding = umap.fit_transform(features.values)
features = (
features.assign_coords(UMAP1=("sample", embedding[:, 0]))
.assign_coords(UMAP2=("sample", embedding[:, 1]))
.set_index(sample=["UMAP1", "UMAP2"], append=True)
)

# %% PCA analysis of the features

Expand Down Expand Up @@ -214,41 +203,6 @@
# Compute correlation between PCA features and computed features
correlation = feature_df_removed.corr(method="spearman")

# %% display PCA correlation as a heatmap

# remove UMAP compnents from the correlation matrix before plotting
correlation_pca = correlation.drop(columns=["UMAP1", "UMAP2"])

plt.figure(figsize=(20, 5))
sns.heatmap(
correlation_pca.drop(columns=["PCA1", "PCA2", "PCA3"]).loc["PCA1":"PCA3", :],
annot=True,
cmap="coolwarm",
fmt=".2f",
)
plt.title("Correlation between PCA features and computed features")
plt.xlabel("Computed Features")
plt.ylabel("PCA Features")
plt.savefig(
"/hpc/projects/comp.micro/infected_cell_imaging/Single_cell_phenotyping/ContrastiveLearning/Figure_panels/cell_division/PC_vs_CF_umap_phaseonly.svg"
)

# %% display UMAP correlation as a heatmap

plt.figure(figsize=(20, 5))
sns.heatmap(
correlation.drop(columns=["UMAP1", "UMAP2"]).loc["UMAP1":"UMAP2", :],
annot=True,
cmap="coolwarm",
fmt=".2f",
)
plt.title("Correlation between UMAP features and computed features")
plt.xlabel("Computed Features")
plt.ylabel("UMAP Features")
plt.savefig(
"/hpc/projects/comp.micro/infected_cell_imaging/Single_cell_phenotyping/ContrastiveLearning/Figure_panels/cell_division/PC_vs_CF_phaseonly.svg"
)

# %% calculate the p-value and draw volcano plot to show the significance of the correlation

p_values = pd.DataFrame(index=correlation.index, columns=correlation.columns)
Expand Down

0 comments on commit 3e215b5

Please sign in to comment.