Skip to content

Commit

Permalink
ara fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tathey1 committed Dec 27, 2023
1 parent 1063146 commit 98c7a01
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 708 deletions.
40 changes: 30 additions & 10 deletions brainlit/BrainLine/analyze_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ class BrainDistribution:
brain_ids (list): List of brain IDs (keys of data json file).
"""

def __init__(self, brain_ids: list, data_file: str, ontology_file: str):
def __init__(self, brain_ids: list, data_file: str, ontology_file: str, fixes_file: str = None):
self.brain_ids = brain_ids
with open(data_file) as f:
data = json.load(f)
self.brain2paths = data["brain2paths"]
self.subtype_counts = self._get_subtype_counts()
self.ontology_file = ontology_file

if fixes_file == None:
self.ontology_fixes = None
else:
with open(fixes_file) as f:
data = json.load(f)
self.ontology_fixes = data

def _slicetolabels(self, slice, fold_on: bool = False, atlas_level: int = 5):
region_graph = _setup_atlas_graph(self.ontology_file)
atlas_level_nodes = _get_atlas_level_nodes(atlas_level, region_graph)
Expand Down Expand Up @@ -121,11 +128,12 @@ def __init__(
brain_ids: list,
data_file: str,
ontology_file: str,
fixes_file: str = None,
show_plots: bool = True,
bootstrap: int = 0,
shuffle: bool = False,
):
super().__init__(brain_ids, data_file, ontology_file)
super().__init__(brain_ids, data_file, ontology_file, fixes_file)
self.show_plots = show_plots

atlas_points = self._retrieve_soma_coords(brain_ids)
Expand Down Expand Up @@ -209,6 +217,7 @@ def _retrieve_soma_coords(self, brain_ids: list):

def _get_regions(self, points: dict, side: str = None):
brain2paths = self.brain2paths
ontology_fixes = self.ontology_fixes
if "filepath" in brain2paths["atlas"].keys():
vol_atlas = io.imread(brain2paths["atlas"]["filepath"])
else:
Expand All @@ -227,6 +236,9 @@ def _get_regions(self, points: dict, side: str = None):
continue
try:
region = int(vol_atlas[point_int[0], point_int[1], point_int[2]])

if ontology_fixes != None and str(region) in ontology_fixes.keys():
region = ontology_fixes[str(region)]["replacement"]
except IndexError:
continue
except OutOfBoundsError:
Expand Down Expand Up @@ -566,6 +578,7 @@ def _setup_regiongraph(self):
region_graph.nodes[region][brain_id]
+ id_to_regioncounts[brain_id][region]
)


# propagate counts up the hierarchy
for brain_id in brain_ids:
Expand Down Expand Up @@ -989,9 +1002,10 @@ def __init__(
data_file: str,
regional_distribution_dir: str,
ontology_file: str,
fixes_file: str = None,
show_plots: bool = True,
):
super().__init__(brain_ids, data_file, ontology_file)
super().__init__(brain_ids, data_file, ontology_file, fixes_file)
self.regional_distribution_dir = regional_distribution_dir
region_graph, total_axon_vols = self._setup_regiongraph(
regional_distribution_dir
Expand All @@ -1002,6 +1016,7 @@ def __init__(
def _setup_regiongraph(self, regional_distribution_dir):
regional_distribution_dir = self.regional_distribution_dir
brain_ids = self.brain_ids
ontology_fixes = self.ontology_fixes
region_graph = _setup_atlas_graph(self.ontology_file)
max_level = 0

Expand All @@ -1023,14 +1038,19 @@ def _setup_regiongraph(self, regional_distribution_dir):
quantification_dict = pickle.load(f)

for region in quantification_dict.keys():
if region in region_graph.nodes:
region_graph.nodes[region][brain_id + " axon"] = region_graph.nodes[
region
][brain_id + " axon"] + float(quantification_dict[region][1])
region_graph.nodes[region][
if ontology_fixes != None and str(region) in ontology_fixes.keys():
region_idx = ontology_fixes[str(region)]["replacement"]
else:
region_idx = region

if region_idx in region_graph.nodes:
region_graph.nodes[region_idx][brain_id + " axon"] = region_graph.nodes[
region_idx
][brain_id + " axon"] + float(quantification_dict[region_idx][1])
region_graph.nodes[region_idx][
brain_id + " total"
] = region_graph.nodes[region][brain_id + " total"] + float(
quantification_dict[region][0]
] = region_graph.nodes[region_idx][brain_id + " total"] + float(
quantification_dict[region_idx][0]
)

total_axon_vols = {}
Expand Down
82 changes: 82 additions & 0 deletions brainlit/BrainLine/data/open-nd-ara-fixes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"182305696" : {
"point" : [473, 168, 252],
"replacement" : 182305689
},
"182305712" : {
"point" : [499, 216, 285],
"replacement" : 182305689
},
"312782560" : {
"point" : [666, 36, 441],
"replacement" : 312782546
},
"312782592" : {
"point" : [711, 71, 287],
"replacement" : 22
},
"312782656" : {
"point" : [896, 254, 197],
"replacement" : 312782628
},
"484682464" : {
"point" : [765, 203, 514],
"replacement" : 484682470
},
"526157184" : {
"point" : [211, 262, 474],
"replacement" : 526157192
},
"526322272" : {
"point" : [337, 320, 432],
"replacement" : 526322264
},
"527696992" : {
"point" : [337, 319, 457],
"replacement" : 527696977
},
"549009216" : {
"point" : [774, 335, 513],
"replacement" : 549009203
},
"560581568" : {
"point" : [592, 509, 566],
"replacement" : 560581559
},
"563807424" : {
"point" : [764, 348, 375],
"replacement" : 563807435
},
"576073728" : {
"point" : [521, 669, 540],
"replacement" : 576073699
},
"589508416" : {
"point" : [796, 611, 349],
"replacement" : 589508447
},
"589508480" : {
"point" : [1108, 405, 462],
"replacement" : 589508451
},
"599626944" : {
"point" : [752, 300, 563],
"replacement" : 599626923
},
"606826624" : {
"point" : [767, 608, 504],
"replacement" : 606826655
},
"606826688" : {
"point" : [787, 580, 541],
"replacement" : 606826659
},
"607344832" : {
"point" : [822, 532, 564],
"replacement" : 607344834
},
"614454272" : {
"point" : [903, 350, 541],
"replacement" : 614454277
}
}
25 changes: 25 additions & 0 deletions brainlit/BrainLine/data/open-nd-ara-fixes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
https://ara.viz.neurodata.io/?json_url=https://json.neurodata.io/v1?NGStateID=HxplM7aMw4lxeQ

region 182305696 not found with vol: 685646 e.g.[473, 168, 252]: primary somatosensory area unassigned
region 182305712 not found with vol: 576686 e.g.[499, 216, 285]: primary somatosensory area unassigned
region 312782560 not found with vol: 1439164 e.g.[666, 36, 441]: anterior area
region 312782592 not found with vol: 939216 e.g.[711, 71, 287]: anterior area and rostrolateral area and laterointermediate area
region 312782656 not found with vol: 658788 e.g.[896, 254, 197]: postrhinal area
region 484682464 not found with vol: 1328060 e.g.[765, 203, 514]: prosubiculum
region 526157184 not found with vol: 483806 e.g.[211, 262, 474]: frontal pole layer 5
region 526322272 not found with vol: 942 e.g.[337, 320, 432]: frontal pole, layer 6b
region 527696992 not found with vol: 3708 e.g.[337, 319, 457]: orbital area, medial part, layer 6b
region 549009216 not found with vol: 529062 e.g.[774, 335, 513]: retroparafasicular nucleus
region 560581568 not found with vol: 499022 e.g.[592, 509, 566]: xiphoid thalamic nucleus
region 563807424 not found with vol: 302102 e.g.[764, 348, 375]: posterior triangular thalamic nucleus
region 576073728 not found with vol: 264382 e.g.[521, 669, 540]: ventromedial preoptic nucleus
region 589508416 not found with vol: 421334 e.g.[796, 611, 349]: hippocampo-amygdalar transition area
region 589508480 not found with vol: 187780 e.g.[1108, 405, 462]: paratrigeminal nucleus
region 599626944 not found with vol: 62506 e.g.[752, 300, 563]: subcommissural organ
region 606826624 not found with vol: 386320 e.g.[767, 608, 504]: medial mammillary nucleus, posterior part
region 606826688 not found with vol: 93024 e.g.[787, 580, 541]: medial mammillary nucleus, dorsal part
region 607344832 not found with vol: 365658 e.g.[822, 532, 564]: interpeduncular nucleus, rostral
region 614454272 not found with vol: 42112 e.g.[903, 350, 541]: Supraoculomotor periaqueductal gray

https://ara.viz.neurodata.io/?json_url=https://json.neurodata.io/v1?NGStateID=_mB5Z7DqCWbDxA
https://connectivity.brain-map.org/3d-viewer?v=1&types=IMAGEPLANE&IMAGEPLANE=imageplanes
514 changes: 78 additions & 436 deletions experiments/BrainLine/axon_analysis.ipynb

Large diffs are not rendered by default.

0 comments on commit 98c7a01

Please sign in to comment.