FAQ
| This is a
LIVE
service |
Changelog
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Refahi_etal_2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sainsbury Laboratory
teamHJ
publications
Refahi_etal_2020
Commits
dc0c2ab9
Commit
dc0c2ab9
authored
4 years ago
by
yassin.refahi
Browse files
Options
Downloads
Patches
Plain Diff
add dynamic tissue to AtlasViewer
parent
ebab3bf3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
atlasviewer/atlasviewer/dtissue.py
+140
-0
140 additions, 0 deletions
atlasviewer/atlasviewer/dtissue.py
with
140 additions
and
0 deletions
atlasviewer/atlasviewer/dtissue.py
0 → 100755
+
140
−
0
View file @
dc0c2ab9
import
cPickle
import
numpy
as
np
from
atlasviewer.avtiff
import
voxelDimensionsFromTiffFile
,
avimread
class
DTissue
(
object
):
def
__init__
(
self
,
timePoints
=
None
,
background
=
1
):
self
.
timePoints
=
timePoints
self
.
background
=
1
if
self
.
timePoints
is
not
None
:
self
.
dtissue
=
{
tp
:
{}
for
tp
in
self
.
timePoints
}
else
:
self
.
dtissue
=
{}
def
setSegmentationFiles
(
self
,
timePointSegmentationFiles
):
for
tp
in
self
.
dtissue
:
self
.
dtissue
[
tp
][
"
segmentation_file
"
]
=
timePointSegmentationFiles
[
tp
]
def
setResolutions
(
self
,
resolutions
=
None
):
if
resolutions
is
None
:
for
tp
in
self
.
dtissue
:
fn
=
self
.
dtissue
[
tp
][
"
segmentation_file
"
]
res
=
voxelDimensionsFromTiffFile
(
fn
)
self
.
dtissue
[
tp
][
"
resolution
"
]
=
res
else
:
for
tp
in
self
.
dtissue
:
self
.
dtissue
[
tp
][
"
resolution
"
]
=
resolutions
[
tp
]
def
extractLabels
(
self
):
print
"
Extraing labels ...
"
for
tp
in
self
.
dtissue
:
image
,
info
=
avimread
(
self
.
dtissue
[
tp
][
"
segmentation_file
"
])
labels
=
list
(
np
.
unique
(
image
))
self
.
dtissue
[
tp
][
"
labels
"
]
=
labels
print
tp
,
print
"
\n
Done.
"
def
computeVolumes
(
self
):
volumesDict
=
{}
print
"
Computing volumes ...
"
for
tp
in
self
.
dtissue
:
print
tp
image
,
tags
=
avimread
(
self
.
dtissue
[
tp
][
"
segmentation_file
"
])
bc
=
np
.
bincount
(
image
.
flatten
())
voxelS
=
np
.
prod
(
self
.
dtissue
[
tp
][
"
resolution
"
])
vols
=
bc
*
voxelS
self
.
dtissue
[
tp
][
"
volumes
"
]
=
{
cid
:
vols
[
cid
]
for
cid
in
self
.
dtissue
[
tp
][
"
labels
"
]
if
cid
!=
self
.
background
}
print
"
Done.
"
def
setRealTimepoints
(
self
,
realTPD
):
for
tp
in
self
.
dtissue
:
self
.
dtissue
[
tp
][
"
real_timepoint
"
]
=
realTPD
[
tp
]
def
getDaughters
(
self
,
motherTp
,
motherId
):
try
:
return
self
.
dtissue
[
motherTp
][
"
daughters
"
][
motherId
]
except
AttributeError
,
e
:
print
"
Daughters property is not set.
"
def
getMother
(
self
,
daughterTp
,
daughterId
):
try
:
return
self
.
dtissue
[
daughterTp
][
"
mother
"
][
daughterId
]
except
AttributeError
,
e
:
print
"
Daughters property is not set.
"
def
__getitem__
(
self
,
index
):
return
self
.
dtissue
[
index
]
def
extractDescendants
(
self
,
motherTp
,
motherCellId
,
descendantsTp
):
family
=
{
motherTp
:
[
motherCellId
]}
motherTpIndex
,
desesendantsTpIndex
=
self
.
timePoints
.
index
(
motherTp
),
self
.
timePoints
.
index
(
descendantsTp
)
for
ind
in
xrange
(
motherTpIndex
,
desesendantsTpIndex
):
tp
=
self
.
timePoints
[
ind
]
family
[
self
.
timePoints
[
ind
+
1
]]
=
[]
for
cid
in
family
[
tp
]:
family
[
self
.
timePoints
[
ind
+
1
]].
extend
(
self
.
dtissue
[
tp
][
"
daughters
"
][
cid
])
return
family
[
descendantsTp
]
def
setTrackingFiles
(
self
,
trackingFileNames
):
for
(
tp0
,
tp1
),
fname
in
trackingFileNames
.
iteritems
():
tp
=
tp0
self
.
dtissue
[
tp
][
"
daughters
"
]
=
{}
fobj
=
file
(
fname
)
tracking
=
cPickle
.
load
(
fobj
)[
0
]
fobj
.
close
()
for
(
daughter
,
mother
)
in
tracking
:
self
.
dtissue
[
tp
][
"
daughters
"
].
setdefault
(
mother
,
[]).
append
(
daughter
)
for
cid
in
(
set
(
self
.
dtissue
[
tp
][
"
labels
"
])
-
set
(
self
.
dtissue
[
tp
][
"
daughters
"
].
keys
())):
self
.
dtissue
[
tp
][
"
daughters
"
][
cid
]
=
[]
for
(
tp0
,
tp1
),
fname
in
trackingFileNames
.
iteritems
():
tp
=
tp1
self
.
dtissue
[
tp
][
"
mother
"
]
=
{}
fobj
=
file
(
fname
)
tracking
=
cPickle
.
load
(
fobj
)[
0
]
fobj
.
close
()
for
(
daughter
,
mother
)
in
tracking
:
self
.
dtissue
[
tp
][
"
mother
"
][
daughter
]
=
mother
for
cid
in
(
set
(
self
.
dtissue
[
tp
][
"
labels
"
])
-
set
(
self
.
dtissue
[
tp
][
"
mother
"
].
keys
())):
self
.
dtissue
[
tp
][
"
mother
"
][
cid
]
=
-
1
def
setPatternFiles
(
self
,
patternFNames
):
for
tp
,
fn
in
patternFNames
.
iteritems
():
fobj
=
file
(
fn
)
patterns
=
cPickle
.
load
(
fobj
)
fobj
.
close
()
self
.
dtissue
[
tp
][
"
patterns
"
]
=
patterns
print
tp
,
"
L1:
"
,
patterns
[
"
L1
"
]
def
computeGrowthRate
(
self
,
sourceTP
,
targetTP
):
growthRate
=
{}
withDes
=
[]
growth
=
[]
deltaT
=
(
self
.
dtissue
[
targetTP
][
"
real_timepoint
"
]
-
self
.
dtissue
[
sourceTP
][
"
real_timepoint
"
])
for
cid
in
self
.
dtissue
[
sourceTP
][
"
labels
"
]:
if
cid
!=
self
.
background
:
descendants
=
self
.
extractDescendants
(
sourceTP
,
cid
,
targetTP
)
if
len
(
descendants
)
>
0
:
# and (cid in self.dtissue[sourceTP]["patterns"]["L1"]):
dVolume
=
sum
([
self
.
dtissue
[
targetTP
][
"
volumes
"
][
did
]
for
did
in
descendants
])
mVolume
=
self
.
dtissue
[
sourceTP
][
"
volumes
"
][
cid
]
growthRate
[
cid
]
=
(
dVolume
-
mVolume
)
/
(
deltaT
*
mVolume
)
return
growthRate
def
computeRelativeGrowthRate
(
self
,
sourceTP
,
targetTP
):
relativeGrowthRate
=
{}
withDes
=
[]
growth
=
[]
deltaT
=
(
self
.
dtissue
[
targetTP
][
"
real_timepoint
"
]
-
self
.
dtissue
[
sourceTP
][
"
real_timepoint
"
])
for
cid
in
self
.
dtissue
[
sourceTP
][
"
labels
"
]:
if
cid
!=
self
.
background
:
descendants
=
self
.
extractDescendants
(
sourceTP
,
cid
,
targetTP
)
if
len
(
descendants
)
>
0
:
# and (cid in self.dtissue[sourceTP]["patterns"]["L1"]):
dVolume
=
sum
([
self
.
dtissue
[
targetTP
][
"
volumes
"
][
did
]
for
did
in
descendants
])
mVolume
=
self
.
dtissue
[
sourceTP
][
"
volumes
"
][
cid
]
relativeGrowthRate
[
cid
]
=
(
dVolume
-
mVolume
)
/
(
deltaT
*
mVolume
)
return
relativeGrowthRate
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