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
Admin message
GitLab has been upgraded. See what's new in the
Changelog
.
Show more breadcrumbs
Sainsbury Laboratory
teamHJ
publications
Refahi_etal_2020
Commits
f7267ee6
Commit
f7267ee6
authored
4 years ago
by
Argyris Z
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
c5e7badf
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
growthAnalysis/anisos.ipynb
+7
-161
7 additions, 161 deletions
growthAnalysis/anisos.ipynb
with
7 additions
and
161 deletions
growthAnalysis/anisos.ipynb
+
7
−
161
View file @
f7267ee6
...
...
@@ -19,20 +19,6 @@
"import matplotlib.ticker as ticker"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_params = {'01' : {'elev': 120, 'azim' : 270, 'vmax':0.4},\n",
" '02' : {'elev': 70, 'azim' : -20, 'vmax':0.3},\n",
" '03' : {'elev': 90, 'azim' : 270, 'vmax':0.2},\n",
" '04' : {'elev':80, 'azim': 50, 'vmax': 0.2},\n",
" '05' : {'elev':70, 'azim': 220, 'vmax':0.2},\n",
" '06' : {'elev':90, 'azim': 270, 'vmax':0.2}}"
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -69,39 +55,11 @@
"metadata": {},
"outputs": [],
"source": [
"#fid='01'\n",
"#tssFn = \"lins_allflowers/f\" + fid + \"_tss.pkl\"\n",
"#linssFn = \"lins_allflowers/f\" + fid + \"_linss.pkl\"\n",
"\n",
"#with open(tssFn, 'rb') as tssF:\n",
"# tss = cPickle.load(tssF, encoding='latin1')\n",
"\n",
"#with open(linssFn, 'rb') as linssF:\n",
"# linss = cPickle.load(linssF, encoding='latin1')\n",
"\n",
"#if fid=='01':\n",
"# lin.filterL1(tss)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dataDir = \"../data/\"\n",
"tss, linss = lin.mkSeries1(dataDir)\n",
"lin.filterL1(tss)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import importlib\n",
"importlib.reload(seg)"
"#load FM1 at specified timepoints\n",
"tss, linss = lin.mkSeries1(d=\"../data/FM1/tv/\",\n",
" dExprs=\"../data/geneExpression/\",\n",
" linDataLoc=\"../data/FM1/tracking_data/\",\n",
" ft=lambda t: t in {10, 40, 96, 120, 132})"
]
},
{
...
...
@@ -117,9 +75,8 @@
"metadata": {},
"outputs": [],
"source": [
"fid='01'\n",
"G = p.mkTGraphN()\n",
"regs = seg.getCellRegions(dataDir=dataDir, fid=
fid
, d=3)"
"regs = seg.getCellRegions(dataDir=dataDir, fid=
'01'
, d=3)"
]
},
{
...
...
@@ -268,117 +225,6 @@
" plt.savefig(fout, dpi=300, bbox_inches='tight')\n",
" plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Anisotropy distributions (all to all timepoints)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fid='01'\n",
"#regs = seg.getCellRegions(fid=fid, d=3)\n",
"#tss_all = cPickle.load(file(\"lins_allflowers/f\" + fid + \"_tss.pkl\"))\n",
"#linss = cPickle.load(file(\"lins_allflowers/f\" + fid + \"_linss.pkl\"))\n",
"\n",
"if fid == '01':\n",
" lin.filterL1(tss_all)\n",
" tss = tss_all\n",
"else:\n",
" tss = dict([(t, seg.filterL1(ts)) for t, ts in tss_all.iteritems()])\n",
" \n",
"timepoints = sorted(tss.keys())[::2]\n",
"n = len(timepoints)\n",
"\n",
"fig = plt.figure(figsize=(10, 8))\n",
"plt.subplots_adjust(hspace=0.85, wspace=0.5)\n",
"\n",
"for i, t1 in enumerate(timepoints):\n",
" for k, t2 in enumerate(timepoints):\n",
" print(t1, end=\",\")\n",
" print(t2, end=\" \")\n",
" if t1 > t2:\n",
" ax = plt.subplot2grid((n, n), (i, k))\n",
" #plot forward\n",
" plt.rcParams.update({'font.size': 8})\n",
" ax.set_title(str(t2) + \"h\" + \"-\" + str(t1)+\"h\")\n",
" plt.rcParams.update({'font.size': 10})\n",
" ax.set_xlim([-0.05, 1.05])\n",
" ax.set_xticks([0.0, 0.5, 1.0])\n",
" ans = aniso.ganisos_forward(regs, tss, linss, t2, t1)\n",
" ans_ = np.array([an for _, an in ans.items() if an])\n",
" sns.distplot(ans_, ax=ax) \n",
" \n",
"plt.savefig(\"aniso_calcs/anisotropy_rates_f\" + str(fid) + \"_allTs.png\", dpi=300, bbox_inches='tight')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Anisotropy distributions (all to all timepoints) on templates"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def plot_ans(ts, ans, ax, s=30, vmax=0.5):\n",
" xs = [c.pos.x for c in ts]\n",
" ys = [c.pos.y for c in ts]\n",
" zs = [c.pos.z for c in ts]\n",
" cs = [ans.get(c.cid, 0.0) for c in ts]\n",
" vmax = max(cs)\n",
" \n",
" \n",
" points = ax.scatter(xs, ys, zs, c=cs, cmap=plt.cm.jet, alpha=0.9, s=s, vmin=0.0, vmax=vmax,\n",
" edgecolors='black', linewidths=0.5)\n",
" plt.colorbar(points, shrink=0.5, ticks=[0.0, vmax])\n",
" plt.axis('off')\n",
" \n",
" return\n",
"\n",
"fig = plt.figure(figsize=(20, 15))\n",
"timepoints = sorted(tss.keys())\n",
"n=len(timepoints)\n",
"\n",
"for i, t1 in enumerate(timepoints):\n",
" for k, t2 in enumerate(timepoints):\n",
" print(t1, t2, end=\" \")\n",
" if t1 < t2:\n",
" ax = plt.subplot2grid((n, n), (i, k), projection='3d')\n",
" ax.set_title(str(t1)+\"h\" + \"-\" + str(t2) + \"h\")\n",
" ax.view_init(elev=plot_params[fid]['elev'], azim=plot_params[fid]['azim'])\n",
" #plot\n",
" ans = aniso.ganisos_forward(regs, tss, linss, t1, t2)\n",
" ans_ = dict([(cid, an) for cid, an in ans.items() if an])\n",
" plot_ans(tss[t1], ans_, ax, s=60)\n",
" elif t1 > t2:\n",
" ax = plt.subplot2grid((n, n), (i, k), projection='3d')\n",
" ax.set_title(str(t2)+\"h\" + \"-\" + str(t1) + \"h\")\n",
" ax.view_init(elev=plot_params[fid]['elev'], azim=plot_params[fid]['azim'])\n",
" #plot\n",
" ans = aniso.ganisos_backward(regs, tss, linss, t2, t1)\n",
" ans_ = dict([(cid, an) for cid, an in ans.items() if an])\n",
" plot_ans(tss[t1], ans_, ax, s=60)\n",
" else:\n",
" ax = plt.subplot2grid((n, n), (i, k))\n",
" ax.set_xlim(0.0, 1.0)\n",
" ax.set_ylim(0.0, 1.0)\n",
" ax.text(0.4, 0.5, str(t1)+\"h\", transform = ax.transAxes, fontsize=9)\n",
" ax.axis('off')\n",
" \n",
"fout = \"anisotropy_allTs_{fid}.png\".format(fid=fid)\n",
"plt.savefig(fout, dpi=300, bbox_inches='tight')"
]
}
],
"metadata": {
...
...
@@ -397,7 +243,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.
7
.4"
"version": "3.
6
.4"
}
},
"nbformat": 4,
...
...
%% Cell type:code id: tags:
```
python
import
patternTransitions
as
p
from
itertools
import
repeat
import
seaborn
as
sns
import
matplotlib.pyplot
as
plt
from
mpl_toolkits.mplot3d
import
Axes3D
import
common.seg
as
seg
import
_pickle
as
cPickle
import
aniso
import
numpy
as
np
import
common.lin
as
lin
import
matplotlib.ticker
as
ticker
```
%% Cell type:code id: tags:
```
python
plot_params
=
{
'
01
'
:
{
'
elev
'
:
120
,
'
azim
'
:
270
,
'
vmax
'
:
0.4
},
'
02
'
:
{
'
elev
'
:
70
,
'
azim
'
:
-
20
,
'
vmax
'
:
0.3
},
'
03
'
:
{
'
elev
'
:
90
,
'
azim
'
:
270
,
'
vmax
'
:
0.2
},
'
04
'
:
{
'
elev
'
:
80
,
'
azim
'
:
50
,
'
vmax
'
:
0.2
},
'
05
'
:
{
'
elev
'
:
70
,
'
azim
'
:
220
,
'
vmax
'
:
0.2
},
'
06
'
:
{
'
elev
'
:
90
,
'
azim
'
:
270
,
'
vmax
'
:
0.2
}}
```
%% Cell type:code id: tags:
```
python
def
mkViolinPlot
(
d
,
ax
,
ws
=
0.7
):
xs_labs
=
sorted
(
d
.
keys
())
xs
=
range
(
len
(
xs_labs
))
ys
=
[
d
[
x
]
for
x
in
xs_labs
]
ax
.
yaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
0.005
))
sns
.
set_style
(
"
whitegrid
"
,
{
'
grid.linestyle
'
:
'
--
'
})
cls
=
sns
.
color_palette
()
ax
.
set_xticks
(
xs
)
ax
.
set_xticklabels
(
xs_labs
)
violin_parts
=
ax
.
violinplot
(
ys
,
xs
,
showmeans
=
True
,
widths
=
ws
)
for
pc
in
violin_parts
[
'
bodies
'
]:
pc
.
set_facecolor
(
"
#f5d742
"
)
pc
.
set_edgecolor
(
'
black
'
)
for
partname
in
(
'
cbars
'
,
'
cmins
'
,
'
cmaxes
'
,
'
cmeans
'
):
vp
=
violin_parts
[
partname
]
vp
.
set_edgecolor
(
'
red
'
)
vp
.
set_linewidth
(
0.5
)
plt
.
xticks
(
rotation
=
90
)
```
%% Cell type:code id: tags:
```
python
#fid='01'
#tssFn = "lins_allflowers/f" + fid + "_tss.pkl"
#linssFn = "lins_allflowers/f" + fid + "_linss.pkl"
#with open(tssFn, 'rb') as tssF:
# tss = cPickle.load(tssF, encoding='latin1')
#with open(linssFn, 'rb') as linssF:
# linss = cPickle.load(linssF, encoding='latin1')
#if fid=='01':
# lin.filterL1(tss)
```
%% Cell type:code id: tags:
```
python
dataDir
=
"
../data/
"
tss
,
linss
=
lin
.
mkSeries1
(
dataDir
)
lin
.
filterL1
(
tss
)
```
%% Cell type:code id: tags:
```
python
import
importlib
importlib
.
reload
(
seg
)
#load FM1 at specified timepoints
tss
,
linss
=
lin
.
mkSeries1
(
d
=
"
../data/FM1/tv/
"
,
dExprs
=
"
../data/geneExpression/
"
,
linDataLoc
=
"
../data/FM1/tracking_data/
"
,
ft
=
lambda
t
:
t
in
{
10
,
40
,
96
,
120
,
132
})
```
%% Cell type:markdown id: tags:
## Per pattern
%% Cell type:code id: tags:
```
python
fid
=
'
01
'
G
=
p
.
mkTGraphN
()
regs
=
seg
.
getCellRegions
(
dataDir
=
dataDir
,
fid
=
fid
,
d
=
3
)
regs
=
seg
.
getCellRegions
(
dataDir
=
dataDir
,
fid
=
'
01
'
,
d
=
3
)
```
%% Cell type:code id: tags:
```
python
gans
=
p
.
calcAnisotropies
(
regs
,
tss
,
linss
)
gans_pat
=
p
.
addCombPatterns
(
gans
,
tss
)
gans_state
=
p
.
getGAnisosPerPattern
(
G
,
gans_pat
)
```
%% Cell type:code id: tags:
```
python
plt
.
rcParams
.
update
({
'
font.size
'
:
12
})
fig
=
plt
.
figure
(
figsize
=
(
9
,
4.5
))
ax
=
fig
.
add_subplot
(
'
111
'
)
ax
.
set_xlabel
(
"
cell state
"
)
ax
.
set_ylabel
(
r
'
anisotropy rate ($h^{-1}$)
'
)
ax
.
yaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
0.05
))
mkViolinPlot
(
gans_state
,
ax
)
fout
=
"
pattern_anisotropy.png
"
plt
.
savefig
(
fout
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
def
tToStage
(
t
):
if
t
==
10
:
return
0
elif
t
==
40
:
return
1
elif
t
==
96
:
return
2
elif
t
==
120
:
return
3
elif
t
==
132
:
return
4
```
%% Cell type:markdown id: tags:
## Per pattern on graph
%% Cell type:code id: tags:
```
python
G
=
p
.
mkTGraphN
()
p
.
addGAnisos
(
G
,
gans_pat
)
```
%% Cell type:code id: tags:
```
python
p
.
drawTGraph
(
G
,
p
.
ganiso
)
```
%% Cell type:markdown id: tags:
## Per gene
%% Cell type:code id: tags:
```
python
gans_gene
=
p
.
getGAnisosPerGene
(
tss
,
gans
)
```
%% Cell type:code id: tags:
```
python
fig
=
plt
.
figure
(
figsize
=
(
10
,
5
))
ax
=
fig
.
add_subplot
(
'
111
'
)
ax
.
set_xlabel
(
"
gene
"
)
ax
.
set_ylabel
(
r
'
anisotropy ($h^{-1}$)
'
)
ax
.
yaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
0.05
))
mkViolinPlot
(
gans_gene
,
ax
)
fout
=
"
gene_anisotropy.png
"
plt
.
savefig
(
fout
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
plt
.
show
()
```
%% Cell type:markdown id: tags:
## Per gene, per stage
%% Cell type:code id: tags:
```
python
gans_gene_time
=
p
.
getGAnisosPerGeneTime
(
tss
,
gans
)
```
%% Cell type:code id: tags:
```
python
for
t
in
sorted
(
gans_gene_time
.
keys
()):
fig
=
plt
.
figure
(
figsize
=
(
10
,
5
))
ax
=
fig
.
add_subplot
(
'
111
'
)
ax
.
set_title
(
"
stage {t}
"
.
format
(
t
=
tToStage
(
t
)))
ax
.
set_xlabel
(
"
gene
"
)
ax
.
set_ylabel
(
r
'
anisotropy ($h^{-1}$)
'
)
ax
.
set_ylim
((
0.0
,
0.03
))
ax
.
yaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
0.05
))
mkViolinPlot
(
gans_gene_time
[
t
],
ax
,
ws
=
0.4
)
fout
=
"
gene_anisotropy_{t}.png
"
.
format
(
t
=
t
)
plt
.
savefig
(
fout
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
plt
.
show
()
```
%% Cell type:markdown id: tags:
## Anisotropy distributions (all to all timepoints)
%% Cell type:code id: tags:
```
python
fid
=
'
01
'
#regs = seg.getCellRegions(fid=fid, d=3)
#tss_all = cPickle.load(file("lins_allflowers/f" + fid + "_tss.pkl"))
#linss = cPickle.load(file("lins_allflowers/f" + fid + "_linss.pkl"))
if
fid
==
'
01
'
:
lin
.
filterL1
(
tss_all
)
tss
=
tss_all
else
:
tss
=
dict
([(
t
,
seg
.
filterL1
(
ts
))
for
t
,
ts
in
tss_all
.
iteritems
()])
timepoints
=
sorted
(
tss
.
keys
())[::
2
]
n
=
len
(
timepoints
)
fig
=
plt
.
figure
(
figsize
=
(
10
,
8
))
plt
.
subplots_adjust
(
hspace
=
0.85
,
wspace
=
0.5
)
for
i
,
t1
in
enumerate
(
timepoints
):
for
k
,
t2
in
enumerate
(
timepoints
):
print
(
t1
,
end
=
"
,
"
)
print
(
t2
,
end
=
"
"
)
if
t1
>
t2
:
ax
=
plt
.
subplot2grid
((
n
,
n
),
(
i
,
k
))
#plot forward
plt
.
rcParams
.
update
({
'
font.size
'
:
8
})
ax
.
set_title
(
str
(
t2
)
+
"
h
"
+
"
-
"
+
str
(
t1
)
+
"
h
"
)
plt
.
rcParams
.
update
({
'
font.size
'
:
10
})
ax
.
set_xlim
([
-
0.05
,
1.05
])
ax
.
set_xticks
([
0.0
,
0.5
,
1.0
])
ans
=
aniso
.
ganisos_forward
(
regs
,
tss
,
linss
,
t2
,
t1
)
ans_
=
np
.
array
([
an
for
_
,
an
in
ans
.
items
()
if
an
])
sns
.
distplot
(
ans_
,
ax
=
ax
)
plt
.
savefig
(
"
aniso_calcs/anisotropy_rates_f
"
+
str
(
fid
)
+
"
_allTs.png
"
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
```
%% Cell type:markdown id: tags:
## Anisotropy distributions (all to all timepoints) on templates
%% Cell type:code id: tags:
```
python
def
plot_ans
(
ts
,
ans
,
ax
,
s
=
30
,
vmax
=
0.5
):
xs
=
[
c
.
pos
.
x
for
c
in
ts
]
ys
=
[
c
.
pos
.
y
for
c
in
ts
]
zs
=
[
c
.
pos
.
z
for
c
in
ts
]
cs
=
[
ans
.
get
(
c
.
cid
,
0.0
)
for
c
in
ts
]
vmax
=
max
(
cs
)
points
=
ax
.
scatter
(
xs
,
ys
,
zs
,
c
=
cs
,
cmap
=
plt
.
cm
.
jet
,
alpha
=
0.9
,
s
=
s
,
vmin
=
0.0
,
vmax
=
vmax
,
edgecolors
=
'
black
'
,
linewidths
=
0.5
)
plt
.
colorbar
(
points
,
shrink
=
0.5
,
ticks
=
[
0.0
,
vmax
])
plt
.
axis
(
'
off
'
)
return
fig
=
plt
.
figure
(
figsize
=
(
20
,
15
))
timepoints
=
sorted
(
tss
.
keys
())
n
=
len
(
timepoints
)
for
i
,
t1
in
enumerate
(
timepoints
):
for
k
,
t2
in
enumerate
(
timepoints
):
print
(
t1
,
t2
,
end
=
"
"
)
if
t1
<
t2
:
ax
=
plt
.
subplot2grid
((
n
,
n
),
(
i
,
k
),
projection
=
'
3d
'
)
ax
.
set_title
(
str
(
t1
)
+
"
h
"
+
"
-
"
+
str
(
t2
)
+
"
h
"
)
ax
.
view_init
(
elev
=
plot_params
[
fid
][
'
elev
'
],
azim
=
plot_params
[
fid
][
'
azim
'
])
#plot
ans
=
aniso
.
ganisos_forward
(
regs
,
tss
,
linss
,
t1
,
t2
)
ans_
=
dict
([(
cid
,
an
)
for
cid
,
an
in
ans
.
items
()
if
an
])
plot_ans
(
tss
[
t1
],
ans_
,
ax
,
s
=
60
)
elif
t1
>
t2
:
ax
=
plt
.
subplot2grid
((
n
,
n
),
(
i
,
k
),
projection
=
'
3d
'
)
ax
.
set_title
(
str
(
t2
)
+
"
h
"
+
"
-
"
+
str
(
t1
)
+
"
h
"
)
ax
.
view_init
(
elev
=
plot_params
[
fid
][
'
elev
'
],
azim
=
plot_params
[
fid
][
'
azim
'
])
#plot
ans
=
aniso
.
ganisos_backward
(
regs
,
tss
,
linss
,
t2
,
t1
)
ans_
=
dict
([(
cid
,
an
)
for
cid
,
an
in
ans
.
items
()
if
an
])
plot_ans
(
tss
[
t1
],
ans_
,
ax
,
s
=
60
)
else
:
ax
=
plt
.
subplot2grid
((
n
,
n
),
(
i
,
k
))
ax
.
set_xlim
(
0.0
,
1.0
)
ax
.
set_ylim
(
0.0
,
1.0
)
ax
.
text
(
0.4
,
0.5
,
str
(
t1
)
+
"
h
"
,
transform
=
ax
.
transAxes
,
fontsize
=
9
)
ax
.
axis
(
'
off
'
)
fout
=
"
anisotropy_allTs_{fid}.png
"
.
format
(
fid
=
fid
)
plt
.
savefig
(
fout
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
```
...
...
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