Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alibylite
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
alibylite
Commits
eb00e2b2
Commit
eb00e2b2
authored
1 year ago
by
pswain
Browse files
Options
Downloads
Patches
Plain Diff
feature(signal): make check on lineage assignment by validate_lineage optional
parent
fbc1d8f2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/agora/io/signal.py
+10
-6
10 additions, 6 deletions
src/agora/io/signal.py
src/agora/utils/indexing.py
+26
-19
26 additions, 19 deletions
src/agora/utils/indexing.py
with
36 additions
and
25 deletions
src/agora/io/signal.py
+
10
−
6
View file @
eb00e2b2
...
@@ -142,15 +142,15 @@ class Signal(BridgeH5):
...
@@ -142,15 +142,15 @@ class Signal(BridgeH5):
with
h5py
.
File
(
self
.
filename
,
"
r
"
)
as
f
:
with
h5py
.
File
(
self
.
filename
,
"
r
"
)
as
f
:
if
lineage_location
not
in
f
:
if
lineage_location
not
in
f
:
lineage_location
=
"
postprocessing/lineage
"
lineage_location
=
"
postprocessing/lineage
"
t
ile_mo_da
=
f
[
lineage_location
]
t
raps_mothers_daughters
=
f
[
lineage_location
]
if
isinstance
(
t
ile_mo_da
,
h5py
.
Dataset
):
if
isinstance
(
t
raps_mothers_daughters
,
h5py
.
Dataset
):
lineage
=
t
ile_mo_da
[()]
lineage
=
t
raps_mothers_daughters
[()]
else
:
else
:
lineage
=
np
.
array
(
lineage
=
np
.
array
(
(
(
t
ile_mo_da
[
"
trap
"
],
t
raps_mothers_daughters
[
"
trap
"
],
t
ile_mo_da
[
"
mother_label
"
],
t
raps_mothers_daughters
[
"
mother_label
"
],
t
ile_mo_da
[
"
daughter_label
"
],
t
raps_mothers_daughters
[
"
daughter_label
"
],
)
)
).
T
).
T
return
lineage
return
lineage
...
@@ -249,6 +249,7 @@ class Signal(BridgeH5):
...
@@ -249,6 +249,7 @@ class Signal(BridgeH5):
dataset
:
str
or
t
.
List
[
str
],
dataset
:
str
or
t
.
List
[
str
],
in_minutes
:
bool
=
True
,
in_minutes
:
bool
=
True
,
lineage
:
bool
=
False
,
lineage
:
bool
=
False
,
run_lineage_check
:
bool
=
True
,
**
kwargs
,
**
kwargs
,
)
->
pd
.
DataFrame
or
t
.
List
[
pd
.
DataFrame
]:
)
->
pd
.
DataFrame
or
t
.
List
[
pd
.
DataFrame
]:
"""
"""
...
@@ -262,6 +263,8 @@ class Signal(BridgeH5):
...
@@ -262,6 +263,8 @@ class Signal(BridgeH5):
If True, convert column headings to times in minutes.
If True, convert column headings to times in minutes.
lineage: boolean
lineage: boolean
If True, add mother_label to index.
If True, add mother_label to index.
run_lineage_check: boolean
If True, raise exception if a likely error in the lineage assignment.
"""
"""
try
:
try
:
if
isinstance
(
dataset
,
str
):
if
isinstance
(
dataset
,
str
):
...
@@ -279,6 +282,7 @@ class Signal(BridgeH5):
...
@@ -279,6 +282,7 @@ class Signal(BridgeH5):
lineage
,
lineage
,
indices
=
np
.
array
(
df
.
index
.
to_list
()),
indices
=
np
.
array
(
df
.
index
.
to_list
()),
how
=
"
daughters
"
,
how
=
"
daughters
"
,
run_lineage_check
=
run_lineage_check
,
)
)
mother_label
[
valid_indices
]
=
lineage
[
mother_label
[
valid_indices
]
=
lineage
[
valid_lineage
,
1
valid_lineage
,
1
...
...
This diff is collapsed.
Click to expand it.
src/agora/utils/indexing.py
+
26
−
19
View file @
eb00e2b2
...
@@ -5,7 +5,10 @@ i_dtype = {"names": ["trap_id", "cell_id"], "formats": [np.int64, np.int64]}
...
@@ -5,7 +5,10 @@ i_dtype = {"names": ["trap_id", "cell_id"], "formats": [np.int64, np.int64]}
def
validate_lineage
(
def
validate_lineage
(
lineage
:
np
.
ndarray
,
indices
:
np
.
ndarray
,
how
:
str
=
"
families
"
lineage
:
np
.
ndarray
,
indices
:
np
.
ndarray
,
how
:
str
=
"
families
"
,
run_lineage_check
:
bool
=
True
,
):
):
"""
"""
Identify mother-bud pairs both in lineage and a Signal
'
s indices.
Identify mother-bud pairs both in lineage and a Signal
'
s indices.
...
@@ -28,6 +31,9 @@ def validate_lineage(
...
@@ -28,6 +31,9 @@ def validate_lineage(
If
"
mothers
"
, matches indicate mothers from mother-bud pairs;
If
"
mothers
"
, matches indicate mothers from mother-bud pairs;
If
"
daughters
"
, matches indicate daughters from mother-bud pairs;
If
"
daughters
"
, matches indicate daughters from mother-bud pairs;
If
"
families
"
, matches indicate mothers and daughters in mother-bud pairs.
If
"
families
"
, matches indicate mothers and daughters in mother-bud pairs.
run_lineage_check: bool
If True, check for errors in the lineage assignment such as a daughter
being assigned two mothers.
Returns
Returns
-------
-------
...
@@ -85,24 +91,25 @@ def validate_lineage(
...
@@ -85,24 +91,25 @@ def validate_lineage(
valid_indices
=
index_isin
(
indices
,
selected_lineages
[:,
c_index
,
:])
valid_indices
=
index_isin
(
indices
,
selected_lineages
[:,
c_index
,
:])
flat_valid_indices
=
valid_indices
.
flatten
()
flat_valid_indices
=
valid_indices
.
flatten
()
# test for mismatch
# test for mismatch
if
how
==
"
families
"
:
if
run_lineage_check
:
test_mismatch
=
(
if
how
==
"
families
"
:
indices
[
flat_valid_indices
,
:].
size
test_mismatch
=
(
!=
np
.
unique
(
indices
[
flat_valid_indices
,
:].
size
lineage
[
flat_valid_lineage
,
:].
reshape
(
-
1
,
2
),
axis
=
0
!=
np
.
unique
(
).
size
lineage
[
flat_valid_lineage
,
:].
reshape
(
-
1
,
2
),
axis
=
0
)
).
size
else
:
)
test_mismatch
=
(
else
:
indices
[
flat_valid_indices
,
:].
size
test_mismatch
=
(
!=
lineage
[
flat_valid_lineage
,
c_index
,
:].
size
indices
[
flat_valid_indices
,
:].
size
)
!=
lineage
[
flat_valid_lineage
,
c_index
,
:].
size
if
test_mismatch
:
)
# all unique indices in valid_lineages should be in valid_indices
if
test_mismatch
:
raise
Exception
(
# all unique indices in valid_lineages should be in valid_indices
"
Error in validate_lineage:
"
raise
Exception
(
"
lineage information is likely not unique.
"
"
Error in validate_lineage:
"
)
"
lineage information is likely not unique.
"
)
return
flat_valid_lineage
,
flat_valid_indices
return
flat_valid_lineage
,
flat_valid_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