diff --git a/notebooks/process_surface_morphometrics_output.ipynb b/notebooks/process_surface_morphometrics_output.ipynb index bae62dd759a401f1378822ac998f78e353c7520e..6ff1b764d3cdcdba524f3f3d00476ebab02eba2c 100644 --- a/notebooks/process_surface_morphometrics_output.ipynb +++ b/notebooks/process_surface_morphometrics_output.ipynb @@ -72,14 +72,6 @@ " \"\"\"\n", " Clip meshes to avoid border artifacts\n", " \"\"\"\n", - " # bounds = [float(func(m.points[:, dim], 0))\n", - " # for dim in range(3) for func in [np.min, np.max]]\n", - " # bounds[0] = cut_dist\n", - " # bounds[1] = 300 - cut_dist\n", - " # bounds[2] = cut_dist\n", - " # bounds[3] = 300 - cut_dist\n", - " # bounds[4] = cut_dist\n", - " # bounds[5] = 300 - cut_dist\n", " bounds = [cut_dist, 300 - cut_dist] * 3\n", " mc = m.clip_box(bounds, progress_bar=True, invert=False)\n", " return mc\n", @@ -185,7 +177,7 @@ "## Read in coordinates\n", "\n", "import pickle\n", - "df = pickle.load(open(os.path.join(\"/Volumes/Eirene/Points/extracted_images\", 'T3SS_coordinates.pc'), 'rb'))" + "df = pickle.load(open('T3SS_coordinates.pc', 'rb'))" ] }, { @@ -215,17 +207,6 @@ "outputs": [], "source": [ "# alphabetical order\n", - "ruptured = [\n", - " 0,\n", - " 0,\n", - " 0,\n", - " 1,\n", - " 0,\n", - " 0,\n", - " 0,\n", - " 1,\n", - " 1,\n", - "]\n", "\n", "curvdfs = []\n", "poss = []\n", @@ -256,14 +237,15 @@ " curvdf['distance'] = dist\n", " curvdf['index'] = np.arange(len(c))\n", " curvdf['file'] = p.name\n", - " curvdf['touching'] = 'touching' if np.min(dist) < 10 else 'not touching'\n", - " curvdf['ruptured'] = ruptured[ind]\n", - " curvdf['condition'] = 'ruptured' if ruptured[ind] else ('touching' if np.min(dist) < 10 else 'not touching')\n", + " curvdf['touching'] = 'touching' if np.min(dist) < 5 else 'not touching'\n", " curvdf = pd.DataFrame(curvdf)\n", " curvdfs.append(curvdf)\n", "\n", "curvdf = pd.concat(curvdfs)\n", "\n", + "# save curvdf to file\n", + "curvdf.to_csv('output/measurements_curvedness.csv', index=False)\n", + "\n", "# count number of files per condition\n", "curvdf.groupby(['touching', 'file']).count()" ] @@ -301,156 +283,7 @@ "plt.title(\"Curvedness vs distance\")\n", "plt.xlabel('Distance to T3SS tip [nm]')\n", "plt.ylabel('Curvedness')\n", - "plt.savefig(os.path.join(out_dir, 'curvedness_vs_distance.pdf'))\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import seaborn as sns\n", - "from matplotlib import pyplot as plt\n", - "\n", - "# bin distances into bins of width 20\n", - "curvdf['distance_bin'] = pd.cut(curvdf['distance'], bins=np.arange(0, 100, 10))\n", - "\n", - "plt.figure()\n", - "tmp = curvdf.dropna().groupby([\n", - " 'distance_bin',\n", - " 'file',\n", - " ]).agg({'curvedness': 'mean', 'touching': 'first'})\n", - "\n", - "# keep only touching\n", - "tmp = tmp[tmp['touching'] == 'touching']\n", - "\n", - "palette ={\"touching\": \"gray\", \"not touching\": \"white\"}\n", - "\n", - "g = sns.barplot(data=tmp, x='distance_bin', y='curvedness',# errorbar=('pi'),\n", - " # palette=palette,\n", - " color=\"lightgray\",\n", - " )\n", - "\n", - "for patch in g.patches:\n", - " clr = patch.get_facecolor()\n", - " patch.set_edgecolor('black')\n", - "\n", - "plt.title(\"Curvedness vs distance - only touching\")\n", - "plt.xlabel('Distance to T3SS tip [nm]')\n", - "plt.ylabel('Curvedness')\n", - "plt.savefig(os.path.join(out_dir, 'curvedness_vs_distance_only_touching.pdf'))\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import seaborn as sns\n", - "from matplotlib import pyplot as plt\n", - "\n", - "# bin distances into bins of width 20\n", - "curvdf['distance_bin'] = pd.cut(curvdf['distance'], bins=np.arange(0, 100, 10))\n", - "\n", - "plt.figure()\n", - "tmp = curvdf.dropna().groupby([\n", - " 'distance_bin',\n", - " 'file',\n", - " ]).agg({'curvedness': 'mean', 'touching': 'first'}).reset_index()\n", - "\n", - "# keep only touching\n", - "tmp = tmp[tmp['touching'] == 'touching']\n", - "tmp['distance_bin_center'] = tmp['distance_bin'].apply(lambda x: x.mid)\n", - "\n", - "palette ={\"touching\": \"gray\", \"not touching\": \"white\"}\n", - "\n", - "g = sns.lineplot(data=tmp, x='distance_bin_center', y='curvedness', errorbar=('sd'),\n", - " # palette=palette,\n", - " color=\"gray\",\n", - " )\n", - "\n", - "for patch in g.patches:\n", - " clr = patch.get_facecolor()\n", - " patch.set_edgecolor('black')\n", - "\n", - "plt.title(\"Curvedness vs distance - only touching\")\n", - "plt.xlabel('Distance to T3SS tip [nm]')\n", - "plt.ylabel('Curvedness')\n", - "plt.savefig(os.path.join(out_dir, 'curvedness_vs_distance_only_touching_line.pdf'))\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import seaborn as sns\n", - "from matplotlib import pyplot as plt\n", - "\n", - "# bin distances into bins of width 20\n", - "curvdf['distance_bin'] = pd.cut(curvdf['distance'], bins=np.arange(0, 100, 10))\n", - "\n", - "plt.figure()\n", - "tmp = curvdf.dropna().groupby([\n", - " 'distance_bin',\n", - " 'file',\n", - " ]).agg({'curvedness': 'mean', 'touching': 'first'})\n", - "\n", - "palette ={\"touching\": \"gray\", \"not touching\": \"white\"}\n", - "\n", - "g = sns.barplot(data=tmp, x='distance_bin', y='curvedness',#, errorbar=('pi'),\n", - " # palette=palette,\n", - " color=\"lightgray\",\n", - " )\n", - "\n", - "for patch in g.patches:\n", - " clr = patch.get_facecolor()\n", - " patch.set_edgecolor('black')\n", - "\n", - "plt.title(\"Curvedness vs distance - all substacks\")\n", - "plt.xlabel('Distance to T3SS tip [nm]')\n", - "plt.ylabel('Curvedness')\n", - "plt.savefig(os.path.join(out_dir, 'curvedness_vs_distance_all.pdf'))\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import seaborn as sns\n", - "from matplotlib import pyplot as plt\n", - "\n", - "# bin distances into bins of width 20\n", - "curvdf['distance_bin'] = pd.cut(curvdf['distance'], bins=np.arange(0, 100, 10))\n", - "\n", - "# tmp = curvdf.dropna().groupby([\n", - "# 'distance_bin',\n", - "# 'file',\n", - "# ]).agg({'curvedness': 'mean', 'touching': 'first'})\n", - "tmp = curvdf\n", - "\n", - "tmp = tmp.reset_index().dropna()\n", - "tmp['distance_centers'] = [i.mid for i in tmp['distance_bin']]\n", - "tmp['substack'] = [i.split('_Mem')[0] for i in tmp['file']]\n", - "\n", - "# palette ={\"touching\": \"gray\", \"not touching\": \"white\"}\n", - "\n", - "plt.figure(figsize=(15, 8))\n", - "# plt.figure()\n", - "# plt.figure(figsize=(10, 5))\n", - "g = sns.barplot(data=tmp,\n", - " # x='distance_centers',\n", - " x='distance_bin',\n", - " y='curvedness', errorbar=('pi', 50),\n", - " # palette=palette,\n", - " # color=\"lightgray\",\n", - " hue='substack',\n", - " )" + "# plt.savefig(os.path.join(out_dir, 'curvedness_vs_distance.pdf'))\n" ] }, {