{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO\n",
    "# CONSOLIDATE TO ONE DIMENSION\n",
    "\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import sklearn as sk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "blob_1 = np.random.multivariate_normal([0,1,5],np.identity(3),size=300)\n",
    "blob_2 = np.random.multivariate_normal([0,1,5],np.identity(3),size=300)\n",
    "\n",
    "# cov = np.array([\n",
    "#     [1,-1,0],\n",
    "#     [-1,1,0],\n",
    "#     [0,0,1]\n",
    "# ])\n",
    "\n",
    "# blob_3 = np.random.multivariate_normal([2,4,1],np.identity(3),size=200)\n",
    "# blob_4 = np.random.multivariate_normal([4,2,1],np.identity(3),size=100)\n",
    "# blob_5 = np.random.multivariate_normal([3,3,1],cov,size=500)\n",
    "\n",
    "blob_3 = np.random.multivariate_normal([4,2,1],np.identity(3)*2,size=200)\n",
    "blob_4 = np.random.multivariate_normal([2,4,1],np.identity(3)*2,size=100)\n",
    "blob_5 = np.random.multivariate_normal([3,3,1],np.identity(3)*2,size=500)\n",
    "\n",
    "combined_1 = np.vstack([blob_1,blob_3,blob_4])\n",
    "\n",
    "labels_1 = np.zeros(600)\n",
    "labels_1[:300] = 1\n",
    "labels_1[300:500] = 3\n",
    "labels_1[500:] = 4\n",
    "\n",
    "combined_2 = np.vstack([blob_2,blob_5])\n",
    "\n",
    "labels_2 = np.zeros(800)\n",
    "labels_2[:300] = 2\n",
    "labels_2[300:] = 5\n",
    "\n",
    "joint = np.vstack([combined_1,combined_2])\n",
    "joint_labels = np.hstack([labels_1,labels_2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.manifold import TSNE\n",
    "\n",
    "coordinates_1 = TSNE().fit_transform(combined_1)\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*coordinates_1.T,c=labels_1,cmap='rainbow')\n",
    "plt.show()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "coordinates_2 = TSNE().fit_transform(combined_2)\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*coordinates_2.T,c=labels_2,cmap='rainbow')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "coordinates_joint = TSNE().fit_transform(joint)\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*coordinates_joint.T,c=joint_labels,cmap='rainbow')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scanpy as sc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "blobs_1 = sc.AnnData(combined_1)\n",
    "blobs_2 = sc.AnnData(combined_2)\n",
    "blobs_joint = sc.AnnData(joint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.pp.neighbors(blobs_1)\n",
    "sc.pp.neighbors(blobs_2)\n",
    "sc.pp.neighbors(blobs_joint)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.tl.umap(blobs_1)\n",
    "sc.tl.umap(blobs_2)\n",
    "sc.tl.umap(blobs_joint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.pl.umap(blobs_1)\n",
    "sc.pl.umap(blobs_2)\n",
    "sc.pl.umap(blobs_joint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.tl.louvain(blobs_1,resolution=.3)\n",
    "sc.pl.umap(blobs_1,color='louvain')\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*blobs_1.obsm['X_umap'].T,c=labels_1,cmap='rainbow')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.tl.louvain(blobs_2,resolution=.3)\n",
    "sc.pl.umap(blobs_2,color='louvain')\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*blobs_2.obsm['X_umap'].T,c=labels_2,cmap='rainbow')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.tl.louvain(blobs_joint,resolution=.3)\n",
    "sc.pl.umap(blobs_joint,color='louvain')\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(*blobs_joint.obsm['X_umap'].T,c=joint_labels,cmap='rainbow')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}

