-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from neurodata/develop
update for 0.3.0 release
- Loading branch information
Showing
17 changed files
with
1,049 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from brainlit.algorithms.trace_analysis.fit_spline import * | ||
from brainlit.algorithms.trace_analysis.spline_fxns import * |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
187 changes: 187 additions & 0 deletions
187
experiments/axon_geometry/notebooks/resample_trace.ipynb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
{ | ||
"metadata": { | ||
"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.8.10" | ||
}, | ||
"orig_nbformat": 4, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3.8.6 ('env': venv)" | ||
}, | ||
"interpreter": { | ||
"hash": "c48f87b51193a18c36f6ec1b39da40df380a4c3fb2fa54b3e413dc2378ec9052" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2, | ||
"cells": [ | ||
{ | ||
"source": [ | ||
"In order to run this notebook, you must have generated data with random dropout of trace vertices. This can be done by uncommenting the bottom of `generate_trace_data.ipynb`" | ||
], | ||
"cell_type": "markdown", | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"import os\n", | ||
"import pandas as pd\n", | ||
"import seaborn as sns\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np\n", | ||
"import scipy\n", | ||
"from tqdm import tqdm" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"max_id = 300\n", | ||
"\n", | ||
"def classify_height(row):\n", | ||
" height = row[\"height\"]\n", | ||
" if height <= 2:\n", | ||
" return height\n", | ||
" else:\n", | ||
" return 3\n", | ||
"\n", | ||
"def numerical_class(row):\n", | ||
" _class = row[\"class\"]\n", | ||
" if _class == \"primary\":\n", | ||
" return 0\n", | ||
" if _class == \"collateral\":\n", | ||
" return 1\n", | ||
" if _class == \"terminal\":\n", | ||
" return 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#specify brain1 or brain2 below\n", | ||
"brain = \"brain1\"\n", | ||
"\n", | ||
"root_dir = Path(os.path.abspath('')).parents[1]\n", | ||
"experiment_dir = os.path.join(root_dir, \"axon_geometry\")\n", | ||
"data_dir = os.path.join(experiment_dir, \"data\", brain)\n", | ||
"segments_swc_dir = os.path.join(data_dir, \"segments_swc\")\n", | ||
"print(f\"Directory where swcs reside: {segments_swc_dir}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"for i in range(20):\n", | ||
" print(f\"****************Iter: {i}********************\")\n", | ||
" dropout_version = \"10pct_iter\" + str(i)\n", | ||
" trace_data_dir = os.path.join(data_dir, \"trace_data\")\n", | ||
" trace_data_dir = os.path.join(trace_data_dir, \"1\")\n", | ||
" trace_data_dir = os.path.join(trace_data_dir, dropout_version)\n", | ||
" df_path = os.path.join(trace_data_dir, \"df.csv\")\n", | ||
" if os.path.exists(df_path):\n", | ||
" df = pd.read_csv(df_path)\n", | ||
" else:\n", | ||
" df = pd.DataFrame(columns=[\"seg_id\", \"class\", \"height\", \"log_seg_length\", \"measure\", \"value\", \"log_value\"])\n", | ||
" for i in tqdm(np.arange(0, max_id)):\n", | ||
" i = int(i)\n", | ||
" trace_data_path = os.path.join(trace_data_dir, \"{}.npy\".format(i))\n", | ||
" if os.path.exists(trace_data_path) is True:\n", | ||
" trace_data = np.load(trace_data_path, allow_pickle=True)\n", | ||
"\n", | ||
" for node in trace_data:\n", | ||
" seg_length = node[\"seg_length\"]\n", | ||
" height = node[\"height\"]\n", | ||
" _class = node[\"class\"]\n", | ||
" mean_curvature = node[\"mean_curvature\"]\n", | ||
" mean_torsion = node[\"mean_torsion\"]\n", | ||
" \n", | ||
" log_seg_length = np.log10(seg_length)\n", | ||
"\n", | ||
" log_mean_curvature = np.log10(mean_curvature)\n", | ||
" df = df.append({\"seg_id\": i, \"height\": height, \"class\": _class, \"log_seg_length\": log_seg_length, \"measure\": \"curvature\", \"value\": mean_curvature, \"log_value\": log_mean_curvature}, ignore_index=True)\n", | ||
"\n", | ||
" log_mean_torsion = np.log10(mean_torsion)\n", | ||
" df = df.append({\"seg_id\": i, \"height\": height, \"class\": _class, \"log_seg_length\": log_seg_length, \"measure\": \"torsion\", \"value\": mean_torsion, \"log_value\": log_mean_torsion}, ignore_index=True)\n", | ||
" df.to_csv(df_path)\n", | ||
" df[\"class\"] = df.apply(numerical_class, axis=1)\n", | ||
" df[\"height_class\"] = df.apply(classify_height, axis=1)\n", | ||
"\n", | ||
"\n", | ||
" measures = [\"curvature\", \"torsion\"]\n", | ||
"\n", | ||
" classes = {0: \"primary\", 1: \"collateral\", 2: \"terminal\"}\n", | ||
" n = len(classes)\n", | ||
" matrix_pairs = np.triu(np.ones((n, n)), k=1)\n", | ||
" (coord_pairs_x, coord_pairs_y) = np.where(matrix_pairs == 1)\n", | ||
"\n", | ||
" for measure in measures:\n", | ||
" for class_1, class_2 in zip(coord_pairs_x, coord_pairs_y):\n", | ||
" Y1 = []\n", | ||
" Y2 = []\n", | ||
" segment_numbers = []\n", | ||
" X_class = []\n", | ||
" neuron_id = 0\n", | ||
" #collect data from all neurons\n", | ||
" for i in np.arange(0, max_id):\n", | ||
" sample_query = df.loc[(df['seg_id'] == i) & ((df['class'] == class_1)) & (df['measure'] == measure)]\n", | ||
" num_segments = len(sample_query.index)\n", | ||
" if num_segments > 0:\n", | ||
" Y1.append(np.mean(sample_query[\"value\"].to_numpy()))\n", | ||
" sample_query = df.loc[(df['seg_id'] == i) & ((df['class'] == class_2)) & (df['measure'] == measure)]\n", | ||
" Y2.append(np.mean(sample_query[\"value\"].to_numpy()))\n", | ||
"\n", | ||
" # Sign Test\n", | ||
" dif = np.subtract(Y1, Y2)\n", | ||
" k = np.sum(dif > 0)\n", | ||
" n = dif.shape[0]\n", | ||
" upper_bool = k > n // 2\n", | ||
" if upper_bool:\n", | ||
" p = np.sum(scipy.stats.binom.pmf(range(k,n+1), n=n, p=0.5))\n", | ||
" else:\n", | ||
" p = np.sum(scipy.stats.binom.pmf(range(0,k+1), n=n, p=0.5))\n", | ||
"\n", | ||
" if p < 0.05/12:\n", | ||
" if upper_bool:\n", | ||
" symb = \">\"\n", | ||
" else:\n", | ||
" symb = \"<\"\n", | ||
" print(f\"{classes[class_1]} {symb} {classes[class_2]} in {measure}\")\n", | ||
" print(f\"p-val was: {p}\")\n", | ||
" else:\n", | ||
" print(f\"No difference between {classes[class_1]} and {classes[class_2]} in {measure}\")\n", | ||
" print(f\"p-val was: {p}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
] | ||
} |
Oops, something went wrong.