Skip to content
Snippets Groups Projects
Commit b72ef8fc authored by encinass1u's avatar encinass1u
Browse files

First push

parent f9af4278
Branches master
No related tags found
1 merge request!1Master
Showing
with 502 additions and 86 deletions
File deleted
File deleted
File deleted
File deleted
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 25 11:00:48 2022
#Code following the trace where the cell has been and saving the files in different formats.
@author: encinass1u
"""
import numpy as np
import pickle
......@@ -17,7 +13,6 @@ from bio2mslib.inout.inout import WriteData as WD
import os
import pandas as pd
from bio2mslib.analysis.models import CellModels as DM
import create_graph as cg
from pandas import DataFrame
#Open te pickle file
......@@ -26,7 +21,7 @@ with open('Cell_migration_3'+'.pkl', 'rb') as csv_file:
im = plt.imshow(Z, cmap="copper_r")
iter= 1 #initial iteration
itermax = 10 #last iteration
itermax = 3SSS #last iteration
L = 12 #longitud of the cell sample
while iter<= itermax:
......@@ -41,22 +36,14 @@ while iter<= itermax:
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
#Saving the file of pickle
with open('Cell_migration_'+str(iter)+'_II.pkl', 'wb') as csv_file:
with open('Cell_migration_'+str(iter)+'_II.pkl', 'wb') as pkl_file:
pickle.dump(Z,pkl_file)
with open('Cell_migration_'+str(iter)+'_II.xlsx', 'wb') as excel_file:
pickle.dump(Z,excel_file)
with open('Cell_migration_'+str(iter)+'_II.cvs', 'wb') as csv_file:
pickle.dump(Z,csv_file)
iter +=1
#Definition of saved objects path to use them and create a GIF
if os.path.isdir(results_path) == False :
os.mkdir(results_path)
if os.path.isdir(path_simulation_gif) == False :
os.mkdir(path_simulation_gif)
WD().create_gif_from_images(files_path=results_path+os.sep+"Migration_22",results_path=path_simulation_gif,filename='Cell_Migration_Trace.gif', time_lapse= time_lapse, deleteOriginFiles=0)
graph_name= 'Cell_Trace'
data = pd.read_pkl(results_path+os.sep+"Cell_migration_'+str(iter)+'_II.pkl")
#creation of a gif and a final image of the cells count
cg.createGraph(data, graph_title='Movement')
cg.createGIFGraph(data, path_simulation_gif, 1, graph_name)
......
#PRoliferation o a single cell in the Jeong et al. Equation based on the ammount of nutrient
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
import copy
from matplotlib import pyplot as plt
import random
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
from bio2mslib.analysis.models import CellModels as DM
import os
from config import *
#Seth path for file saving
ls_images=[]
results_path = os.getcwd()+os.sep+"Single_cell"
path_simulation_gif= results_path
path_simulation = results_path+os.sep+"prolif"
if os.path.isdir(path_simulation) == False :
os.mkdir(path_simulation)
#Empty matrix size declaration
lengthx = 12
lengthy = 12
G= np.zeros((lengthx,lengthy))
ST = copy.deepcopy(G)
#Pickle of the obtained matrix
with open('Cell_grid.pkl', 'wb') as csv_file:
pickle.dump(ST,csv_file)
Z = copy.deepcopy(ST)
#insertion of a single cell to track its movement based on the simpspn model
uni_cell = Z[(5,4)]
Z[(5,4)] = 1
iter = 1
itermax = 5
Cd = 1*10**-5 #Cell density
C = 100 #nutrient concentration
Cdmax = 1 #maximum cell density
M = 0.001 #Cell motility coefficient
Lambda = 1 #rate of cell growth
LambdaC =10**-8 #Consumption rate of nutrients
D = 2*10**-5 #Diffusion coefficient
dt = 1 #time step
P = copy.deepcopy(Z)
L = 12
time_lapse=0.5
#Start loop to prolifere
while iter<= itermax:
#Using function of la place to make the initial cell proliferate
LaplaTot=ndimage.laplace(Z)
# im2 = plt.imshow(LaplaTot, cmap="copper_r")
# plt.show()
for i in range(1,L-1):
for j in range(1,L-1):
Z[i,j] = P[i,j] + dt*M*LaplaTot[i,j]*(1-(P[i,j]/Cdmax))+Lambda*1*P[i,j]*(1-(P[i,j]/Cdmax))
if Z[i,j]>0:
Z[i,j]=0.1
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
iter +=1
#Naming the results files
name = 'Single_cell_prolif'+str(iter)+'.png'
plt.imsave(os.path.join(path_simulation, name), Z, cmap="copper_r")
filename = name
ls_images.append(filename)
WD().create_gif_from_images(files_path=results_path+os.sep+"prolif",results_path=path_simulation_gif,filename='Proliferation_single_cell.gif', time_lapse= time_lapse, deleteOriginFiles=0)
#Model from jeong et al. used to perfome the proliferation model added with the migration.
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
from bio2mslib.inout.inout import WriteData as WD
from bio2mslib.analysis.models import CellModels as DM
import os
import pandas as pd
from pandas import DataFrame
import copy
from matplotlib import pyplot as plt
import random
from config import *
import pickle
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
ls_images=[]
results_path=os.getcwd()+os.sep+"Single_cell"
path_simulation_gif = os.getcwd()+os.sep+"Single_cell"
path_simulation = results_path+os.sep+"prolif_migr_"
if os.path.isdir(path_simulation) == False :
os.mkdir(path_simulation)
with open('Cell_grid.pkl', 'rb') as csv_file:
data_saved = pickle.load(csv_file)
print(data_saved)
Z = copy.deepcopy(data_saved)
#Reopening choosen surface
with open('G_surface_empty.pkl', 'rb') as csv_file:
Gst = pickle.load(csv_file)
im2 = plt.imshow(Z, cmap="copper_r")
# #Visual preentation in image of the matrix
im1 = plt.imshow(Gst, cmap="copper_r")
plt.show()
Gbis = copy.deepcopy(Gst)
#insertion of a single cell to track its movement based on the simpspn model
uni_cell = Z[(5,4)]
Z[(5,4)] = 1
iter = 1
itermax = 5
Cd = 1*10**-5 #Cell density
C = 100 #nutrient concentration
Cdmax = 1 #maximum cell density
M = 0.001 #Cell motility coefficient
Lambda = 1 #rate of cell growth
LambdaC =10**-8 #Consumption rate of nutrients
D = 2*10**-5 #Diffusion coefficient
dt = 1 #time step
P = copy.deepcopy(Z)
uni_cell = Gbis[(5,4)]
Gbis[(5,5)] = 1
L = 12
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
Cn = 1*10**-5 #Cell density
NO2 = 10**2 #nutrient concentration
Cnmax = 10**7 #maximum cell density
Dm = 0.001 #Cell motility coefficient
CRgrw = 1 #rate of cell growth
CRNO2 =10**-8 #Consumption rate of nutrients
DNO2 = 2*10**-5
dt = 1 #time step
iter = 1
#Start loop to prolifere
while iter<= itermax:
while iter <= 5:
#Using function of la place to make the initial cell proliferate
LaplaTot=ndimage.laplace(Z)
LaplaTot=ndimage.laplace(Gbis)
for i in range(1,L-1):
for j in range(1,L-1):
h = random.randint(-1,1) #horizontal value for the movement of the cell
v = random.randint(-1,1) #vertival value for the movement of the cell
if Z[i,j]==1 and (h != 0 or v!= 0) and i<L and j<L:
Z[h + i, v + j]= 1
x = random.randint(-1,1) #horizontal value for the movement of the cell
y = random.randint(-1,1) #vertival value for the movement of the cell
if Gbis[i,j]==1 and (x != 0 or y!= 0) and i<L and j<L:
Gbis[x + i, y + j]= 1
#Proliferation after migration
Z[i,j] = P[i,j] + dt*M*LaplaTot[i,j]*(1-(P[i,j]/Cdmax))+Lambda*1*P[i,j]*(1-(P[i,j]/Cdmax))
if Z[i,j]>0:
Z[i,j]=1
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
iter = iter+1
Gbis[i,j] = P[i,j] + dt*M*LaplaTot[i,j]*(1-(P[i,j]/Cnmax))+CRgrw*1*P[i,j]*(1-(P[i,j]/Cnmax))
if Gbis[i,j]>0:
Gbis[i,j]=1
im2 = plt.imshow(Gbis, cmap="copper_r")
plt.show()
iter +=1
name = 'Single_cell_migr_prolif'+str(iter)+'.png'
plt.imsave(os.path.join(path_simulation, name), Z, cmap="copper_r")
filename = name
ls_images.append(filename)
with open('Cell_g.pkl', 'wb') as csv_file:
pickle.dump(ST,csv_file)
WD().create_gif_from_images(files_path=results_path+os.sep+"prolif_migr",results_path=path_simulation_gif,filename='Proliferation_migration_single_cell.gif', time_lapse= time_lapse, deleteOriginFiles=0)
#GIF creation using same libraries
import numpy as np
from bio2mslib.inout.inout import WriteData as WD
from bio2mslib.analysis.models import CellModels as DM
import os
import pandas as pd
from pandas import DataFrame
import copy
from matplotlib import pyplot as plt
import random
from config import *
ls_images=[]
results_path = os.getcwd()+os.sep+"Migration_Single_cell"
path_simulation_gif=results_path
path_simulation = results_path+os.sep+"Migration_Single_cell"
if os.path.isdir(path_simulation) == False :
os.mkdir(path_simulation)
#Empty matrix size declaration
lengthx = 12
lengthy = 12
G= np.zeros((lengthx,lengthy))
ST = copy.deepcopy(G)
#Loop to add the \ surface
for i in range (0,12):
for j in range (0,12):
if (i == j):
ST[i,j]=0.5
Z = copy.deepcopy(ST)
uni_cell = Z[(5,4)]
Z[(5,4)] = 1
iter = 1
itermax = 3
time_lapse = 0.5
while iter<= itermax:
for i in range(0,12):
for j in range(0,12):
# if Zcopy[im,jm]>= 1:
# Zcopyinitial = copy.deepcopy(Zcopy[im,jm])
h = random.randint(-1,1) #horizontal value for the movement of the cell
v = random.randint(-1,1) #vertival value for the movement of the cell
if Z[i,j]==1 and (h != 0 or v!= 0):
Z[i,j]= 0.7
Z[h + i, v + j]= 1
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
name = 'Migration_'+str(iter)+'.png'
plt.imsave(os.path.join(path_simulation, name), Z, cmap="copper_r")
filename = name
ls_images.append(filename)
iter +=1
WD().create_gif_from_images(files_path=results_path+os.sep+"Migration_Single_cell",results_path=path_simulation_gif,filename='Migration_GIF_single_cell.gif', time_lapse= time_lapse, deleteOriginFiles=0)
\ No newline at end of file
#GIF creation using same libraries
import numpy as np
from bio2mslib.inout.inout import WriteData as WD
from bio2mslib.analysis.models import CellModels as DM
import os
import pandas as pd
from pandas import DataFrame
import copy
from matplotlib import pyplot as plt
import random
from config import *
ls_images=[]
results_path = os.getcwd()+os.sep+"GIF_result"
path_simulation_gif= os.getcwd()+os.sep+"GIF_result"
path_simulation = results_path+os.sep+"Images_for_GIF"
if os.path.isdir(path_simulation) == False :
os.mkdir(path_simulation)
#Empty matrix size declaration
lengthx = 12
lengthy = 12
G= np.zeros((lengthx,lengthy))
ST = copy.deepcopy(G)
#Loop to add the \ surface
for i in range (0,12):
for j in range (0,12):
if (i == j):
ST[i,j]=0.5
Z = copy.deepcopy(ST)
uni_cell = Z[(5,4)]
Z[(5,4)] = 1
iter = 1
itermax = 3
time_lapse = 0.5
while iter<= itermax:
for i in range(0,12):
for j in range(0,12):
# if Zcopy[im,jm]>= 1:
# Zcopyinitial = copy.deepcopy(Zcopy[im,jm])
h = random.randint(-1,1) #horizontal value for the movement of the cell
v = random.randint(-1,1) #vertival value for the movement of the cell
if Z[i,j]==1 and (h != 0 or v!= 0):
Z[i,j]= 0.7
Z[h + i, v + j]= 1
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
name = 'Migration_'+str(iter)+'.png'
plt.imsave(os.path.join(path_simulation, name), Z, cmap="copper_r")
filename = name
ls_images.append(filename)
iter +=1
WD().create_gif_from_images(files_path=results_path+os.sep+"Images_for_GIF",results_path=path_simulation_gif,filename='Migration_GIF_single_cell.gif', time_lapse= time_lapse, deleteOriginFiles=0)
\ No newline at end of file
File added
#Gst generator,it is possible to choose a type of texture for the cell couture.
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
import copy
from matplotlib import pyplot as plt
import random
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
#Selection of desire treated surface, Gts
First_Pickle= True
square_grid=False
highs_grid=False
diagonal=True
if First_Pickle== True:
#L is the matrix dimension
L =12
Lx =np.linspace(0, L, 12)
Ly =np.linspace(0, L, 12)
#G is the ground, an empty matrix to add the desire surface
G= np.zeros((L,L))
#Gts us the ground for treated surface
Gts = copy.deepcopy(G)
if square_grid==True:
# #Square grid
for i in range (1,len(Lx)-1):
for j in range(1,len(Ly)-1):
if ((i % 2) !=0) or ((j % 2) ==0):
Gts[i,j] = 0.5
elif highs_grid==True:
for i in range (1,len(Lx)-1):
for j in range(1,len(Ly)-1):
if i==0 or j==0 or i==len(Lx)-1 or j==len(Ly)-1:
Gst[i,j] = 0.5
elif i==1 or j==1 or i==len(Lx)-2 or j==len(Ly)-2:
Gts[i,j] = 0.7
elif diagonal==True:
for i in range (1,len(Lx)-1):
for j in range (1,len(Ly)-1):
if (i == j):
Gts[i,j]=0.5
else:
with open('G_surface_empty.pkl', 'rb') as csv_file:
Gts = pickle.load(csv_file)
with open('G_surface_empty.pkl', 'wb') as csv_file:
pickle.dump(Gts,csv_file)
im = plt.imshow(Gts, cmap="copper_r")
plt.show()
#PRoliferation o a single cell in the Jeong et al. Equation based on the ammount of nutrient
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
import copy
from matplotlib import pyplot as plt
import random
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
#Empty matrix size declaration
lengthx = 12
lengthy = 12
G= np.zeros((lengthx,lengthy))
Gbis = copy.deepcopy(G)
for i in range (4,lengthx-4):
for j in range (4,lengthy-4):
G[i,j]==1
im2 = plt.imshow(G, cmap="copper_r")
plt.show()
#insertion of a single cell to track its movement based on the simpspn model
# iter = 1
# itermax = 5
# Cn = 1*10**-5 #Cell density
# NO2 = 100 #nutrient concentration
# Cnmax = 1 #maximum cell density
# Dm = 0.001 #Cell motility coefficient
# Ncgrw = 1 #rate of cell growth
# CRNO2 =10**-8 #Consumption rate of nutrients
# Dn = 2*10**-5 #Diffusion coefficient
# dt = 1 #time step
# P = copy.deepcopy(Gbis)
# L = 12
# im2 = plt.imshow(Gbis, cmap="copper_r")
# plt.show()
# #Start loop to prolifere
# while iter<= itermax:
# #Using function of la place to make the initial cell proliferate
# LaplaTot=ndimage.laplace(Gbis)
# # im2 = plt.imshow(LaplaTot, cmap="copper_r")
# # plt.show()
# for i in range(1,L-1):
# for j in range(1,L-1):
# Gbis[i,j] = P[i,j] + dt*Dm*LaplaTot[i,j]*(1-(P[i,j]/Cnmax))+Ncgrw*1*P[i,j]*(1-(P[i,j]/Cnmax))
# if Gbis[i,j]>0:
# Gbis[i,j]=0.1
# im2 = plt.imshow(Gbis, cmap="copper_r")
# plt.show()
# iter = iter+1
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
import copy
from matplotlib import pyplot as plt
import random
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
from Gts_selection import L, Lx, Ly
from bio2mslib.analysis.models import CellModels as DM
from matplotlib.pyplot import figure
#Declaring saving paths for results
ls_images=[]
results_path = os.getcwd()+os.sep+"Single_cell"
path_simulation_gif =os.getcwd()+os.sep+"Single_cell"
path_simulation = results_path+os.sep+"prolif_migr"
if os.path.isdir(path_simulation) == False :
os.mkdir(path_simulation)
#Reopening choosen surface
with open('G_surface_empty.pkl', 'rb') as csv_file:
Gts = pickle.load(csv_file)
# #Visual preentation in image of the matrix
# im1 = plt.imshow(Gts, cmap="copper_r")
# plt.show()
#Gs is ground seeded, a copy of the choosen surface to seed the cells,
Gs = copy.deepcopy(Gts)
#Milticelular seeding
for i in range (4,L-6):
for j in range (4,L-7):
if Gs[i,j]==0.5:
Gs[i,j]=1.5
else:
Gs[i,j]=1
#images of the cell in the surface
couture= plt.imshow(Gs, cmap="copper_r")
plt.show()
#Variable deffinition for PDE proliferation & migration model
Cd = 1*10**-5 #Cell density
NO2 = 10**2 #nutrient concentration
Cdmax = 10**7 #maximum cell density
Dm = 0.001 #Cell motility coefficient
CRgrw = 1 #rate of cell growth
CRNO2 =10**-8 #Consumption rate of nutrients
DNO2 = 2*10**-5
dt = 1 #time step
time_lapse = 0.1
Gscopy = copy.deepcopy(Gs)
Laplace = ndimage.laplace(Gs)
#Migration
iter = 0
while iter<= 15:
for mi in range(1, len(Lx)-1):
for mj in range(1, len(Ly)-1):
x = random.randint(-1,1)#horizontal value for the movement of the cell
y = random.randint(-1,1)#vertival value for the movement of the cell
if Gs[mi,mj]==1 and (x != 0 or y!= 0) and ((mi+x)<len(Lx)) and ((mj+y)< len(Ly)):
Gs[mi+x,mj+y]= 1
Gs[mi,mj]=0
#Proliferation after migration
Gs[mi,mj] = Gscopy[mi,mj] + dt*Dm*Laplace[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax))+CRgrw*1*Gscopy[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax))
if Gs[mi,mj]>0 and Gs[mi,mj]!=0.7 and Gs[mi,mj]!=0.5 :
Gs[mi,mj]=1
im2 = plt.imshow(Gs, cmap="copper_r", norm = None, aspect ='equal', vmin=0 ,vmax=12)
plt.show()
name = 'Single_cell_migr_prolif'+str(iter)+'.png'
# plt.imsave(os.path.join(path_simulation, name), Gs, cmap="copper_r")
filename = name
ls_images.append(im2)
iter+=1
WD().create_gif_from_images(files_path=results_path+os.sep+"prolif_migr",results_path=path_simulation_gif,filename='Cell_behavior.gif', time_lapse= time_lapse, deleteOriginFiles=0)
\ No newline at end of file
......@@ -33,8 +33,8 @@ for i in range (0,12):
#Pickle of the obtained matrix
with open('Cell_grid.pkl', 'wb') as csv_file:
pickle.dump(ST,csv_file)
Laplace = ndimage.laplace(Z)
P = copy.deepcopy(Z)
Laplace = ndimage.laplace(ST)
P = copy.deepcopy(ST)
iter= 1 #initial iteration
itermax = 5 #last iteration
L = 12 #longitud of the cell sample
......@@ -48,13 +48,13 @@ D = 2*10**-5
dt = 1 #time step
while iter<= itermax:
LaplaTot=ndimage.laplace(Z)
LaplaTot=ndimage.laplace(ST)
for i in range(0,L):
for j in range(0,L):
h = random.randint(-1,1) #horizontal value for the movement of the cell
v = random.randint(-1,1) #vertival value for the movement of the cell
if Z[i,j]==1 and (h != 0 or v!= 0) and i<L and j<L:
Z[i,j] = P[i,j] + dt*M*Laplace[i,j]*(1-(P[i,j]/Cdmax))+Lambda*1*P[i,j]*(1-(P[i,j]/Cdmax))
ST[i,j] = P[i,j] + dt*M*Laplace[i,j]*(1-(P[i,j]/Cdmax))+Lambda*1*P[i,j]*(1-(P[i,j]/Cdmax))
im2 = plt.imshow(Z, cmap="copper_r")
plt.show()
......
;
\ No newline at end of file
File added
File added
#Gst generator,it is possible to choose a type of texture for the cell couture.
import numpy as np
import pickle
import random
import matplotlib.pyplot as ptl
import copy
from matplotlib import pyplot as plt
import random
from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
import pyvista as pv
#Selection of desire treated surface, Gts
First_Pickle= True
square_grid=False
highs_grid=True
diagonal=False
#
with open('Surface_SMAT.vtk', 'rb') as vtk_file:
tata = pickle.load(vtk_file)
surface = pv.read(tata)
tata.plot()
......@@ -9,6 +9,15 @@ from scipy import ndimage
from bio2mslib.inout.inout import WriteData as WD
import os
First_Pickle= False
if First_Pickle== True:
with open('Cell_grid.pkl', 'wb') as csv_file:
pickle.dump(ST,csv_file)
else:
with open('Cell_grid.pkl', 'rb') as csv_file:
data_saved = pickle.load(csv_file)
#Empty matrix size declaration
lengthx = 12
lengthy = 12
......@@ -84,24 +93,3 @@ while iter<= 5:
plt.show()
iter+=1
# elif h==0 and v != 0 and Zcopy[im,jm-v]==0:
# Zcopy[im,jm]=0
# Zcopy[im,jm-v]=Zcopyinitial
# elif v==0 and h != 0 and Zcopy[im+l,jm]==0:
# Zcopy[im,jm]=0
# Zcopy[im+h,jm]=Zcopyinitial
#Proliferation process for the cells, regarding that we only have cells in the
# for i in range (4,lengthx-4):
# for j in range (4,lengthy-4):
# if Z[i,j]<=1:
# for i in range (4,lengthx-4):
# for j in range (4,lengthy-4):
# Z[i,j] = Zcopy[i,j] + M*Laplace[i,j]*(1-Zcopy[i,j]/Cdmax) + Lambda*Zcopy[i,j]*(1-Zcopy[i,j]/Cdmax)
# im2 = plt.imshow(Z, cmap="copper_r")
# plt.show()
#WD().create_gif_from_images(files_path=results_path+os.sep+"cell_results_var",results_path=path_simulation_gif,filename='Nbr_cells_graph_nutri_variable_migration.gif', time_lapse= time_lapse, deleteOriginFiles=0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment