FAQ | This is a LIVE service | Changelog

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

Analysis of lfy mutant

parent 827ed750
No related branches found
No related tags found
No related merge requests found
from collections import defaultdict
import _pickle as cPickle
from os.path import join
import common.lin as lin
import common.seg as seg
import selected_cells_t47 as s
import pr
import grates_lfy as grateslf
import grates
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import math
from itertools import repeat
import growth_control as gc
def plot_ts_q_(ts, d, lb="vals", bounds=(0, 1), txt=""):
vmin, vmax = bounds
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 = [d[c.cid] for c in ts]
fig = plt.figure(figsize=(1.5, 1.5))
ax = fig.add_subplot(111, projection='3d')
ax.view_init(elev=-77, azim=-55)
ax.scatter(xs, ys, zs, c=cs, cmap="coolwarm", alpha=0.9, s=7, vmin=vmin,
vmax=vmax, edgecolors='black', linewidths=0.5)
ax.set_title(txt)
plt.axis('off')
fout = "comb_regions/{lb}.png".format(lb=lb)
plt.savefig(fout, dpi=300, bbox_inches='tight')
plt.show()
def convertLins(linD):
ts = [0, 9, 17, 24, 32, 39, 47, 57]
for t1, t2 in zip(ts, ts[1:]):
print(t1, t2)
linFn_ = "daughters_mothers_{t1}h_{t2}h.lin"
linFn = join(linD, linFn_.format(t1=str(t1),
t2=str(t2)))
with open(linFn, "rb") as linF:
ln = cPickle.load(linF, encoding="latin1")
x = defaultdict(list)
for d, m in ln[0]:
x[m].append(d)
txtLinFn = "{t1}hrs_to_{t2}hrs.txt"
with open(join(linD, txtLinFn.format(t1=str(t1), t2=str(t2))), "w") as fout:
rs = list()
for m, ds in x.items():
dsRepr = ",".join([str(d) for d in ds])
r = "{m}: {ds}".format(m=str(m), ds=dsRepr)
rs.append(r)
fout.write("\n".join(rs))
def read_filter_tss():
tss, linss = lin.mkSeriesGeomIm("/Users/s1437009/Downloads/")
cs_t47 = set.union(s.region_1,
s.region_2,
s.region_3,
s.region_4,
s.region_5)
tss[47].L1_cells = cs_t47
tss[47] = tss[47].filterL1()
with open("t47_L1.csv", "w") as fout:
fout.write(tss[47].toOrganism())
def cell_types():
ctyps = dict()
for cid in s.region_1:
ctyps[cid] = 1
for cid in s.region_2:
ctyps[cid] = 2
for cid in s.region_3:
ctyps[cid] = 3
for cid in s.region_4:
ctyps[cid] = 4
for cid in s.region_5:
ctyps[cid] = 5
return ctyps
def get_ctypes_():
fns = ["t47_centre.csv", # 1
"t47_boundaries.csv", # 2
"t47_insepals.csv", # 3
"t47_outsepals1.csv"] # 4
ctyps = dict()
for i, fn in enumerate(fns):
d = pr.read_csv(fn)
for cid in set([elem["id"] for elem in d]):
ctyps[cid] = i + 1
return ctyps
def get_ctypes_t39():
tss, linss = lin.mkSeriesGeomIm("/Users/s1437009/Downloads/")
ctyps = dict()
for cid in s.region1_t39(linss):
ctyps[cid] = 1
for cid in s.region2_t39(linss):
ctyps[cid] = 2
for cid in s.region3_t39(linss):
ctyps[cid] = 3
for cid in s.region4_t39(linss):
ctyps[cid] = 4
for cid in s.region5_t39(linss):
ctyps[cid] = 5
return ctyps
def gratio_ts(grs, r1, r2):
def gratio(xs, xs1):
if not xs or not xs1:
return np.nan
m1 = np.median(xs)
m2 = np.median(xs1)
return (m1 - m2) / (m1 + m2)
grs1 = [grs.get(cid, np.nan) for cid in r1]
grs2 = [grs.get(cid, np.nan) for cid in r2]
grs1_ = [gr for gr in grs1 if not math.isnan(gr)
and gr > -0.005 and gr < 0.15]
grs2_ = [gr for gr in grs2 if not math.isnan(gr)
and gr > -0.005 and gr < 0.15]
return gratio(grs1_, grs2_)
def plot_distrs(grs, r1, r2, lb):
grs1 = [grs[cid] for cid in r1 if grs[cid] > -0.005 and grs[cid] < 0.15]
grs2 = [grs[cid] for cid in r2 if grs[cid] > -0.005 and grs[cid] < 0.15]
cls = sns.color_palette("coolwarm")
fig = plt.figure(figsize=(3.5, 3.7))
ax = fig.add_subplot('111')
ax.set_xlim(-0.05, 0.18)
sns.distplot(grs1, bins=10, color=cls[-1], kde=True, ax=ax,
label="region1")
sns.distplot(grs2, bins=10, color=cls[0], kde=True, ax=ax,
label="region2")
ax.set_xlabel(r'$\mu$m/h'.format())
plt.savefig("comb_regions/zone{i}.png".format(i=lb), dpi=300)
plt.show()
def plot_distrs_strip(grs, r1, r2, lb):
grs1 = [grs.get(cid, np.nan) for cid in r1]
grs2 = [grs.get(cid, np.nan) for cid in r2]
grs1_ = [gr for gr in grs1 if not math.isnan(gr)
and gr > -0.005 and gr < 0.15]
grs2_ = [gr for gr in grs2 if not math.isnan(gr)
and gr > -0.005 and gr < 0.15]
m1 = np.median(grs1_)
m2 = np.median(grs2_)
gr = (m1 - m2) / (m1 + m2)
cls = sns.color_palette("coolwarm")
fig = plt.figure(figsize=(4, 3))
ax = fig.add_subplot('111')
ax.set_xlim(-0.05, 0.18)
ax.set_title("gr={:.3f}".format(gr))
xs = list(repeat(1, len(grs1_))) + list(repeat(1, len(grs2_)))
hs = list(repeat(1, len(grs1_))) + list(repeat(2, len(grs2_)))
ys = grs1_ + grs2_
sns.stripplot(xs, ys, hue=hs, ax=ax, alpha=0.25, palette={1: cls[0], 2:cls[-1]})
sns.pointplot([1, 1], [m1, m2], hue=[1, 2], join=False,
markers="d", scale=.75, ci=None, ax=ax, palette={1: cls[0], 2:cls[-1]})
ax.set_xlabel(r'$\mu$m/h'.format())
plt.savefig("comb_regions/zone{i}_strip.png".format(i=lb), dpi=300)
plt.show()
def plot_distrs_strip_(grs, grs_, r1, r2, r1_, r2_, lb):
grs1 = [grs.get(cid, np.nan) for cid in r1]
grs2 = [grs.get(cid, np.nan) for cid in r2]
grs1_ = [gr for gr in grs1 if not math.isnan(gr)]
grs2_ = [gr for gr in grs2 if not math.isnan(gr)]
grs1_1 = [grs_.get(cid, np.nan) for cid in r1_]
grs2_1 = [grs_.get(cid, np.nan) for cid in r2_]
grs1_1 = [gr for gr in grs1_1 if not math.isnan(gr)]
grs2_1 = [gr for gr in grs2_1 if not math.isnan(gr)]
m1 = np.mean(grs1_)
m2 = np.mean(grs2_)
m1_ = np.mean(grs1_1)
m2_ = np.mean(grs2_1)
cls = sns.color_palette("coolwarm")
fig = plt.figure(figsize=(4, 3))
ax = fig.add_subplot('111')
xs = (list(repeat("lfy", len(grs1_))) +
list(repeat("lfy", len(grs2_))) +
list(repeat("wt", len(grs1_1))) +
list(repeat("wt", len(grs2_1))))
hs = (list(repeat(1, len(grs1_))) +
list(repeat(2, len(grs2_))) +
list(repeat(1, len(grs1_1))) +
list(repeat(2, len(grs2_1))))
ys = grs1_ + grs2_ + grs1_1 + grs2_1
sns.stripplot(xs, ys, hue=hs, ax=ax, alpha=0.25,
palette={1: cls[-1], 2: cls[0]})
sns.pointplot([1, 1, 2, 2], [m1, m2, m1_, m2_],
hue=[1, 2, 1, 2], join=False,
markers="d", scale=.75, ci=None,
ax=ax, palette={1: cls[-1], 2: cls[0]})
ax.set_xlabel(r'$\mu$m/h'.format())
ax.set_xticklabels(["lfy", "wt"])
plt.savefig("comb_regions/zone{i}_strip.png".format(i=lb), dpi=300)
plt.show()
def region_gratios_t39(tss, linss):
r1_t39 = s.region1_t39(linss)
r2_t39 = s.region2_t39(linss)
r3_t39 = s.region3_t39(linss)
r4_t39 = s.region4_t39(linss)
r5_t39 = s.region5_t39(linss)
cids_t39 = set.union(r1_t39,
r2_t39,
r3_t39,
r4_t39,
r5_t39)
tss[39].L1_cells = cids_t39
tss[39] = tss[39].filterL1()
zone1 = (r1_t39, r5_t39)
zone3 = (set.union(r1_t39, r2_t39), set.union(r3_t39, r4_t39))
grsss = grates.grates_avg_cons(tss, linss)
grss = grsss[39]
for i, sep in enumerate([zone1, zone3]):
p1, p2 = sep
plot_distrs_strip(grss, p1, p2, "{i}_t{t}".format(i=str(i+1), t=39))
gr = gratio_ts(grss, p1, p2)
print(i+1, gr)
d = dict()
for c in tss[39]:
if c.cid in p1:
d[c.cid] = 1.0
elif c.cid in p2:
d[c.cid] = 0.0
else:
d[c.cid] = 0.5
plot_ts_q_(tss[39], d, lb="zone{i}_t39_templ".format(i=i+1),
bounds=(0.1, 0.9))
def region_gratios_t47(tss, linss):
r1_t47 = s.region_1
r2_t47 = s.region_2
r3_t47 = s.region_3
r4_t47 = s.region_4
r5_t47 = s.region_5
cids_t47 = set.union(r1_t47,
r2_t47,
r3_t47,
r4_t47,
r5_t47)
tss[47].L1_cells = cids_t47
tss[47] = tss[47].filterL1()
zone1 = (r1_t47, r5_t47)
zone2 = (set.union(r1_t47, r2_t47),
set.union(r3_t47, r4_t47, r5_t47))
zone3 = (set.union(r1_t47, r2_t47), set.union(r3_t47, r4_t47))
grss = grates.grates_backward(tss, linss, 39, 47)
for i, sep in enumerate([zone1, zone2, zone3]):
p1, p2 = sep
plot_distrs_strip(grss, p1, p2, "{i}_t{t}".format(i=str(i+1), t=47))
gr = gratio_ts(grss, p1, p2)
print(i+1, gr)
d = dict()
for c in tss[47]:
if c.cid in p1:
d[c.cid] = 1.0
elif c.cid in p2:
d[c.cid] = 0.0
else:
d[c.cid] = 0.5
plot_ts_q_(tss[47], d, lb="zone{i}_t47_templ".format(i=i+1),
bounds=(0.1, 0.9))
def boundary_gratios():
tss, linss = lin.mkSeriesGeomIm("/Users/s1437009/Downloads/")
r1_t47 = s.region_1
r2_t47 = s.region_2
r3_t47 = s.region_3
r4_t47 = s.region_4
r5_t47 = s.region_5
cids_t47 = set.union(r1_t47,
r2_t47,
r3_t47,
r4_t47,
r5_t47)
tss[47].L1_cells = cids_t47
tss[47] = tss[47].filterL1()
r1 = set.union(r1_t47, r2_t47)
r2 = set.union(r3_t47, r4_t47)
grss = grates.grates_backward(tss, linss, 39, 47)
plot_distrs_strip(grss, r1, r2, "boundary")
d = dict()
for c in tss[47]:
if c.cid in r1:
d[c.cid] = 1.0
elif c.cid in r2:
d[c.cid] = 0.0
else:
d[c.cid] = 0.5
plot_ts_q_(tss[47], d, lb="zone{i}_t47_templ".format(i="boundaries"),
bounds=(0.1, 0.9))
def filterL1_lfy(tss, linss):
r1_t39 = s.region1_t39(linss)
r2_t39 = s.region2_t39(linss)
r3_t39 = s.region3_t39(linss)
r4_t39 = s.region4_t39(linss)
r5_t39 = s.region5_t39(linss)
cids_t39 = set.union(r1_t39,
r2_t39,
r3_t39,
r4_t39,
r5_t39)
tss[39].L1_cells = cids_t39
tss[39] = tss[39].filterL1()
r1_t47 = s.region_1
r2_t47 = s.region_2
r3_t47 = s.region_3
r4_t47 = s.region_4
r5_t47 = s.region_5
cids_t47 = set.union(r1_t47,
r2_t47,
r3_t47,
r4_t47,
r5_t47)
tss[47].L1_cells = cids_t47
tss[47] = tss[47].filterL1()
def do_gratios_lfy_wt(tss, linss, tss_, linss_):
r1_t39 = s.region1_t39(linss)
r2_t39 = s.region2_t39(linss)
r3_t39 = s.region3_t39(linss)
r4_t39 = s.region4_t39(linss)
r5_t39 = s.region5_t39(linss)
zone1 = (r1_t39, r5_t39)
zone3 = (set.union(r1_t39, r2_t39), set.union(r3_t39, r4_t39))
zone1_ = gc.GPairRegions(120, tss_[120], 'ETTIN', 'LFY').get_regions()
zone3_ = gc.GPairRegions(120, tss_[120], 'AP1', 'LFY').get_regions()
grss = grateslf.grates_avg_cons(tss, linss)
grss_ = grates.grates_avg_cons(tss_, linss_)
for i, (z, z_) in enumerate([(zone1, zone1_), (zone3, zone3_)]):
print(i)
r1, r2 = z
r1_, r2_ = z_
plot_distrs_strip_(grss[39], grss_[120], r1, r2, r1_, r2_,
"s3-comp-{i}".format(i=i))
def do_comp(tss, linss, tss_, linss_):
r1_t39 = s.region1_t39(linss)
r2_t39 = s.region2_t39(linss)
r3_t39 = s.region3_t39(linss)
r4_t39 = s.region4_t39(linss)
r5_t39 = s.region5_t39(linss)
r1_t47 = s.region_1
r2_t47 = s.region_2
r3_t47 = s.region_3
r4_t47 = s.region_4
r5_t47 = s.region_5
zones_s3 = [((r1_t39, r5_t39),
gc.GPairRegions(120, tss_[120], 'ETTIN', 'LFY').get_regions()),
((set.union(r1_t39, r2_t39), set.union(r3_t39, r4_t39)),
gc.GPairRegions(120, tss_[120], 'AP1', 'LFY').get_regions())]
zones_s4 = [((r1_t47, r5_t47),
gc.GPairRegions(132, tss_[132], 'ETTIN', 'LFY').get_regions()),
((set.union(r1_t47, r2_t47), set.union(r3_t47, r4_t47)),
gc.GPairRegions(132, tss_[132], 'AP1', 'LFY').get_regions()),
((set.union(r1_t47, r2_t47), set.union(r3_t47, r4_t47, r5_t47)),
gc.GPairRegions(132, tss_[132], 'SEP1', 'LFY').get_regions())]
annots = ["z1-s3",
"z2-s3",
"z1-s4",
"z2-s4",
"z3-s4"]
grss = grateslf.grates_avg_cons(tss, linss)
grss_ = grates.grates_avg_cons(tss_, linss_)
lfy = list()
wt = list()
for z, z_ in zones_s3:
r1, r2 = z
lfy.append(gratio_ts(grss[39], r1, r2))
r1_, r2_ = z_
wt.append(gratio_ts(grss_[120], r1_, r2_))
for z, z_ in zones_s4:
r1, r2 = z
lfy.append(gratio_ts(grss[47], r1, r2))
r1_, r2_ = z_
wt.append(gratio_ts(grss_[132], r1_, r2_))
plt.rcParams.update({'font.size': 8})
fig = plt.figure(figsize=(2.7, 2.7))
ax = plt.subplot2grid((1, 1), (0, 0))
sns.scatterplot(wt, lfy, ax=ax, s=80, alpha=1.0)
ax.set_xlabel("wt")
ax.set_ylabel("lfy")
sns.lineplot(x=[-0.1, 1.1], y=[-0.1, 1.1], ax=ax, linewidth=0.5)
ax.lines[0].set_linestyle("--")
for annot, x, y in zip(annots, wt, lfy):
ax.annotate(annot, (x, y))
plt.show()
import common.lin as lin
region_1 = set([1544, 1041, 2066, 1561, 687, 1058, 1059, 2089, 2094, 1091, 584, 1098, 1463, 2126, 603, 1628, 2142, 611, 1129, 1140, 630, 2175, 646, 1676, 676, 2220, 1711, 689, 2232, 1725, 2238, 1218, 2243, 1220, 712, 1226, 2255, 2257, 1234, 1237, 743, 758, 763, 2347, 2313, 779, 1805, 2325, 2332, 2333, 803, 811, 2353, 2354, 822, 823, 829, 1854, 1345, 2370, 836, 1351, 2383, 1363, 2399, 1888, 869, 2406, 872, 2409, 1388, 2416, 1342, 886, 1914, 2431, 896, 1409, 1416, 2443, 908, 1936, 2366, 2453, 2455, 921, 931, 1447, 1971, 2487, 1070, 955, 2493, 2494, 2495, 1986, 966, 971, 2000, 1501, 2025, 2032, 1529])
region_2 = set([1025, 2050, 918, 1793, 2314, 907, 1036, 1282, 2446, 1069, 2221, 1970, 2371, 1686, 1689, 2074, 2203, 1309, 2334, 2463, 1954, 1122, 1320, 1577, 973, 1837, 1101, 2095, 1969, 1229, 1391, 1972, 1455, 2358, 1335, 2233, 2143, 2364, 2365, 2113, 1475, 965, 1094, 780, 1740, 717, 781, 2128, 1492, 981, 1750, 2127, 1164, 1629, 863, 1869, 2256, 1890, 2275, 2021, 1382, 2279, 2410, 1832, 742, 879, 1197, 2162, 852, 1876, 1786, 1662, 1125])
region_3 = set([1410, 1796, 2054, 1419, 1368, 1938, 1302, 1305, 1828, 1461, 2164, 1215, 1217, 1219, 2122, 1877, 1880, 1759, 2144, 2022, 1255, 2026, 1139, 1396, 1142, 2169, 1471, 1514])
region_4 = set([2432, 1540, 1801, 1039, 1680, 1048, 1554, 2196, 1688, 922, 1821, 2215, 2348, 690, 1589, 1601, 1093, 1482, 975, 1748, 854, 2264, 1630, 1383, 2287, 1652, 1531])
region_5 = set([1408, 1922, 1283, 1924, 1797, 1798, 1582, 1167, 1496, 1426, 1555, 2008, 1326, 1434, 1947, 1923, 1565, 1925, 1696, 1442, 2075, 1189, 2087, 1449, 1834, 1581, 1838, 1839, 1845, 1334, 1592, 1722, 1213, 1483, 2116, 1771, 1864, 1995, 1357, 1946, 2027, 1616, 1617, 1751, 1624, 1625, 1498, 1499, 2013, 1829, 1760, 1378, 1252, 1254, 2023, 1386, 2155, 1647, 1141, 1654, 1892, 1532, 1789, 1790, 1663])
def region1_t39(linss):
d = lin.invertMap(linss[(39, 47)])
return set([d[cid] for cid in region_1])
def region2_t39(linss):
d = lin.invertMap(linss[(39, 47)])
return set([d[cid] for cid in region_2])
def region3_t39(linss):
d = lin.invertMap(linss[(39, 47)])
return set([d[cid] for cid in region_3])
def region4_t39(linss):
d = lin.invertMap(linss[(39, 47)])
return set([d[cid] for cid in region_4])
def region5_t39(linss):
d = lin.invertMap(linss[(39, 47)])
return set([d[cid] for cid in region_5])
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