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
56b0fb87
Commit
56b0fb87
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
refactor(picker): simplify lineage process
parent
e4e31e1d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/postprocessor/core/reshapers/picker.py
+31
-109
31 additions, 109 deletions
src/postprocessor/core/reshapers/picker.py
with
31 additions
and
109 deletions
src/postprocessor/core/reshapers/picker.py
+
31
−
109
View file @
56b0fb87
...
@@ -11,8 +11,9 @@ from agora.abc import ParametersABC
...
@@ -11,8 +11,9 @@ from agora.abc import ParametersABC
from
agora.io.cells
import
Cells
from
agora.io.cells
import
Cells
from
utils_find_1st
import
cmp_equal
,
find_1st
from
utils_find_1st
import
cmp_equal
,
find_1st
from
postprocessor.core.
abc
import
Post
Process
ABC
from
postprocessor.core.
lineageprocess
import
Lineage
Process
from
postprocessor.core.functions.tracks
import
max_nonstop_ntps
,
max_ntps
from
postprocessor.core.functions.tracks
import
max_nonstop_ntps
,
max_ntps
from
agora.utils.association
import
validate_association
class
pickerParameters
(
ParametersABC
):
class
pickerParameters
(
ParametersABC
):
...
@@ -28,7 +29,7 @@ class pickerParameters(ParametersABC):
...
@@ -28,7 +29,7 @@ class pickerParameters(ParametersABC):
}
}
class
picker
(
Post
Process
ABC
):
class
picker
(
Lineage
Process
):
"""
"""
:cells: Cell object passed to the constructor
:cells: Cell object passed to the constructor
:condition: Tuple with condition and associated parameter(s), conditions can be
:condition: Tuple with condition and associated parameter(s), conditions can be
...
@@ -44,124 +45,45 @@ class picker(PostProcessABC):
...
@@ -44,124 +45,45 @@ class picker(PostProcessABC):
):
):
super
().
__init__
(
parameters
=
parameters
)
super
().
__init__
(
parameters
=
parameters
)
self
.
_
cells
=
cells
self
.
cells
=
cells
def
pick_by_lineage
(
self
,
signal
s
,
how
):
def
pick_by_lineage
(
self
,
signal
,
how
):
self
.
orig_signals
=
signal
s
self
.
orig_signals
=
signal
idx
=
signals
.
index
idx
=
np
.
array
(
signal
.
index
.
to_list
())
mothers_daughters
=
self
.
cells
.
mothers_daughters
if
how
:
valid_indices
,
valid_lineage
=
[
slice
(
None
)]
*
2
mothers
=
set
(
self
.
mothers
)
daughters
=
set
(
self
.
daughters
)
# daughters, mothers = np.where(mother_bud_mat)
def
search
(
a
,
b
):
return
np
.
where
(
np
.
in1d
(
np
.
ravel_multi_index
(
np
.
array
(
a
).
T
,
np
.
array
(
a
).
max
(
0
)
+
1
),
np
.
ravel_multi_index
(
np
.
array
(
b
).
T
,
np
.
array
(
a
).
max
(
0
)
+
1
),
)
)
if
how
==
"
mothers
"
:
idx
=
mothers
elif
how
==
"
daughters
"
:
idx
=
daughters
elif
how
==
"
daughters_w_mothers
"
:
present_mothers
=
idx
.
intersection
(
mothers
)
idx
=
set
(
[
tuple
(
x
)
for
m
in
present_mothers
for
x
in
np
.
array
(
self
.
daughters
)[
search
(
self
.
mothers
,
m
)
]
]
)
print
(
"
associated daughters:
"
,
idx
)
elif
how
==
"
mothers_w_daughters
"
:
present_daughters
=
idx
.
intersection
(
daughters
)
idx
=
set
(
[
tuple
(
x
)
for
d
in
present_daughters
for
x
in
np
.
array
(
self
.
mothers
)[
search
(
self
.
daughters
,
d
)
]
]
)
elif
how
==
"
full_families
"
:
present_mothers
=
idx
.
intersection
(
mothers
)
dwm_idx
=
set
(
[
tuple
(
x
)
for
m
in
present_mothers
for
x
in
np
.
array
(
self
.
daughters
)[
search
(
np
.
array
(
self
.
mothers
),
m
)
]
]
)
present_daughters
=
idx
.
intersection
(
daughters
)
mwd_idx
=
set
(
[
tuple
(
x
)
for
d
in
present_daughters
for
x
in
np
.
array
(
self
.
mothers
)[
search
(
np
.
array
(
self
.
daughters
),
d
)
]
]
)
idx
=
mwd_idx
.
union
(
dwm_idx
)
elif
how
==
"
families
"
or
how
==
"
orphans
"
:
families
=
mothers
.
union
(
daughters
)
if
how
==
"
families
"
:
idx
=
families
elif
how
==
"
orphans
"
:
idx
=
idx
.
diference
(
families
)
idx
=
idx
.
intersection
(
signals
.
index
)
return
idx
if
how
==
"
mothers
"
:
valid_lineage
,
valid_indices
=
validate_association
(
mothers_daughters
,
idx
,
match_column
=
0
)
elif
how
==
"
daughters
"
:
valid_lineage
,
valid_indices
=
validate_association
(
mothers_daughters
,
idx
,
match_column
=
0
)
elif
how
==
"
families
"
:
# Mothers and daughters that are still present
valid_lineage
,
valid_indices
=
validate_association
(
mothers_daughters
,
idx
,
match_column
=
0
)
idx
=
idx
[
valid_indices
]
mothers_daughters
=
mothers_daughters
[
valid_lineage
]
return
mothers_daughters
,
idx
def
loc_lineage
(
self
,
signals
:
pd
.
DataFrame
,
how
:
str
):
_
,
valid_indices
=
self
.
pick_by_lineage
(
signals
,
how
)
return
signals
.
loc
[
valid_indices
]
def
pick_by_condition
(
self
,
signals
,
condition
,
thresh
):
def
pick_by_condition
(
self
,
signals
,
condition
,
thresh
):
idx
=
self
.
switch_case
(
signals
,
condition
,
thresh
)
idx
=
self
.
switch_case
(
signals
,
condition
,
thresh
)
return
idx
return
idx
def
get_mothers_daughters
(
self
):
ma
=
self
.
_cells
[
"
mother_assign_dynamic
"
]
trap
=
self
.
_cells
[
"
trap
"
]
label
=
self
.
_cells
[
"
cell_label
"
]
nested_massign
=
self
.
_cells
.
mother_assign_from_dynamic
(
ma
,
label
,
trap
,
self
.
_cells
.
ntraps
)
# mother_bud_mat = self.mother_assign_to_mb_matrix(nested_massign)
if
sum
([
x
for
y
in
nested_massign
for
x
in
y
]):
mothers
,
daughters
=
zip
(
*
[
((
tid
,
m
),
(
tid
,
d
))
for
tid
,
trapcells
in
enumerate
(
nested_massign
)
for
d
,
m
in
enumerate
(
trapcells
,
1
)
if
m
]
)
else
:
mothers
,
daughters
=
([],
[])
print
(
"
Warning:Picker: No mother-daughters assigned
"
)
return
mothers
,
daughters
def
run
(
self
,
signals
):
def
run
(
self
,
signals
):
self
.
orig_signals
=
signals
self
.
orig_signals
=
signals
indices
=
set
(
signals
.
index
)
indices
=
set
(
signals
.
index
)
self
.
mothers
,
self
.
daughters
=
self
.
get_
mothers_daughters
()
self
.
mothers
,
self
.
daughters
=
self
.
cells
.
mothers_daughters
for
alg
,
op
,
*
params
in
self
.
sequence
:
for
alg
,
op
,
*
params
in
self
.
sequence
:
new_indices
=
tuple
()
new_indices
=
tuple
()
if
indices
:
if
indices
:
...
...
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