Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aliby-mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Swain Lab
aliby
aliby-mirror
Commits
942f6a60
Commit
942f6a60
authored
3 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
add recursive tree exploration
Former-commit-id: 38e0bc115caa73bfbaad89feb962091486601192
parent
7335342e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/io/base.py
+65
-0
65 additions, 0 deletions
core/io/base.py
with
65 additions
and
0 deletions
core/io/base.py
+
65
−
0
View file @
942f6a60
from
typing
import
Union
from
itertools
import
groupby
import
h5py
import
h5py
...
@@ -5,5 +8,67 @@ class BridgeH5:
...
@@ -5,5 +8,67 @@ class BridgeH5:
def
__init__
(
self
,
file
):
def
__init__
(
self
,
file
):
self
.
_hdf
=
h5py
.
File
(
file
,
"
r
"
)
self
.
_hdf
=
h5py
.
File
(
file
,
"
r
"
)
self
.
_filecheck
()
def
_filecheck
(
self
):
assert
"
cell_info
"
in
self
.
_hdf
,
"
Invalid file. No
'
cell_info
'
found.
"
def
close
(
self
):
def
close
(
self
):
self
.
_hdf
.
close
()
self
.
_hdf
.
close
()
def
max_ncellpairs
(
self
,
nstepsback
):
"""
Get maximum number of cell pairs to be calculated
"""
dset
=
self
.
_hdf
[
"
cell_info
"
][()]
# attrs = self._hdf[dataset].attrs
pass
@property
def
cell_tree
(
self
):
return
self
.
get_info_tree
()
def
get_info_tree
(
self
,
fields
:
Union
[
tuple
,
list
]
=
(
"
trap
"
,
"
timepoint
"
,
"
cell_label
"
)
):
"""
Returns traps, time points and labels for this position in form of a tree
in the hierarchy determined by the argument fields. Note that it is
compressed to non-empty elements and timepoints.
Default hierarchy is:
- trap
- time point
- cell label
This function currently produces trees of depth 3, but it can easily be
extended for deeper trees if needed (e.g. considering groups,
chambers and/or positions).
input
:fields: Fields to fetch from
'
cell_info
'
inside the hdf5 storage
returns
:tree: Nested dictionary where keys (or branches) are the upper levels
and the leaves are the last element of :fields:.
"""
zipped_info
=
(
*
zip
(
*
[
self
.
_hdf
[
"
cell_info
"
][
f
][()]
for
f
in
fields
]),)
return
recursive_groupsort
(
zipped_info
)
def
groupsort
(
iterable
:
Union
[
tuple
,
list
]):
# Groups a list or tuple by the first element and returns
# a dictionary that follows {v[0]:sorted(v[1:]) for v in iterable}.
# Sorted by the first element in the remaining values
return
{
k
:
[
x
[
1
:]
for
x
in
v
]
for
k
,
v
in
groupby
(
iterable
,
lambda
x
:
x
[
0
])}
def
recursive_groupsort
(
iterable
):
# Recursive extension of groupsort
if
len
(
iterable
[
0
])
>
1
:
return
{
k
:
recursive_groupsort
(
v
)
for
k
,
v
in
groupsort
(
iterable
).
items
()}
else
:
# Only two elements in list
return
[
x
[
0
]
for
x
in
iterable
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment