Last active
June 24, 2020 09:22
-
-
Save rahulbhadani/eb705711832ac8d6afe21d37062950a2 to your computer and use it in GitHub Desktop.
UMAP Visualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import umap | |
import zipfile | |
import urllib.request | |
import pandas as pd | |
import umap | |
urllib.request.urlretrieve("https://ftp.ncbi.nlm.nih.gov/geo/samples/GSM2230nnn/GSM2230760/suppl/GSM2230760_human4_umifm_counts.csv.gz", 'GSM2230760_human4_umifm_counts.csv.gz') | |
data = pd.read_csv('GSM2230760_human4_umifm_counts.csv.gz') | |
data.drop(columns='Unnamed: 0', inplace=True) | |
data.set_index("barcode", inplace=True) | |
reducer = umap.UMAP() | |
embedding = reducer.fit_transform(data.loc[:, data.columns != 'assigned_cluster'].values) | |
import matplotlib.pyplot as plt | |
import seaborn as sn | |
print(data.assigned_cluster.unique()) | |
# Map the cell types to categorical variable (integer number) for color coding | |
clr = data.assigned_cluster.map({"ductal":0, "delta":1, "alpha":2, "activated_stellate": 3, "beta": 4, "macrophage": 5, "quiescent_stellate": 6, "acinar":7, "gamma":8, "epsilon":9, "endothelial":10, "t_cell":11, "mast":12, "schwann":13}) | |
plt.rcParams['figure.figsize'] = [26.0, 24.0] | |
plt.scatter( | |
embedding[:, 0], | |
embedding[:, 1], s =10, | |
c=clr, cmap="magma") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment