Skip to content

Instantly share code, notes, and snippets.

@NicoKiaru
Created May 15, 2024 08:39
Show Gist options
  • Save NicoKiaru/94601b614f29c70b971848e0cd6711cf to your computer and use it in GitHub Desktop.
Save NicoKiaru/94601b614f29c70b971848e0cd6711cf to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "0eeedd94-14a4-449e-93ae-2857ca9003e3",
"metadata": {},
"source": [
"# From QuPath to Visualisation and Quantification\n",
"\n",
"NOTE: For the sake of speed, we are using the 25 micron atlas. In a real case scenario, it's much better to use the 10 micron atlas. Simply replace `allen_mouse_25um` by `allen_mouse_10um`."
]
},
{
"cell_type": "markdown",
"id": "9e2471cf-ca3d-433a-96bc-43d942c06fa1",
"metadata": {
"tags": []
},
"source": [
"## Collecting and filtering results "
]
},
{
"cell_type": "markdown",
"id": "746952f4-665f-44d7-a738-a368d15137d7",
"metadata": {},
"source": [
"After detecting the cells in QuPath, you have exported the results as tables, saved as csv files. In the QuPath project folder you'll find a `results` folder that contains `Image1Name_detections.csv` , `Image1Name_annotations.csv` ... \n",
"\n",
"Let's see a way to visualise and process these data.\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "ca24b85f-0d84-4961-8d5b-01b7dfae6a8b",
"metadata": {},
"source": [
"### Merging all data into a single dataframe"
]
},
{
"cell_type": "markdown",
"id": "4bac3521-ee4d-41d1-b242-db6fa4a2ae26",
"metadata": {},
"source": [
"Let's merge all csv of cell detections."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de5e383f-822a-4412-9255-49f4f98b8c5c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Import dependencies\n",
"import os\n",
"import glob\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from bg_atlasapi.bg_atlas import BrainGlobeAtlas\n",
"verbose = True"
]
},
{
"cell_type": "markdown",
"id": "c10be416-155a-4bd6-8347-4aab30d48f36",
"metadata": {
"tags": []
},
"source": [
"Specify the folder where csv files can be found"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "344ef53c-cba5-447b-b92c-4dd72f1dd96a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"dir = TODO please specify the path of the folder containing csv files '/home/biop/... /qupath_project/results'"
]
},
{
"cell_type": "markdown",
"id": "b57832ac-063b-4c54-9c74-298c0976d953",
"metadata": {
"tags": []
},
"source": [
"Make a list of all csv files containing detections"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8579b43-21f4-4e3f-8211-a04fb590d4e8",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"detections_csv_files = glob.glob(dir+'/*detections.csv')\n",
"if (verbose) : print('\\n'.join(detections_csv_files[:5]))"
]
},
{
"cell_type": "markdown",
"id": "0148d773-8cd1-45e7-941c-c18e1fd2c63e",
"metadata": {},
"source": [
"Append the content of the files in a big frame and select the columns we want to keep"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88c7b118-61ad-40bd-b20d-076f44f451b9",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"df = []\n",
"\n",
"# here you can use detections_csv_files[:10] to process only few files and go faster\n",
"for file in detections_csv_files : \n",
" df.append( pd.read_csv(file , sep='\\t', header=(0) ) )\n",
" \n",
"big_frame = pd.concat(df, ignore_index=True)\n",
"\n",
"# Here we'll keep only the image, the parent region, coordinates and Mean Fluorescent value in Cy3 channel\n",
"filtered_df = big_frame[ ['Image', 'Parent', 'Atlas_X', 'Atlas_Y', 'Atlas_Z', 'Nucleus: FL CY3 mean']]\n",
"filtered_df[:10] # Display a subset of cells to check that we collected the right columns"
]
},
{
"cell_type": "markdown",
"id": "bf5b0059-f41a-406f-80a4-9fca00fd648c",
"metadata": {},
"source": [
"### Basic data filtering according to a property"
]
},
{
"cell_type": "markdown",
"id": "bab32932-c4e3-48b5-b96b-2d637ded3cf8",
"metadata": {},
"source": [
"Filter data and keep cells for which the mean value of the Cy3 channel is above 100 values for cell above 100"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0175e3d-1500-4143-90be-2356b3e77c08",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"cy3_filtered_df = filtered_df[filtered_df[ 'Nucleus: FL CY3 mean'] > 100 ]\n",
"cy3_filtered_df[:10]"
]
},
{
"cell_type": "markdown",
"id": "85d6040f-e12b-4ab3-b73f-2bacdd595277",
"metadata": {},
"source": [
"### Converting Allen CCFv3 coordinates to BrainGlobe compatible coordinates"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1387418d-d251-4498-b09c-1e89ab37aeed",
"metadata": {},
"outputs": [],
"source": [
"# Converts the coordinates to python and brainglobe expectations: swap X and Z, converts from millimeters to micrometers\n",
"cy3_pos_cells = np.array( cy3_filtered_df[['Atlas_X', 'Atlas_Y','Atlas_Z']] , float ) * 1000.0"
]
},
{
"cell_type": "markdown",
"id": "d97836ac-e96b-4041-a172-43c18c60ec3e",
"metadata": {},
"source": [
"### Using Brainglobe to find cells located within an atlas region\n",
"\n",
"We can also filter per regions, that requires a little bit of work: we need to gather all the descendants regions and check whether the detected cells belong to any of the descendant region.\n",
"\n",
"See https://brainglobe.info/index.html for information about BrainGlobe. BrainGlobe is a set of software that eases the manipulation of several atlases with common code. It notably wraps the Allen brain atlas that we are using here."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6434c0a-30c9-4a84-9c14-8da290fcf5ac",
"metadata": {},
"outputs": [],
"source": [
"atlas = BrainGlobeAtlas(\"allen_mouse_25um\") # Loads the atlas label image at 25 microns resolution\n",
"# see https://github.com/brainglobe/brainglobe-atlasapi/blob/eee08c6d9aa9b69251f5adab3efc2ed85fc91cd8/tutorials/Atlas%20API%20usage.ipynb#L1227\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2c7b18d-2fda-444c-a6e7-5833e0f2b8b3",
"metadata": {},
"outputs": [],
"source": [
"# Define the region we are interested in \n",
"region_of_interest = TODO specify the acronym of a region of your choice, something like \"CA\"\n",
"\n",
"# get the region ID\n",
"region_id = atlas.structures.acronym_to_id_map[ region_of_interest ]\n",
"if verbose : print(\"region_id : \" , str(region_id))\n",
"\n",
"# get descendants Names \n",
"descendants_names = atlas.get_structure_descendants(region_id)\n",
"\n",
"# and look for IDs of each one\n",
"descendants_ids = []\n",
"for name in descendants_names:\n",
" descendants_ids.append( atlas.structures.acronym_to_id_map[name] ) \n",
" \n",
"if verbose : print(\"descendants_ids : \" , descendants_ids)\n",
"\n",
"# Combine IDs of region\n",
"region_and_descendants_ids = descendants_ids + [ region_id ]\n",
"if verbose : print(\"region_descendants_ids : \", region_and_descendants_ids ) \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e554718b-7c32-4aa9-8134-8f03184c1cc7",
"metadata": {},
"outputs": [],
"source": [
"# We have all the information to filter the number of detections per region\n",
"\n",
"cells_in_region = []\n",
"\n",
"for cell in cy3_pos_cells:\n",
" structure_id_of_cell = atlas.structure_from_coords(cell, microns=True) # We read the label image at the position of the cell\n",
" if structure_id_of_cell in region_and_descendants_ids:\n",
" cells_in_region.append(cell)\n",
"\n",
"# Number of points in the Region\n",
"print(\"There are \"+str(len(cells_in_region))+\" cells in the \"+region_of_interest+\" region.\")"
]
},
{
"cell_type": "markdown",
"id": "445aada4-24c7-4371-89b6-9190fc68390e",
"metadata": {
"tags": []
},
"source": [
"## Visualisation of cells in napari"
]
},
{
"cell_type": "markdown",
"id": "5f283326-c1e1-4869-883a-792e55d809c6",
"metadata": {},
"source": [
"### Create an instance of the napari viewer"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc2d243-7934-4a12-a882-300343b91ae1",
"metadata": {},
"outputs": [],
"source": [
"%gui qt5\n",
"import napari"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0a375d7-1411-455f-b92a-9bf902c148cf",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Create a Napari viewer in 3D mode\n",
"viewer = napari.Viewer(ndisplay=3) # Sets the viewer to 3D mode - the 2D slicing mode is not very convenient here"
]
},
{
"cell_type": "markdown",
"id": "734fd144-6792-4859-8b71-85cbe35ba189",
"metadata": {},
"source": [
"### Display all cells as a point cloud"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30a337d2-5147-42ee-9976-fe7e21df2dfc",
"metadata": {},
"outputs": [],
"source": [
"# Display all positive detected cells\n",
"viewer.add_points( cy3_pos_cells, \n",
" size = 50, \n",
" name = \"Cy3+ Cells\",\n",
" blending = 'additive' # the default blending is not ideal when so many points are displayed in 3D\n",
" )\n",
"\n",
"# You can lower the opacity of the layer to see a bit better the structure of the points (0.10)."
]
},
{
"cell_type": "markdown",
"id": "74e63bc7-7ec9-46c7-9220-a4bf860555ed",
"metadata": {},
"source": [
"### Display all cells colored according to a property"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68aba66b-e0dd-4311-ae72-83bd791c12c3",
"metadata": {},
"outputs": [],
"source": [
"# We can color the points according to a property of the dataframe, for instance according the the mean CY3 intensity\n",
"\n",
"max_cy3 = max(cy3_filtered_df[ 'Nucleus: FL CY3 mean'])/3 # the division by 3 is there to increase the level of brightness\n",
"\n",
"color_cells = []\n",
"\n",
"cy3_values = cy3_filtered_df[ 'Nucleus: FL CY3 mean'].values # Dataframe to numpy array\n",
"\n",
"# Combine 'cy3' values with constant values for green and blue components\n",
"colors_rgb_from_cy3 = [(min(cy3/max_cy3,1), 0, 0,1) for cy3 in cy3_values] # Assuming cy3 values represent the red component\n",
"edge_rgb_from_cy3 = [(min(cy3/max_cy3,1), 0, 0, 0.5) for cy3 in cy3_values] # Assuming cy3 values represent the red component\n",
"\n",
"# Add colored points layer to Napari viewer\n",
"viewer.add_points(cy3_pos_cells, \n",
" size=50, \n",
" name = \"Cy3+ Cells - Cy3 colored\",\n",
" face_color=colors_rgb_from_cy3, \n",
" edge_color=edge_rgb_from_cy3, \n",
" blending='additive'\n",
" )\n"
]
},
{
"cell_type": "markdown",
"id": "19e6c608-e2ad-4560-88e4-e6155d0f200a",
"metadata": {},
"source": [
"### Display cells of a subregion"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4ec3c51-8ba9-435d-9dec-7118e2817546",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Display positive cells detected in regions\n",
"viewer.add_points( cells_in_region, \n",
" size = 25, \n",
" symbol = 'diamond',\n",
" name = \"Cy3+ Cells In \"+region_of_interest,\n",
" blending = 'additive',\n",
" face_color = 'Green',\n",
" edge_color = 'Green'\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "f3b10b57-9a11-4a3d-8b74-9a695237b79f",
"metadata": {},
"source": [
"## Visualing atlas regions with brainrender-napari"
]
},
{
"cell_type": "markdown",
"id": "7c9b2022-37ee-4b1e-b669-1ca5c78fca55",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"Brainrender-napari (https://github.com/brainglobe/brainrender-napari) is a napari plugin to render BrainGlobe atlases and associated data as layers. It has a graphical user interface and can also used programmatically.\n",
"\n",
"### With the graphical user interface\n",
"\n",
"Within napari, you can:\n",
"- click on `Plugins > Brainrender`. This will take a few minutes. But then a side bar will show up.\n",
"- click on `Allen mouse (25 um)`\n",
"\n",
"You can now navigate through the atlas hierarchy. Double click on any of the region (like root), and then it will show up as a mesh in the viewer.\n",
"\n",
"See https://brainglobe.info/tutorials/visualise-atlas-napari.html for other functionalities"
]
},
{
"cell_type": "markdown",
"id": "6a5263e3-9f36-4516-9224-5eb201cacbf3",
"metadata": {},
"source": [
"### With the application programming interface"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69c98e88-21f4-4c65-8188-216e531c654e",
"metadata": {},
"outputs": [],
"source": [
"# See documentation at https://github.com/brainglobe/brainrender-napari\n",
"\n",
"# NOT POSSIBLE YET! See https://github.com/brainglobe/brainrender-napari/issues/53"
]
},
{
"cell_type": "markdown",
"id": "7714eb67-f267-4d86-a00d-b93551d85066",
"metadata": {},
"source": [
"## Counting cells per region\n",
"\n",
"### Dict: id to cell count, acronym to cell count\n",
"\n",
"Here we count the cells and sort them by region. Each region has certain properties, like an id, which is a unique number in the atlas, and an acronym.\n",
"\n",
"In the cell below, we sort all cells by region id (in contrast to the cells above, a cell belongs to one region only - this means that if we sum all cells from all regions, we will find the total number of detected cells). Be aware that if you find cells in a region which is not in a leaf of the atlas, this means that the cell is in the region but NOT in the subregions.\n",
"\n",
"In the cell below, we sort all cells by id, and then convert this data to a more human readable dict where each key is the acronym of the region instead of the int id."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11bfa865-af15-45d4-8405-bddcabf5d4f6",
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"# Create a defaultdict with int as the default factory\n",
"count_per_id = defaultdict(int)\n",
"\n",
"for cell in cy3_pos_cells:\n",
" structure_id_of_cell = atlas.structure_from_coords(cell, microns=True) # We read the label image at the position of the cell\n",
" count_per_id[structure_id_of_cell] += 1\n",
"\n",
"# We can convert this dict to a count per acronym\n",
"\n",
"count_per_acronym = {}\n",
"\n",
"for struct_id, count in count_per_id.items():\n",
" structure_info = atlas.structures.get(struct_id)\n",
" if structure_info:\n",
" acronym = structure_info['acronym']\n",
" count_per_acronym[acronym] = count\n",
" else:\n",
" # Handle the case where structure ID is not found\n",
" # For example, you can skip it or assign a default value\n",
" count_per_acronym['OUTSIDE'] = count_per_acronym.get('OUTSIDE',0) + 1\n",
"\n",
"print(count_per_id)\n",
"print(count_per_acronym)\n"
]
},
{
"cell_type": "markdown",
"id": "76025b91-2e0a-4789-90fc-ebf053080941",
"metadata": {},
"source": [
"### Dict: acronym to cell count"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a0451c7-af47-4c3c-84fe-8f6304f9e57d",
"metadata": {},
"outputs": [],
"source": [
"# Or you can directly create a dict with the acronym\n",
"\n",
"count_per_acronym = {}\n",
"\n",
"for cell in cy3_pos_cells:\n",
" try:\n",
" structure_acronym_of_cell = atlas.structure_from_coords(cell, \n",
" microns=True,\n",
" as_acronym=True) # We read the label image at the position of the cell\n",
" count_per_acronym[structure_acronym_of_cell] = count_per_acronym.get(structure_acronym_of_cell,0) + 1\n",
" except KeyError: # When cells are outside of the Brain, that may happen\n",
" count_per_acronym['OUTSIDE'] = count_per_acronym.get('OUTSIDE',0) + 1\n",
"\n",
"\n",
"print(count_per_acronym)"
]
},
{
"cell_type": "markdown",
"id": "c892579d-17a0-43da-820f-bebd385053cb",
"metadata": {},
"source": [
"### Dict: acronym to cell count, skipping lower levels of the atlas hierarchy\n",
"\n",
"Sometimes you don't want to look at what's happening within the finest subdivisions of the structures. Here's a possible way of cropping data at a certain hierarchy level.\n",
"\n",
"Try running the following cell with different `max_hierarchy_level` (1, then 2, then 10 ...).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "92672b61-9d73-4d20-8bb0-d2f63dc153f2",
"metadata": {},
"outputs": [],
"source": [
"hierarchy_level = len(atlas.structures['GPe'][\"structure_id_path\"]) # Example code: find the path length to get to a certain region of the atlas\n",
"\n",
"max_hierarchy_level = 5 # 1 = root, 2 = VS, fiber tracts, grey, etc.\n",
"\n",
"count_per_acronym_max_level = {}\n",
"\n",
"for cell in cy3_pos_cells:\n",
" struct_id = atlas.structure_from_coords(cell, microns=True) # We read the label image at the position of the cell\n",
" structure_info = atlas.structures.get(struct_id)\n",
" if structure_info:\n",
" struct_id_path = structure_info[\"structure_id_path\"]\n",
" level_hierarchy_chosen = min(max_hierarchy_level, len(struct_id_path))\n",
" id_cell = struct_id_path[level_hierarchy_chosen-1]\n",
" acronym = atlas.structures.get(id_cell)['acronym']\n",
" count_per_acronym_max_level[acronym] = count_per_acronym_max_level.get(acronym,0) + 1\n",
" else:\n",
" # Handle the case where structure ID is not found\n",
" # For example, you can skip it or assign a default value\n",
" count_per_acronym_max_level['OUTSIDE'] = count_per_acronym_max_level.get('OUTSIDE',0) + 1\n",
"\n",
"print(count_per_acronym_max_level)"
]
},
{
"cell_type": "markdown",
"id": "f16d08d3-3551-4c21-9653-cedbd2b7f60a",
"metadata": {},
"source": [
"### Bar plot of cell count per region\n",
"\n",
"If you run the previous cell with `max_hierarchy_level = 5` and then the next one, you will see that the majority of cells are within the `CTXpl` region."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20d50c9f-0a2b-4575-b57c-bd7ccce556fa",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"# Sample dictionary\n",
"data = count_per_acronym_max_level\n",
"\n",
"# Specify colors for each bar - the color of the atlas region (we set the outside label to black)\n",
"colors = [[color / 255 for color in atlas.structures[acronym]['rgb_triplet']] if atlas.structures.get(acronym) else [0,0,0] for acronym in data.keys()]#['red', 'green', 'blue']\n",
"\n",
"# Extract categories and heights from the dictionary\n",
"categories = list(data.keys())\n",
"heights = list(data.values())\n",
"\n",
"# Create a figure with a larger width\n",
"plt.figure(figsize=(10, 6))\n",
"\n",
"# Create a bar chart\n",
"bars = plt.bar(categories, heights, color=colors)\n",
"\n",
"# Rotate x-axis labels vertically\n",
"plt.xticks(rotation='vertical')\n",
"\n",
"# Add labels and title\n",
"plt.xlabel('Brain region (hierarchy level '+str(max_hierarchy_level)+')')\n",
"plt.ylabel('# Cells')\n",
"plt.title('Cy3 positive cells per region')\n",
"\n",
"# Display the plot\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "30e96346-7daa-4bb0-b1c9-c5072a46417e",
"metadata": {},
"source": [
"### Bar plot of cell count per region within a subregion, at a certain hierarchy level\n",
"\n",
"With the cell below, we can break down the cell count within the subregions of the `CTXpl` region."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc62274c-961d-4e4d-ba63-d2a5d585ca20",
"metadata": {},
"outputs": [],
"source": [
"# To break down what's happening in CTXpl\n",
"\n",
"sub_region = 'CTXpl'\n",
"max_hierarchy_level = 7 # 1 = root, 2 = VS, fiber tracts, grey, etc.\n",
"\n",
"id_sub_region = atlas.structures.get(sub_region)['id']\n",
"\n",
"# Sometimes you don't want to get the finest subdivisions of the structures\n",
"# Here's a possible way of cropping at a certain hierarchy level\n",
"\n",
"count_per_acronym_max_level_in_subregion = {}\n",
"\n",
"for cell in cy3_pos_cells:\n",
" struct_id = atlas.structure_from_coords(cell, microns=True) # We read the label image at the position of the cell\n",
" structure_info = atlas.structures.get(struct_id)\n",
" if structure_info:\n",
" struct_id_path = structure_info[\"structure_id_path\"]\n",
" if id_sub_region in struct_id_path:\n",
" level_hierarchy_chosen = min(max_hierarchy_level, len(struct_id_path))\n",
" id_cell = struct_id_path[level_hierarchy_chosen-1]\n",
" acronym = atlas.structures.get(id_cell)['acronym']\n",
" count_per_acronym_max_level_in_subregion[acronym] = count_per_acronym_max_level_in_subregion.get(acronym,0) + 1\n",
" else:\n",
" count_per_acronym_max_level_in_subregion['OUTSIDE'] = count_per_acronym_max_level_in_subregion.get('OUTSIDE',0) + 1\n",
" else:\n",
" # Handle the case where structure ID is not found\n",
" # For example, you can skip it or assign a default value\n",
" count_per_acronym_max_level_in_subregion['OUTSIDE'] = count_per_acronym_max_level_in_subregion.get('OUTSIDE',0) + 1\n",
"\n",
"print(count_per_acronym_max_level_in_subregion)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3064c4d-45b6-4f7b-89e9-46716d975ec8",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"# Sample dictionary\n",
"data = count_per_acronym_max_level_in_subregion\n",
"\n",
"# Specify colors for each bar - the color of the atlas region (we set the outside label to black)\n",
"colors = [[color / 255 for color in atlas.structures[acronym]['rgb_triplet']] if atlas.structures.get(acronym) else [0,0,0] for acronym in data.keys()]#['red', 'green', 'blue']\n",
"\n",
"# Extract categories and heights from the dictionary\n",
"categories = list(data.keys())\n",
"heights = list(data.values())\n",
"\n",
"\n",
"# Create a figure with a larger width\n",
"plt.figure(figsize=(10, 6))\n",
"\n",
"# Create a bar chart\n",
"bars = plt.bar(categories, heights, color=colors)\n",
"\n",
"# Rotate x-axis labels vertically\n",
"plt.xticks(rotation='vertical')\n",
"\n",
"# Add labels and title\n",
"plt.xlabel('Brain region (hierarchy level '+str(max_hierarchy_level)+')')\n",
"plt.ylabel('# Cells')\n",
"plt.title('Cy3 positive cells per region in subregion '+sub_region)\n",
"\n",
"# Display the plot\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "c1f72c6b-3156-4d93-a80b-e99860eefad3",
"metadata": {},
"source": [
"# Extra"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6c5053d-c30a-467b-ba83-726c973a3797",
"metadata": {},
"outputs": [],
"source": [
"# Run this cells if you want to display the full atlas structure\n",
"atlas.structures"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "473e0dcf-d952-42ee-b77e-127364b653db",
"metadata": {},
"outputs": [],
"source": [
"atlas.structures.get('CA')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ee1a344-6199-47dd-86bc-a3300da38ab8",
"metadata": {},
"outputs": [],
"source": [
"atlas.structures.get(996)['acronym'] # Just to know the syntax to collect the information"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e14eb331-89ae-468e-9a71-0361ef947309",
"metadata": {},
"outputs": [],
"source": [
"viewer.layers[5].scale"
]
},
{
"cell_type": "markdown",
"id": "4ae00c7f-0d89-42c6-a6b3-04b670632e78",
"metadata": {},
"source": [
"## Bash commands to setup this notebook locally\n",
"```\n",
"conda create -n brainrender-env python=3.9\n",
"conda activate brainrender-env\n",
"pip install jupyterlab\n",
"pip install brainrender-napari==0.0.3\n",
"pip install bg-atlasapi\n",
"pip install napari[all]\n",
"jupyter lab\n",
"```"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment