FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit f7267ee6 authored by Argyris Z's avatar Argyris Z
Browse files

Cleanup

parent c5e7badf
No related branches found
No related tags found
No related merge requests found
%% 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')
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment