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
b7799f04
Commit
b7799f04
authored
3 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
restructure parameters
Former-commit-id: 4c84242712d62802c372002a5b9dd02ff9909207
parent
186ea5fe
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
core/functions/test_hdf.py
+4
-1
4 additions, 1 deletion
core/functions/test_hdf.py
core/parameters.py
+33
-0
33 additions, 0 deletions
core/parameters.py
core/picker.py
+29
-12
29 additions, 12 deletions
core/picker.py
core/processor.py
+30
-27
30 additions, 27 deletions
core/processor.py
with
96 additions
and
40 deletions
core/functions/test_hdf.py
+
4
−
1
View file @
b7799f04
...
...
@@ -4,7 +4,10 @@ import h5py
from
core.cells
import
Cells
import
pandas
as
pd
f
=
h5py
.
File
(
"
/home/alan/Documents/sync_docs/PhD/tmp/DO6MS2_003store.h5
"
)
# f = h5py.File("/home/alan/Documents/sync_docs/PhD/tmp/DO6MS2_003store.h5")
f
=
h5py
.
File
(
"
/shared_libs/pipeline-core/scripts/data/20191026_ss_experiments_01/DO6MS2_003store.h5
"
)
tracks
=
f
[
"
/extraction/general/None/area
"
][()]
cell
=
Cells
.
from_source
(
"
/home/alan/Documents/sync_docs/PhD/tmp/DO6MS2_003store.h5
"
)
from
postprocessor.core.picker
import
Picker
...
...
This diff is collapsed.
Click to expand it.
core/parameters.py
0 → 100644
+
33
−
0
View file @
b7799f04
from
abc
import
ABC
,
abstractmethod
class
ParametersABC
(
ABC
):
"""
Base class to add yaml functionality to parameters
"""
def
to_dict
(
self
):
return
self
.
__dict__
@classmethod
def
from_dict
(
cls
,
d
):
return
cls
(
**
d
)
def
to_yaml
(
self
,
path
=
None
):
return
dump
(
self
.
__dict__
,
path
)
@classmethod
def
from_yaml
(
cls
,
yam
):
with
open
(
Path
(
yam
))
as
f
:
params
=
safe_load
(
f
)
return
cls
(
**
params
)
@abstractmethod
@classmethod
def
default
(
cls
):
pass
@abstractmethod
def
run
(
self
):
pass
This diff is collapsed.
Click to expand it.
core/picker.py
+
29
−
12
View file @
b7799f04
from
typing
import
Tuple
,
Union
,
List
from
abc
import
ABC
,
abstractmethod
import
numpy
as
np
import
pandas
as
pd
from
core.cells
import
CellsHDF
from
postprocessor.core.parameters
import
ParametersABC
from
postprocessor.core.functions.signals
import
max_ntps
,
max_nonstop_ntps
# def BasePicker(ABC):
# """
# Base class to add mother-bud filtering support
# """
# def __init__(self, branch=None, lineage=None):
# self.lineage = lineage
@ParametersABC.register
class
PickerParameters
:
def
__init__
(
self
,
condition
:
Tuple
[
str
,
Union
[
float
,
int
]]
=
None
,
lineage
:
str
=
None
,
sequence
:
List
[
str
]
=
[
"
lineage
"
,
"
condition
"
],
):
self
.
condition
=
condition
self
.
lineage
=
lineage
self
.
sequence
=
sequence
@classmethod
def
defaults
(
cls
):
return
cls
.
from_dict
(
{
"
condition
"
:
(
"
present
"
,
0.8
),
"
lineage
"
:
None
,
"
sequence
"
:
[
"
lineage
"
,
"
condition
"
],
}
)
class
Picker
:
...
...
@@ -29,16 +47,15 @@ class Picker:
self
,
signals
:
pd
.
DataFrame
,
cells
:
CellsHDF
,
condition
:
Tuple
[
str
,
Union
[
float
,
int
]]
=
None
,
lineage
:
str
=
None
,
sequence
:
List
[
str
]
=
[
"
lineage
"
,
"
condition
"
],
parameters
:
PickerParameters
,
):
self
.
signals
=
signals
self
.
_index
=
signals
.
index
self
.
_cells
=
cells
self
.
condition
=
condition
self
.
lineage
=
lineage
self
.
sequence
=
sequence
self
.
parameters
=
parameters
for
k
,
v
in
parameters
.
to_dict
().
items
():
# access parameters directly
setattr
(
self
,
k
,
v
)
@staticmethod
def
mother_assign_to_mb_matrix
(
ma
:
List
[
np
.
array
]):
...
...
This diff is collapsed.
Click to expand it.
core/processor.py
+
30
−
27
View file @
b7799f04
...
...
@@ -2,18 +2,23 @@ import pandas as pd
class
Parameters
:
def
__init__
(
self
,
merger
=
None
,
picker
=
None
,
processes
=
None
,
branches
=
None
):
"""
Anthology of parameters used for postprocessing
"""
def
__init__
(
self
,
merger
=
None
,
picker
=
None
,
processes
=
None
,
datasets
=
None
):
self
.
merger
=
merger
self
.
picker
=
picker
self
.
processes
=
processes
self
.
branches
=
branches
self
.
datasets
=
datasets
def
__getitem__
(
self
,
item
):
return
getattr
(
self
,
item
)
class
PostProcessor
:
def
__init__
(
self
,
parameters
,
signals
):
def
__init__
(
self
,
fname
,
parameters
,
signals
):
self
.
parameters
=
parameters
self
.
merger
=
Merger
(
parameters
[
"
merger
"
])
...
...
@@ -21,13 +26,14 @@ class PostProcessor:
self
.
processes
=
[
self
.
get_process
(
process
)
for
process
in
parameters
[
"
processes
"
]
]
self
.
branche
s
=
parameters
[
"
branche
s
"
]
self
.
dataset
s
=
parameters
[
"
dataset
s
"
]
def
run
(
self
):
self
.
merger
.
run
(
signals
.
get_branch
(
self
.
branches
[
"
merger
"
]))
self
.
picker
.
run
(
signals
.
get_branch
(
self
.
branches
[
"
picker
"
]))
for
process
,
branch
in
zip
(
self
.
processes
,
self
.
branches
[
"
processes
"
]):
process
.
run
(
signals
.
get_branch
(
branch
))
self
.
merger
.
run
(
signals
[
self
.
datasets
[
"
merger
"
]])
self
.
picker
.
run
(
signals
[
self
.
datasets
[
"
picker
"
]])
for
process
,
dataset
in
zip
(
self
.
processes
,
self
.
datasets
[
"
processes
"
]):
process_result
=
process
.
run
(
signals
.
get_dataset
(
dataset
))
self
.
writer
.
write
(
process_result
,
dataset
)
class
Signals
:
...
...
@@ -38,26 +44,13 @@ class Signals:
def
__init__
(
self
,
file
):
self
.
_hdf
=
h5py
.
File
(
file
,
"
r
"
)
@staticmethod
def
_if_ext_or_post
(
name
):
if
name
.
startswith
(
"
extraction
"
)
or
name
.
startswith
(
"
postprocessing
"
):
if
len
(
name
.
split
(
"
/
"
))
>
3
:
return
name
@property
def
branches
(
self
):
return
signals
.
_hdf
.
visit
(
self
.
_if_ext_or_post
)
def
__getitem__
(
self
,
dataset
):
dset
=
self
.
_hdf
[
dataset
][()]
attrs
=
self
.
_hdf
[
dataset
].
attrs
first_dataset
=
"
/
"
+
dataset
.
split
(
"
/
"
)[
0
]
+
"
/
"
timepoints
=
self
.
_hdf
[
first_dataset
].
attrs
[
"
processed_timepoints
"
]
def
get_branch
(
self
,
branch
):
return
self
.
_hdf
[
branch
][()]
def
branch_to_df
(
self
,
branch
):
dset
=
self
.
_hdf
[
branch
][()]
attrs
=
self
.
_hdf
[
branch
].
attrs
first_branch
=
"
/
"
+
branch
.
split
(
"
/
"
)[
0
]
+
"
/
"
timepoints
=
self
.
_hdf
[
first_branch
].
attrs
[
"
processed_timepoints
"
]
if
"
cell_label
"
in
self
.
_hdf
[
branch
].
attrs
:
if
"
cell_label
"
in
self
.
_hdf
[
dataset
].
attrs
:
ids
=
pd
.
MultiIndex
.
from_tuples
(
zip
(
attrs
[
"
trap
"
],
attrs
[
"
cell_label
"
]),
names
=
[
"
trap
"
,
"
cell_label
"
]
)
...
...
@@ -66,5 +59,15 @@ class Signals:
return
pd
.
DataFrame
(
dset
,
index
=
ids
,
columns
=
timepoints
)
@staticmethod
def
_if_ext_or_post
(
name
):
if
name
.
startswith
(
"
extraction
"
)
or
name
.
startswith
(
"
postprocessing
"
):
if
len
(
name
.
split
(
"
/
"
))
>
3
:
return
name
@property
def
datasets
(
self
):
return
signals
.
_hdf
.
visit
(
self
.
_if_ext_or_post
)
def
close
(
self
):
self
.
_hdf
.
close
()
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