def hybrid_tech_c(coef, set, sol): #2.2 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching sol['tip_cell'] = [] for nom in range(0, n_sp): #dicek setiap element xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position dirr = movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 ok '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement''' sol, tipp = movement(sol, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4) #2.2.(2) '''Checking if X4 is absorbed''' if not tipp == 'stay': sol, abs = absorbed_f(sol, set, nom) else: abs = 'no' if abs == 'no': sol['tip_cell'].append(sol['matrix_tip'][nom][-1]) return sol
def hybrid_tech(coef, set, sol, c_o): #2.23 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) sol['backward_list'] = [] #backward list for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position dirr, probb = movement_dir(coef, set, sol, xb, yb, c_o) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' sol['n'][xb,yb] = 0 sol['stalk'][xb,yb] = 1 else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement And Tip-Tip Anastomosis Checking''' branch = False sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) return sol
def hybrid_tech(coef, set, sol, c_o): #2.23 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy( sol['n'] ) #to save the value of 'n' at time step k (we are calculating at time step k+1) sol['backward_list'] = [] #backward list for nom in range(0, n_sp): #dicek setiap tip if not nom in sol[ 'sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position dirr, probb = movement_dir( coef, set, sol, xb, yb, c_o) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[ 4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' sol['n'][xb, yb] = 0 sol['stalk'][xb, yb] = 1 else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement And Tip-Tip Anastomosis Checking''' branch = False sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, set, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4, branch) #2.2.(2) return sol
def hybrid_tech_c(coef, set, sol): #2.2 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching sol['tip_cell'] = [] for nom in range(0,n_sp): #dicek setiap element xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position dirr= movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 ok '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement''' sol,tipp = movement(sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(2) '''Checking if X4 is absorbed''' if not tipp == 'stay': sol, abs = absorbed_f(sol,set,nom) else: abs = 'no' if abs == 'no': sol['tip_cell'].append(sol['matrix_tip'][nom][-1]) return sol
def hybrid_tech_c(coef, set, sol): #2.2 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) sol['loc_anas_tt'] = [] sol['loc_anas_tb'] = [] for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position '''Proliferation if sol['life_mit'][nom] >= coef['T_mitosis']: sol['life_mit'][nom] = 0 if sol['list_tip_movement'] == 'left': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] - 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'right': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] + 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'down': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] -2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'up': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] + 2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) Proliferation''' dirr= movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 ok '''Checking The movement if another tip meet nom''' movi = False if [xb,yb] in sol['PP']: movi = True if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 ''' With No backward movement if sol['list_tip_movement'][nom] == 'left': dirr[2] == 0 if sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['list_tip_movement'][nom] == 'right': dirr[1] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['list_tip_movement'][nom] == 'down': dirr[4] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 elif sol['list_tip_movement'][nom] == 'up': dirr[3] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 ''' if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #if no space sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb,yb]) else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement''' sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(2) '''2.1 Branching Decision''' PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA1' if movi == True: sol['PP'].remove([xb,yb]) sol['pp'].pop((xb,yb)) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA2' #print sol['life_time_tip'][nom] if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA3' '''Probability of Branching using life time''' list_prob = range(1,11)#prob_by_c(sol,xb,yb) #2.2.(4) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #BRANCHING! #print 'YAYAYA4' sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb,yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' '''The Movement from branching''' while tipp == 'stay': sol, tipp = movement_branch(tipp,sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(5) return sol, n_o
def system_2d(coef, set, sol, n_o): #2.3 c_o = numpy.copy(sol['c']) #to save values at time step k (we are calculating at time step k+1) f_o = numpy.copy(sol['f']) #to save values at time step k (we are calculating at time step k+1) '''Calculate Velocity from tip cell's Vel''' sol['Vel_x'] = numpy.zeros((set['Nx']+1,set['Ny']+1)) sol['Vel_y'] = numpy.zeros((set['Nx']+1,set['Ny']+1)) for y in range(1,set['Ny'],2): for x in range(1,set['Nx'],2): if n_o[x,y] == 1: dirr, probb = movement_dir(coef, set, sol, x, y) sol['Vel_x'][x,y] = -probb[1]+probb[2] sol['Vel_y'][x,y] = -probb[3]+probb[4] '''Solve c & f at sub lattice''' for y in range(0,set['Ny']+1,2): for x in range(0,set['Nx']+1,2): c_star = sol['c_o'][x,y] - c_o[x,y] gam_f = sol['c_o'][x,y]*c_star/((1/(coef['Gama']))+c_star) move_c = 0 move_f = 0 if y == 0: if x == 0: mean_n = n_o[x+1,y+1]/4 elif x == set['Nx']: mean_n = n_o[x-1,y+1]/4 else: mean_n = (n_o[x-1,y+1] + n_o[x+1,y+1])/4 move_c = 0#coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y])-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(0)-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) elif y == set['Ny']: if x == 0: mean_n = n_o[x+1,y-1]/4 elif x == set['Nx']: mean_n = n_o[x-1,y-1]/4 else: mean_n = (n_o[x-1,y-1] + n_o[x+1,y-1])/4 move_c = 0#coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y]coef['Gama'])-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(0))/(set['h']**2) else: if x == 0: mean_n = (n_o[x+1,y-1] + n_o[x+1,y+1])/2 move_c = 0#coef['Alp_c']*set['dt']*(vijx_p*(0)-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) elif x == set['Nx']: mean_n = (n_o[x-1,y-1] + n_o[x-1,y+1])/4 move_c = 0#coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y])-vijx_n*(0)+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) else: mean_n = (n_o[x+1,y+1] + n_o[x-1,y+1] + n_o[x+1,y-1] + n_o[x-1,y-1])/4 vel_x_mean = (sol['Vel_x'][x+1,y+1] + sol['Vel_x'][x-1,y+1] + sol['Vel_x'][x+1,y-1] + sol['Vel_x'][x-1,y-1])/4 vel_y_mean = (sol['Vel_y'][x+1,y+1] + sol['Vel_y'][x-1,y+1] + sol['Vel_y'][x+1,y-1] + sol['Vel_y'][x-1,y-1])/4 vijx_p = max(0,vel_x_mean) vijx_n = max(0,-vel_x_mean) vijy_p = max(0,vel_y_mean) vijy_n = max(0,-vel_y_mean) # if vel_x_mean != 0 or vel_y_mean != 0: # print vel_x_mean, vel_y_mean #Method: not from P1,P2,P3,... # vijx_p, vijx_n, vijy_p, vijy_n = velocity_max(coef,set,sol,n_o,c_o,f_o,x,y) move_c = coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y])-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']) move_f = coef['Alp_f']*set['dt']*(vijx_p*(f_o[x,y]-f_o[x-2,y])-vijx_n*(f_o[x+2,y]-f_o[x,y])+vijy_p*(f_o[x,y]-f_o[x,y-2])-vijy_n*(f_o[x,y+2]-f_o[x,y]))/(set['h']) digestion_c = set['dt']*coef['Nu']*c_o[x,y]*mean_n digestion_f = set['dt']*gam_f*f_o[x,y]*mean_n #coef['Gama'] prolifer_f = set['dt']*coef['Beta']*mean_n sol['c'][x,y] = c_o[x,y] - digestion_c - move_c sol['f'][x,y] = f_o[x,y] + prolifer_f - digestion_f - move_f # if move_c != 0 or move_f != 0: # print move_c, move_f, digestion_c, digestion_f if sol['c'][x,y] != sol['c_o'][x, set['Ny']]: sol['c_n'][x,y] = sol['c'][x,y] return sol
def hybrid_tech(coef, set, sol): #2.23 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) sol['tip_cell'] = [] tipp = [] for nom, nom_isi in enumerate(sol['matrix_tip']): #dicek setiap tip if isinstance(nom_isi[-1], int) == False: #cek kalau sproutnya masih hidup # if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position df = '0' '''Recording backward movement start''' if len(sol['matrix_tip'][nom]) >=2: xbm1 = sol['matrix_tip'][nom][-2][0] #get x position of 2nd last tip position (to avoid backward movement) ybm1 = sol['matrix_tip'][nom][-2][1] #get y position of 2nd last tip position (to avoid backward movement) tx1 = xb-xbm1 ty1 = yb-ybm1 if tx1 == 0: if ty1 < 0: df = '4' else: df = '3' else: if tx1 < 0: df = '2' else: df = '1' #kalau terus backward nanti dia bikin cabang baru. '''Recording backward movement start''' dirr, probb = movement_dir(coef, set, sol, xb, yb, df) #2.2.1 => go to direction_of_movement.py # if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move # if not nom in sol['sp_stop']: # sol['sp_stop'].append(nom) # sol['cause'][nom] = 'no space' # # if [xb,yb] in sol['tip_cell']: # # sol['tip_cell'].remove([xb,yb]) # sol['n'][xb,yb] = 0 # sol['stalk'][xb,yb] = 1 # sol['matrix_tip'][nom][-1].append(10000) #10000 kode utk no space # else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement''' branch = False sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) # '''Check Anastomosis before branching decision''' # sol= anas_after(sol, tipp, n_sp, branchingg = False) # '''Branching decision start''' # for ind_i, i in enumerate(sol['matrix_tip']): # if isinstance(i[-1], int) == False: #sprout yang masih hidup # xbb = i[-1][0] - 1 # ybb = i[-1][1] - 1 # if sol['c_t'][xbb,ybb] > 0: #C_t nya positive # if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # list_prob = prob_by_c(sol,xb,yb) #Probability of Branching using c #range(1,11) #2.2.(4) # tes = randint(1,10) # if not tes in list_prob: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #BRANCHING! # sol['life_time_tip'][nom] = 0 # sol['matrix_tip'].append([[xb,yb]]) # sol['life_time_tip'].append(0) # sol['new_ves_pair'].append([ind_i,len(sol['matrix_tip'])-1]) # '''The Movement from branching''' # nom = len(sol['matrix_tip'])-1 # xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position # yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position # # # dirr, probb = movement_dir(coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py # # # if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move # # if not nom in sol['sp_stop']: # # sol['sp_stop'].append(nom) # # sol['cause'][nom] = 'no space' # # # if [xb,yb] in sol['tip_cell']: # # # sol['tip_cell'].remove([xb,yb]) # # sol['n'][xb,yb] = 0 # # sol['stalk'][xb,yb] = 1 # # sol['matrix_tip'][nom][-1].append(1000) #1000 kode utk no space # # else: # # '''Making list of prob''' # # list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) # # '''The Movement''' # branch = True # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) # # # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(5) # '''Branching decision end''' # '''Check Anastomosis after branching decision''' # sol= anas_after(sol, tipp, n_sp, new_ves, branchingg = True) '''TIP CELL''' for ind_i, i in enumerate(sol['matrix_tip']): if len(i) > 1: if isinstance(i[-1], int) == False: #sprout yang masih hidup sol['tip_cell'].append(i[-1]) else: sol['tip_cell'].append(i[-1]) # if len(sol['backward_list']) > 0: # sol['backward_count'].append(set['k']) return sol
def hybrid_tech_c(coef, set, sol): ##branching decision and action. Also movement line = range(1, 11) #for Pb n_sp = len( sol['matrix_tip']) #to save original number of tips before branching for nom in range(0, n_sp): #dicek setiap tip if not nom in sol[ 'sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. line_1 = range(1, 10001) xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position #print 'xb,yb', xb,',',yb dirr, space = movement_dir(coef, set, sol, xb, yb, nom, n_dir=True) if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: sol['sp_stop'].append(nom) else: if dirr[1] == 0: list_prob_1 = [] else: list_prob_1 = random.sample(line_1, dirr[1]) for i in list_prob_1: line_1.remove(i) if dirr[2] == 0: list_prob_2 = [] else: list_prob_2 = random.sample(line_1, dirr[2]) for i in list_prob_2: line_1.remove(i) if dirr[3] == 0: list_prob_3 = [] else: list_prob_3 = random.sample(line_1, dirr[3]) for i in list_prob_3: line_1.remove(i) if dirr[4] == 0: list_prob_4 = [] else: list_prob_4 = random.sample(line_1, dirr[4]) for i in list_prob_4: line_1.remove(i) list_prob_0 = line_1 #print 'corret:', len(list_prob_0), len(list_prob_1), len(list_prob_2), len(list_prob_3), len(list_prob_4) tes = randint( 1, 10000 ) #select integer number randomly between 1 and 100000 if tes in list_prob_0: tipp = 'stay' elif tes in list_prob_1: tipp = 'left' xpos_new = sol['matrix_tip'][nom][-1][0] - 2 ypos_new = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][nom] = tipp for i in list_prob_1: list_prob_0.append(i) list_prob_1 = [] elif tes in list_prob_2: tipp = 'right' xpos_new = sol['matrix_tip'][nom][-1][0] + 2 ypos_new = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][nom] = tipp for i in list_prob_2: list_prob_0.append(i) list_prob_2 = [] elif tes in list_prob_3: tipp = 'down' xpos_new = sol['matrix_tip'][nom][-1][0] ypos_new = sol['matrix_tip'][nom][-1][1] - 2 sol['matrix_tip'][nom].append((xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][nom] = tipp for i in list_prob_3: list_prob_0.append(i) list_prob_3 = [] elif tes in list_prob_4: tipp = 'up' xpos_new = sol['matrix_tip'][nom][-1][0] ypos_new = sol['matrix_tip'][nom][-1][1] + 2 sol['matrix_tip'][nom].append((xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][nom] = tipp for i in list_prob_4: list_prob_0.append(i) list_prob_4 = [] '''Checking if new position hits any existing vessel''' if not tipp == 'stay': if tipp == 'left' and space[0] == 'stop': sol['sp_stop'].append(nom) elif tipp == 'right' and space[1] == 'stop': sol['sp_stop'].append(nom) elif tipp == 'down' and space[2] == 'stop': sol['sp_stop'].append(nom) elif tipp == 'up' and space[3] == 'stop': sol['sp_stop'].append(nom) '''Checking m space and calculating number of EC''' if not coef['Mic'] == 0 or not coef['Kappa'] == 0: if not tipp == 'stay' and set['t'] > set['tm']: #calculate number of EC #sol['number_ec'] += 1 #Kalau di posisi n baru ada m, m nya dibuang if sol['m'][xpos_new, ypos_new] == 1: sol['m'][xpos_new, ypos_new] == 0 #sol['cell_m'].remove([xpos_new,ypos_new]) '''2.1 Branching Decision''' if tipp == 'stay': sol['life_time_tip'][nom] += sol['tp'] else: if dirr.count(0) >= 3: sol['life_time_tip'][nom] += sol['tp'] else: if sol['life_time_tip'][nom] < coef['T_branch']: sol['life_time_tip'][nom] += sol['tp'] else: #being able to branch by life time #probabilty of branching # print 'NILAI C', c[xb+1,yb+1] if sol['c'][xb + 1, yb + 1] >= 0 and sol['c'][xb + 1, yb + 1] < 0.1: prob_weight = 7 # set the number to select here. list_prob = random.sample( line, prob_weight ) #list of selected numbers from line elif sol['c'][xb + 1, yb + 1] >= 0.1 and sol['c'][xb + 1, yb + 1] < 0.2: prob_weight = 8 # set the number to select here. list_prob = random.sample(line, prob_weight) elif sol['c'][xb + 1, yb + 1] >= 0.2 and sol['c'][xb + 1, yb + 1] < 0.3: prob_weight = 9 # set the number to select here. list_prob = random.sample(line, prob_weight) elif sol['c'][xb + 1, yb + 1] >= 0.3: #do branching list_prob = line #apakah branching? meaning masuk dalam probability of branching? tes = randint( 1, 10 ) #select integer number randomly between 1 and 10 #print 'check 3' if not tes in list_prob: sol['life_time_tip'][nom] += sol['tp'] else: #do branching '''2.1 Branhcing''' sol['life_time_tip'][nom] = 0 sol['matrix_tip'].append([(xb, yb)]) sol['life_time_tip'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' while tipp == 'stay': tes = randint( 1, 10000 ) #select integer number randomly between 1 and 100000 if tes in list_prob_0: tipp = 'stay' elif tes in list_prob_1: tipp = 'left' xpos_new = sol['matrix_tip'][-1][-1][ 0] - 2 ypos_new = sol['matrix_tip'][-1][-1][1] sol['matrix_tip'][-1].append( (xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][-1] = tipp elif tes in list_prob_2: tipp = 'right' xpos_new = sol['matrix_tip'][-1][-1][ 0] + 2 ypos_new = sol['matrix_tip'][-1][-1][1] sol['matrix_tip'][-1].append( (xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][-1] = tipp elif tes in list_prob_3: tipp = 'down' xpos_new = sol['matrix_tip'][-1][-1][0] ypos_new = sol['matrix_tip'][-1][-1][ 1] - 2 sol['matrix_tip'][-1].append( (xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][-1] = tipp elif tes in list_prob_4: tipp = 'up' xpos_new = sol['matrix_tip'][-1][-1][0] ypos_new = sol['matrix_tip'][-1][-1][ 1] + 2 sol['matrix_tip'][-1].append( (xpos_new, ypos_new)) sol['n'][xpos_new, ypos_new] = 1 sol['list_tip_movement'][-1] = tipp '''Checking if new position hits any existing vessel''' if tipp == 'left' and space[0] == 'stop': sol['sp_stop'].append( len(sol['matrix_tip']) - 1) elif tipp == 'right' and space[1] == 'stop': sol['sp_stop'].append( len(sol['matrix_tip']) - 1) elif tipp == 'down' and space[2] == 'stop': sol['sp_stop'].append( len(sol['matrix_tip']) - 1) elif tipp == 'up' and space[3] == 'stop': sol['sp_stop'].append( len(sol['matrix_tip']) - 1) '''Checking m space and calculating number of EC''' if not coef['Mic'] == 0 or not coef[ 'Kappa'] == 0: #calculate number of EC #sol['number_ec'] += 1 #Kalau di posisi n baru ada m, m nya dibuang if set['t'] > set['tm']: if sol['m'][xpos_new, ypos_new] == 1: sol['m'][xpos_new, ypos_new] == 0 # sol['cell_m'].remove([xpos_new,ypos_new]) return sol
def hybrid_tech(coef, set, sol): #2.23 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy( sol['n'] ) #to save the value of 'n' at time step k (we are calculating at time step k+1) sol['tip_cell'] = [] tipp = [] #running movement for all active sprouts for nom, nom_isi in enumerate(sol['matrix_tip']): #dicek setiap tip if isinstance(nom_isi[-1], int) == False: #cek kalau sproutnya masih hidup # if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position dirr, probb = movement_dir( coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[ 4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' # if [xb,yb] in sol['tip_cell']: # sol['tip_cell'].remove([xb,yb]) sol['n'][xb, yb] = 0 sol['stalk'][xb, yb] = 1 sol['matrix_tip'][nom][-1].append( 10000) #10000 kode utk no space else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement''' branch = False sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, set, tipp, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4, branch) #2.2.(2) '''Check Anastomosis before branching decision''' sol = anas_after(sol, tipp, n_sp, branchingg=False) # '''Branching decision''' # for ind_i, i in enumerate(sol['matrix_tip']): # if isinstance(i[-1], int) == False: #sprout yang masih hidup # if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # # Probability of Branching using c # list_prob = prob_by_c(sol,xb,yb) #range(1,11) #2.2.(4) # tes = randint(1,10) # if not tes in list_prob: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #BRANCHING! # # print 'Branchingg' # sol['life_time_tip'][nom] = 0 # sol['matrix_tip'].append([[xb,yb]]) # sol['life_time_tip'].append(0) # '''The Movement from branching''' # nom = len(sol['matrix_tip'])-1 # xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position # yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position # # dirr, probb = movement_dir(coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py # # if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move # if not nom in sol['sp_stop']: # sol['sp_stop'].append(nom) # sol['cause'][nom] = 'no space' # # if [xb,yb] in sol['tip_cell']: # # sol['tip_cell'].remove([xb,yb]) # sol['n'][xb,yb] = 0 # sol['stalk'][xb,yb] = 1 # sol['matrix_tip'][nom][-1].append(1000) #1000 kode utk no space # else: # '''Making list of prob''' # list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) # # '''The Movement''' # branch = False # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) # # # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(5) # # '''Check Anastomosis after branching decision''' # sol= anas_after(sol, tipp, n_sp, branchingg = False) '''TIP CELL''' for ind_i, i in enumerate(sol['matrix_tip']): if len(i) > 1: if isinstance(i[-1], int) == False: #sprout yang masih hidup sol['tip_cell'].append(i[-1]) else: sol['tip_cell'].append(i[-1]) # '''2.1 Branching Decision''' # PP = 'test' # if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # if dirr.count(0) >= 3: #no space to move # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # # Probability of Branching using c # list_prob = prob_by_c(sol,xb,yb) #range(1,11) #2.2.(4) # tes = randint(1,10) # if not tes in list_prob: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #BRANCHING! # # print 'Branchingg' # sol['life_time_tip'][nom] = 0 # sol['matrix_tip'].append([[xb,yb]]) # sol['life_time_tip'].append(0) # '''The Movement from branching''' # branch = True # nom = len(sol['matrix_tip'])-1 # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(5) if len(sol['backward_list']) > 0: sol['backward_count'].append(set['k']) # print 'nom', nom # '''Create tip cell area''' # for tip in sol['tip_cell']: # sol['tip_cell_area'].append([tip[0]-2,tip[1]]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]]) # sol['tip_cell_area'].append([tip[0],tip[1]-2]) # sol['tip_cell_area'].append([tip[0],tip[1]+2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]-2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]-2]) # sol['tip_cell_area'] = [] # for i in sol['tip_cell']: # sol['tip_cell_area'].append([i[0]+1, i[1]+1]) # sol['tip_cell_area'].append([i[0]+1, i[1]-1]) # sol['tip_cell_area'].append([i[0]-1, i[1]+1]) # sol['tip_cell_area'].append([i[0]-1, i[1]-1]) # '''Record New Tip Cell''' # sol['tip_cell'] = [] # for nom in range(0,len(sol['matrix_tip'])): #dicek setiap tip # if not nom in sol['sp_stop']: #record only active sprout # sol['tip_cell'].append([sol['matrix_tip'][nom][-1][0],sol['matrix_tip'][nom][-1][1]]) # count_anas = len(i[1]) # prob_weight = 3 # line = range(1,count_anas*prob_weight+1) # for ind_jj, j in enumerate(i[1]): # globals()['%s' % ind_jj] = random.sample(line, prob_weight) # for k in globals()['%s' % ind_jj]: # line.remove(k) # tess = randint(1,count_anas*prob_weight+1) # kk = 0 # for ind_jj, j in enumerate(i[1]): # if tess in return sol
def hybrid_tech_m(coef, set, sol): mo = sol['m'][:] nom = 0 sol['index_mn'] = [] sol['cell_m'] = [] look = 0 for y in range(1,set['Ny'],2): for x in range(1,set['Nx'],2): if sol['m'][x,y] == 1: sol['cell_m'].append([x,y]) print 'Banyaknya cell m',len(sol['cell_m']) # print 'Banyaknya m yang 1',numpy.count_nonzero(sol['m']) '''Identify The fartest tip from center''' ''' distance = [] for tip in sol['tip_cell']: r_f = numpy.sqrt((tip[0]*set['Hh']-set['O_x'])**2 + (tip[1]*set['Hh']-set['O_y'])**2) distance.append(r_f) far = max(distance) + 0.4 ''' far = 100 for e, cell in enumerate(sol['cell_m']): xb = cell[0] yb = cell[1] if set['layout'] == 'retina': r_f = numpy.sqrt((xb*set['Hh']-set['O_x'])**2 + (yb*set['Hh']-set['O_y'])**2) if r_f <= far: look = 1 else: look = 1 if look == 1: line_1 = range(1,10001) dirr, space = movement_dir(coef, set, sol, xb, yb, nom, n_dir = False) if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: lop = 1 else: if dirr[1] == 0: list_prob_1 = [] else: list_prob_1 = random.sample(line_1, dirr[1]) for i in list_prob_1: line_1.remove(i) if dirr[2] == 0: list_prob_2 = [] else: list_prob_2 = random.sample(line_1, dirr[2]) for i in list_prob_2: line_1.remove(i) if dirr[3] == 0: list_prob_3 = [] else: list_prob_3 = random.sample(line_1, dirr[3]) for i in list_prob_3: line_1.remove(i) if dirr[4] == 0: list_prob_4 = [] else: list_prob_4 = random.sample(line_1, dirr[4]) for i in list_prob_4: line_1.remove(i) list_prob_0 = line_1 #print 'selesai bikin line' nx = xb ny = yb tes = randint(1,10000) #select integer number randomly between 1 and 100000 if tes in list_prob_1: if [xb - 2, yb] not in sol['tip_cell']: nx = xb - 2 ny = yb sol['m'][xb - 2, yb] = 1 sol['m'][xb,yb] = 0 elif tes in list_prob_2: if [xb + 2, yb] not in sol['tip_cell']: nx = xb + 2 ny = yb sol['m'][xb + 2, yb] = 1 sol['m'][xb,yb] = 0 elif tes in list_prob_3: if [xb, yb - 2] not in sol['tip_cell']: nx = xb ny = yb - 2 sol['m'][xb, yb - 2] = 1 sol['m'][xb,yb] = 0 elif tes in list_prob_4: if [xb, yb + 2] not in sol['tip_cell']: nx = xb ny = yb + 2 sol['m'][xb, yb + 2] = 1 sol['m'][xb,yb] = 0 #if sol['n'][nx,ny] == 1: # if [xb,yb] in sol['index_mn']: # sol['index_mn'].remove([xb,yb]) # sol['index_mn'].append([nx,ny]) #for ec_i in range(0,len(sol['matrix_tip'])): # if (nx,ny) in sol['matrix_tip'][ec_i]: # sol['index_mn'].append([nx,ny]) for y in range(1,set['Ny'],2): for x in range(1,set['Nx'],2): if sol['m'][x,y] == 1 and sol['n'][x,y] == 1: sol['index_mn'].append([x,y]) # print 'Banyaknya MC yang di EC', len(sol['index_mn']) return sol
def hybrid_tech(coef, set, sol): #Ref.4.1 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) # sol['vn_o'] = [] #to record tip cell position # sol['bw'] = 0 #to detect backward list sol['backward_list'] = [] #backward list for nom in range(0,n_sp): #we check every tip cell if not nom in sol['sp_stop']: #if the anastomosis happen, we don't need to check its movement or branching decision. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position dirr, probb = movement_dir(coef, set, sol, xb, yb) #Ref.4.1.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) sol['n'][xb,yb] = 0 sol['stalk'][xb,yb] = 1 else: '''Making list of probability for selecting the direction''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #Ref.4.1.2 '''The Movement And Tip-Tip Anastomosis Checking''' branch = False sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #Ref.4.1.3 '''2.1 Branching Decision''' PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch # Probability of Branching using c list_prob = prob_by_c(sol,xb,yb) #range(1,11) ##Ref.4.1.4 tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #BRANCHING! sol['life_time_tip'][nom] = 0 sol['matrix_tip'].append([[xb,yb]]) sol['life_time_tip'].append(0) '''The Movement from branching''' branch = True nom = len(sol['matrix_tip'])-1 sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #Ref.4.1.3 # if len(sol['backward_list']) > 0: #to record which iteration that the backward movement occurs # sol['backward_count'].append(set['k']) # '''Create tip cell area''' # for tip in sol['tip_cell']: # sol['tip_cell_area'].append([tip[0]-2,tip[1]]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]]) # sol['tip_cell_area'].append([tip[0],tip[1]-2]) # sol['tip_cell_area'].append([tip[0],tip[1]+2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]-2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]-2]) '''Create tip cell area for solving c dan f continuously''' sol['tip_cell_area'] = [] for i in sol['tip_cell']: sol['tip_cell_area'].append([i[0]+1, i[1]+1]) sol['tip_cell_area'].append([i[0]+1, i[1]-1]) sol['tip_cell_area'].append([i[0]-1, i[1]+1]) sol['tip_cell_area'].append([i[0]-1, i[1]-1]) # '''Record New Tip Cell''' # sol['tip_cell'] = [] # for nom in range(0,len(sol['matrix_tip'])): #dicek setiap tip # if not nom in sol['sp_stop']: #record only active sprout # sol['tip_cell'].append([sol['matrix_tip'][nom][-1][0],sol['matrix_tip'][nom][-1][1]]) return sol
def hybrid_tech_c(coef, set, sol): n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position # '''Proliferation''' # if sol['life_mit'][nom] >= coef['T_mitosis']: # sol['life_mit'][nom] = 0 # if sol['list_tip_movement'] == 'left': # if [xb,yb] in sol['tip_cell']: # sol['tip_cell'].remove([xb,yb]) # xs = sol['matrix_tip'][nom][-1][0] - 2 # ys = sol['matrix_tip'][nom][-1][1] # sol['matrix_tip'][nom].append((xs,ys)) # sol['n'][xs,ys] = 1 # sol['tip_cell'].append([xs,ys]) # elif sol['list_tip_movement'] == 'right': # if [xb,yb] in sol['tip_cell']: # sol['tip_cell'].remove([xb,yb]) # xs = sol['matrix_tip'][nom][-1][0] + 2 # ys = sol['matrix_tip'][nom][-1][1] # sol['matrix_tip'][nom].append((xs,ys)) # sol['n'][xs,ys] = 1 # sol['tip_cell'].append([xs,ys]) # elif sol['list_tip_movement'] == 'down': # if [xb,yb] in sol['tip_cell']: # sol['tip_cell'].remove([xb,yb]) # xs = sol['matrix_tip'][nom][-1][0] # ys = sol['matrix_tip'][nom][-1][1] -2 # sol['matrix_tip'][nom].append((xs,ys)) # sol['n'][xs,ys] = 1 # sol['tip_cell'].append([xs,ys]) # elif sol['list_tip_movement'] == 'up': # if [xb,yb] in sol['tip_cell']: # sol['tip_cell'].remove([xb,yb]) # xs = sol['matrix_tip'][nom][-1][0] # ys = sol['matrix_tip'][nom][-1][1] + 2 # sol['matrix_tip'][nom].append((xs,ys)) # sol['n'][xs,ys] = 1 # sol['tip_cell'].append([xs,ys]) # '''Proliferation''' dirr= movement_dir(coef, set, sol, xb, yb, nom) if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb,yb]) else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) '''Checking Space for n #if meet vessel''' ml = 'f' mr = 'f' md = 'f' mu = 'f' tip_l = -1 tip_r = -1 tip_d = -1 tip_u = -1 ''' ml, mr, md, mu, tip_l, tip_r, tip_d, tip_u = anastomosis_tip_branch(sol,nom,xb,yb,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) sol['pp'] ={} ml = 'f' mr = 'f' md = 'f' mu = 'f' tip_l = -1 tip_r = -1 tip_d = -1 tip_u = -1 ''' '''The Movement''' sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) '''Test Anastomosis tip-tip if move''' if not tipp == 'stay': sol=anastomosis_tip_tip(sol,nom) '''2.1 Branching Decision''' if tipp == 'stay': #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch cek = str(nom) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #there is possibility to branch if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #there is possibility to branch '''Probability of Branching using c''' list_prob = prob_by_c(sol,xb,yb) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #BRANCHING! sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb,yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' if cek in sol['pp']: sol['pp'].pop('cek') '''The Movement from branching''' while tipp == 'stay': sol, tipp = movement_branch(tipp,sol,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) '''Check Anastomosis''' if not tipp == 'stay': sol=anastomosis_tip_tip(sol,len(sol['matrix_tip'])-1) return sol, n_o
def hybrid_tech(coef, set, sol): #2.23 # print 'all sol', type(sol)#["stop_iter"] n_sp = len( sol['matrix_tip']) #to save original number of tips before branching # n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) # sol['vn_o'] = [] #to record tip cell position # sol['bw'] = 0 #to detect backward list sol['backward_list'] = [] #backward list for nom in range(0, n_sp): #dicek setiap tip if not nom in sol[ 'sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position dirr, probb = movement_dir( coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[ 4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' if [xb, yb] in sol['tip_cell']: sol['tip_cell'].remove([xb, yb]) sol['n'][xb, yb] = 0 sol['stalk'][xb, yb] = 1 else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement And Tip-Tip Anastomosis Checking''' branch = False sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, set, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4, branch) #2.2.(2) '''2.1 Branching Decision''' PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if sol['life_time_tip'][nom] < coef[ 'T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch # Probability of Branching using c list_prob = prob_by_c(sol, xb, yb) #range(1,11) #2.2.(4) tes = randint(1, 10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #BRANCHING! sol['life_time_tip'][nom] = 0 sol['matrix_tip'].append([[xb, yb]]) sol['life_time_tip'].append(0) '''The Movement from branching''' branch = True nom = len(sol['matrix_tip']) - 1 sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, set, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4, branch) #2.2.(5) if len(sol['backward_list']) > 0: sol['backward_count'].append(set['k']) # '''Create tip cell area''' # for tip in sol['tip_cell']: # sol['tip_cell_area'].append([tip[0]-2,tip[1]]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]]) # sol['tip_cell_area'].append([tip[0],tip[1]-2]) # sol['tip_cell_area'].append([tip[0],tip[1]+2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]-2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]-2]) '''Record New Tip Cell''' # sol['tip_cell'] = [] # for nom in range(0,len(sol['matrix_tip'])): #dicek setiap tip # if not nom in sol['sp_stop']: #record only active sprout # sol['tip_cell'].append([sol['matrix_tip'][nom][-1][0],sol['matrix_tip'][nom][-1][1]]) return sol
def system_2d(coef, set, sol, n_o): #2.3 c_o = numpy.copy( sol['c'] ) #to save values at time step k (we are calculating at time step k+1) f_o = numpy.copy( sol['f'] ) #to save values at time step k (we are calculating at time step k+1) '''Calculate Velocity from tip cell's Vel''' sol['Vel_x'] = numpy.zeros((set['Nx'] + 1, set['Ny'] + 1)) sol['Vel_y'] = numpy.zeros((set['Nx'] + 1, set['Ny'] + 1)) for y in range(1, set['Ny'], 2): for x in range(1, set['Nx'], 2): if n_o[x, y] == 1: dirr, probb = movement_dir(coef, set, sol, x, y) sol['Vel_x'][x, y] = -probb[1] + probb[2] sol['Vel_y'][x, y] = -probb[3] + probb[4] '''Solve c & f at sub lattice''' for y in range(0, set['Ny'] + 1, 2): for x in range(0, set['Nx'] + 1, 2): c_star = sol['c_o'][x, y] - c_o[x, y] gam_f = sol['c_o'][x, y] * c_star / ((1 / (coef['Gama'])) + c_star) move_c = 0 move_f = 0 if y == 0: if x == 0: mean_n = n_o[x + 1, y + 1] / 4 elif x == set['Nx']: mean_n = n_o[x - 1, y + 1] / 4 else: mean_n = (n_o[x - 1, y + 1] + n_o[x + 1, y + 1]) / 4 move_c = 0 #coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y])-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(0)-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) elif y == set['Ny']: if x == 0: mean_n = n_o[x + 1, y - 1] / 4 elif x == set['Nx']: mean_n = n_o[x - 1, y - 1] / 4 else: mean_n = (n_o[x - 1, y - 1] + n_o[x + 1, y - 1]) / 4 move_c = 0 #coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y]coef['Gama'])-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(0))/(set['h']**2) else: if x == 0: mean_n = (n_o[x + 1, y - 1] + n_o[x + 1, y + 1]) / 2 move_c = 0 #coef['Alp_c']*set['dt']*(vijx_p*(0)-vijx_n*(c_o[x+2,y]-c_o[x,y])+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) elif x == set['Nx']: mean_n = (n_o[x - 1, y - 1] + n_o[x - 1, y + 1]) / 4 move_c = 0 #coef['Alp_c']*set['dt']*(vijx_p*(c_o[x,y]-c_o[x-2,y])-vijx_n*(0)+vijy_p*(c_o[x,y]-c_o[x,y-2])-vijy_n*(c_o[x,y+2]-c_o[x,y]))/(set['h']**2) else: mean_n = (n_o[x + 1, y + 1] + n_o[x - 1, y + 1] + n_o[x + 1, y - 1] + n_o[x - 1, y - 1]) / 4 vel_x_mean = (sol['Vel_x'][x + 1, y + 1] + sol['Vel_x'][x - 1, y + 1] + sol['Vel_x'][x + 1, y - 1] + sol['Vel_x'][x - 1, y - 1]) / 4 vel_y_mean = (sol['Vel_y'][x + 1, y + 1] + sol['Vel_y'][x - 1, y + 1] + sol['Vel_y'][x + 1, y - 1] + sol['Vel_y'][x - 1, y - 1]) / 4 vijx_p = max(0, vel_x_mean) vijx_n = max(0, -vel_x_mean) vijy_p = max(0, vel_y_mean) vijy_n = max(0, -vel_y_mean) # if vel_x_mean != 0 or vel_y_mean != 0: # print vel_x_mean, vel_y_mean #Method: not from P1,P2,P3,... # vijx_p, vijx_n, vijy_p, vijy_n = velocity_max(coef,set,sol,n_o,c_o,f_o,x,y) move_c = coef['Alp_c'] * set['dt'] * ( vijx_p * (c_o[x, y] - c_o[x - 2, y]) - vijx_n * (c_o[x + 2, y] - c_o[x, y]) + vijy_p * (c_o[x, y] - c_o[x, y - 2]) - vijy_n * (c_o[x, y + 2] - c_o[x, y])) / (set['h']) move_f = coef['Alp_f'] * set['dt'] * ( vijx_p * (f_o[x, y] - f_o[x - 2, y]) - vijx_n * (f_o[x + 2, y] - f_o[x, y]) + vijy_p * (f_o[x, y] - f_o[x, y - 2]) - vijy_n * (f_o[x, y + 2] - f_o[x, y])) / (set['h']) digestion_c = set['dt'] * coef['Nu'] * c_o[x, y] * mean_n digestion_f = set['dt'] * gam_f * f_o[x, y] * mean_n #coef['Gama'] prolifer_f = set['dt'] * coef['Beta'] * mean_n sol['c'][x, y] = c_o[x, y] - digestion_c - move_c sol['f'][x, y] = f_o[x, y] + prolifer_f - digestion_f - move_f # if move_c != 0 or move_f != 0: # print move_c, move_f, digestion_c, digestion_f if sol['c'][x, y] != sol['c_o'][x, set['Ny']]: sol['c_n'][x, y] = sol['c'][x, y] return sol
def hybrid_tech_m(coef, set, sol): mo = sol['m'][:] nom = 0 sol['index_mn'] = [] sol['cell_m'] = [] look = 0 for y in range(1, set['Ny'], 2): for x in range(1, set['Nx'], 2): if sol['m'][x, y] == 1: sol['cell_m'].append([x, y]) print 'Banyaknya cell m', len(sol['cell_m']) # print 'Banyaknya m yang 1',numpy.count_nonzero(sol['m']) '''Identify The fartest tip from center''' ''' distance = [] for tip in sol['tip_cell']: r_f = numpy.sqrt((tip[0]*set['Hh']-set['O_x'])**2 + (tip[1]*set['Hh']-set['O_y'])**2) distance.append(r_f) far = max(distance) + 0.4 ''' far = 100 for e, cell in enumerate(sol['cell_m']): xb = cell[0] yb = cell[1] if set['layout'] == 'retina': r_f = numpy.sqrt((xb * set['Hh'] - set['O_x'])**2 + (yb * set['Hh'] - set['O_y'])**2) if r_f <= far: look = 1 else: look = 1 if look == 1: line_1 = range(1, 10001) dirr, space = movement_dir(coef, set, sol, xb, yb, nom, n_dir=False) if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: lop = 1 else: if dirr[1] == 0: list_prob_1 = [] else: list_prob_1 = random.sample(line_1, dirr[1]) for i in list_prob_1: line_1.remove(i) if dirr[2] == 0: list_prob_2 = [] else: list_prob_2 = random.sample(line_1, dirr[2]) for i in list_prob_2: line_1.remove(i) if dirr[3] == 0: list_prob_3 = [] else: list_prob_3 = random.sample(line_1, dirr[3]) for i in list_prob_3: line_1.remove(i) if dirr[4] == 0: list_prob_4 = [] else: list_prob_4 = random.sample(line_1, dirr[4]) for i in list_prob_4: line_1.remove(i) list_prob_0 = line_1 #print 'selesai bikin line' nx = xb ny = yb tes = randint( 1, 10000 ) #select integer number randomly between 1 and 100000 if tes in list_prob_1: if [xb - 2, yb] not in sol['tip_cell']: nx = xb - 2 ny = yb sol['m'][xb - 2, yb] = 1 sol['m'][xb, yb] = 0 elif tes in list_prob_2: if [xb + 2, yb] not in sol['tip_cell']: nx = xb + 2 ny = yb sol['m'][xb + 2, yb] = 1 sol['m'][xb, yb] = 0 elif tes in list_prob_3: if [xb, yb - 2] not in sol['tip_cell']: nx = xb ny = yb - 2 sol['m'][xb, yb - 2] = 1 sol['m'][xb, yb] = 0 elif tes in list_prob_4: if [xb, yb + 2] not in sol['tip_cell']: nx = xb ny = yb + 2 sol['m'][xb, yb + 2] = 1 sol['m'][xb, yb] = 0 #if sol['n'][nx,ny] == 1: # if [xb,yb] in sol['index_mn']: # sol['index_mn'].remove([xb,yb]) # sol['index_mn'].append([nx,ny]) #for ec_i in range(0,len(sol['matrix_tip'])): # if (nx,ny) in sol['matrix_tip'][ec_i]: # sol['index_mn'].append([nx,ny]) for y in range(1, set['Ny'], 2): for x in range(1, set['Nx'], 2): if sol['m'][x, y] == 1 and sol['n'][x, y] == 1: sol['index_mn'].append([x, y]) # print 'Banyaknya MC yang di EC', len(sol['index_mn']) return sol
def hybrid_tech(coef, set, sol): #2.23 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy( sol['n'] ) #to save the value of 'n' at time step k (we are calculating at time step k+1) sol['tip_cell'] = [] tipp = [] for nom, nom_isi in enumerate(sol['matrix_tip']): #dicek setiap tip if isinstance(nom_isi[-1], int) == False: #cek kalau sproutnya masih hidup # if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position df = '0' '''Recording backward movement start''' if len(sol['matrix_tip'][nom]) >= 2: xbm1 = sol['matrix_tip'][nom][-2][ 0] #get x position of 2nd last tip position (to avoid backward movement) ybm1 = sol['matrix_tip'][nom][-2][ 1] #get y position of 2nd last tip position (to avoid backward movement) tx1 = xb - xbm1 ty1 = yb - ybm1 if tx1 == 0: if ty1 < 0: df = '4' else: df = '3' else: if tx1 < 0: df = '2' else: df = '1' #kalau terus backward nanti dia bikin cabang baru. '''Recording backward movement start''' dirr, probb = movement_dir( coef, set, sol, xb, yb, df) #2.2.1 => go to direction_of_movement.py # if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move # if not nom in sol['sp_stop']: # sol['sp_stop'].append(nom) # sol['cause'][nom] = 'no space' # # if [xb,yb] in sol['tip_cell']: # # sol['tip_cell'].remove([xb,yb]) # sol['n'][xb,yb] = 0 # sol['stalk'][xb,yb] = 1 # sol['matrix_tip'][nom][-1].append(10000) #10000 kode utk no space # else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement''' branch = False sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, set, tipp, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4, branch) #2.2.(2) # '''Check Anastomosis before branching decision''' # sol= anas_after(sol, tipp, n_sp, branchingg = False) # '''Branching decision start''' # for ind_i, i in enumerate(sol['matrix_tip']): # if isinstance(i[-1], int) == False: #sprout yang masih hidup # xbb = i[-1][0] - 1 # ybb = i[-1][1] - 1 # if sol['c_t'][xbb,ybb] > 0: #C_t nya positive # if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #there is possibility to branch # list_prob = prob_by_c(sol,xb,yb) #Probability of Branching using c #range(1,11) #2.2.(4) # tes = randint(1,10) # if not tes in list_prob: #not able to branch # sol['life_time_tip'][nom] += set['dt'] # else: #BRANCHING! # sol['life_time_tip'][nom] = 0 # sol['matrix_tip'].append([[xb,yb]]) # sol['life_time_tip'].append(0) # sol['new_ves_pair'].append([ind_i,len(sol['matrix_tip'])-1]) # '''The Movement from branching''' # nom = len(sol['matrix_tip'])-1 # xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position # yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position # # # dirr, probb = movement_dir(coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py # # # if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move # # if not nom in sol['sp_stop']: # # sol['sp_stop'].append(nom) # # sol['cause'][nom] = 'no space' # # # if [xb,yb] in sol['tip_cell']: # # # sol['tip_cell'].remove([xb,yb]) # # sol['n'][xb,yb] = 0 # # sol['stalk'][xb,yb] = 1 # # sol['matrix_tip'][nom][-1].append(1000) #1000 kode utk no space # # else: # # '''Making list of prob''' # # list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) # # '''The Movement''' # branch = True # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) # # # sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,tipp,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(5) # '''Branching decision end''' # '''Check Anastomosis after branching decision''' # sol= anas_after(sol, tipp, n_sp, new_ves, branchingg = True) '''TIP CELL''' for ind_i, i in enumerate(sol['matrix_tip']): if len(i) > 1: if isinstance(i[-1], int) == False: #sprout yang masih hidup sol['tip_cell'].append(i[-1]) else: sol['tip_cell'].append(i[-1]) # if len(sol['backward_list']) > 0: # sol['backward_count'].append(set['k']) return sol
def hybrid_tech(coef, set, sol): #2.2 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy( sol['n'] ) #to save the value of 'n' at time step k (we are calculating at time step k+1) vn_o = [] #to record tip cell position for nom in range(0, n_sp): #dicek setiap tip if not nom in sol[ 'sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position vn_o.append([xb, yb]) dirr = movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[ 4] == 0: #checking if there is space for tip cell to move sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb, yb]) sol['n'][xb, yb] = 0 else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement''' sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4) #2.2.(2) '''2.1 Branching Decision PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA1' if movi == True: sol['PP'].remove([xb,yb]) sol['pp'].pop((xb,yb)) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA2' #print sol['life_time_tip'][nom] if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA3' # Probability of Branching using c list_prob = range(1,11)#prob_by_c(sol,xb,yb) #2.2.(4) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #BRANCHING! #print 'YAYAYA4' sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb,yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' # The Movement from branching while tipp == 'stay': sol, tipp = movement_branch(tipp,sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(5) ''' '''Vector Velocity of stalk (Vb) Method 1:all towards tip cell''' #profile 1: \/\ for y in range(1, set['Ny'], 2): for x in range(1, set['Nx'], 2): vb_x = 0 vb_y = 0 for ind, vec in enumerate(vn_o): s = m.sqrt((x - vec[0])**2 + (y - vec[1])**2) if s <= 2: h_s = 0 elif s <= 10: h_s = 0.5 + coef['m1'] * (s - 10) elif s <= 20: h_s = 2 + coef['m2'] * (s - 20) elif s <= 40: h_s = 0 + coef['m3'] * (s - 40) else: h_s = 0 if s != 0: vb_x += (vec[0] - x) * h_s / s #unit vector vb_y += (vec[1] - y) * h_s / s #unit vector sol['Vb_x'][x, y] = vb_x sol['Vb_y'][x, y] = vb_y #profile 2: / for y in range(1, set['Ny'], 2): for x in range(1, set['Nx'], 2): vb_x = 0 vb_y = 0 for ind, vec in enumerate(vn_o): s = m.sqrt((x - vec[0])**2 + (y - vec[1])**2) if s <= 2: h_s = 0 elif s <= 50: h_s = 1 + coef['m1'] * (s - 50) else: h_s = 1 if s != 0: vb_x += (vec[0] - x) * h_s / s #unit vector vb_y += (vec[1] - y) * h_s / s #unit vector sol['Vb_x'][x, y] = vb_x sol['Vb_y'][x, y] = vb_y # print 'Tip cell position:', vn_o # print 'Velocity Vector stalk on [3,201]: [',sol['Vb_x'][3,201],',',sol['Vb_y'][3,201],']' return sol, n_o
def hybrid_tech_c(coef, set, sol): #2.2 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position '''Proliferation''' if sol['life_mit'][nom] >= coef['T_mitosis']: sol['life_mit'][nom] = 0 if sol['list_tip_movement'] == 'left': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] - 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'right': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] + 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'down': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] -2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'up': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] + 2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) '''Proliferation''' dirr= movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb,yb]) else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''Checking Space for n #if meet vessel''' ml = 'f' mr = 'f' md = 'f' mu = 'f' tip_l = -1 tip_r = -1 tip_d = -1 tip_u = -1 ''' ml, mr, md, mu, tip_l, tip_r, tip_d, tip_u = anastomosis_tip_branch(sol,nom,xb,yb,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) sol['pp'] ={} ml = 'f' mr = 'f' md = 'f' mu = 'f' tip_l = -1 tip_r = -1 tip_d = -1 tip_u = -1 ''' '''The Movement''' sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) #2.2.(2) '''Test Anastomosis tip-tip if move''' if not tipp == 'stay': sol=anastomosis_tip_tip(sol,nom) #2.2.(3) '''2.1 Branching Decision''' if tipp == 'stay': #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch cek = str(nom) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #there is possibility to branch if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #there is possibility to branch '''Probability of Branching using c''' list_prob = prob_by_c(sol,xb,yb) #2.2.(4) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] if cek in sol['pp']: sol['pp'].pop('cek') else: #BRANCHING! sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb,yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' if cek in sol['pp']: sol['pp'].pop('cek') '''The Movement from branching''' while tipp == 'stay': sol, tipp = movement_branch(tipp,sol,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4,ml,mr,md,mu,tip_l,tip_r,tip_d,tip_u) #2.2.(5) '''Check Anastomosis''' if not tipp == 'stay': sol=anastomosis_tip_tip(sol,len(sol['matrix_tip'])-1) #2.2.(3) return sol
def hybrid_tech(coef, set, sol): #2.23 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) # sol['vn_o'] = [] #to record tip cell position # sol['bw'] = 0 #to detect backward list sol['backward_list'] = [] #backward list for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position dirr, probb = movement_dir(coef, set, sol, xb, yb) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move if not nom in sol['sp_stop']: sol['sp_stop'].append(nom) sol['cause'][nom] = 'no space' if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) sol['n'][xb,yb] = 0 sol['stalk'][xb,yb] = 1 else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement And Tip-Tip Anastomosis Checking''' branch = False sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(2) '''2.1 Branching Decision''' PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #there is possibility to branch # Probability of Branching using c list_prob = prob_by_c(sol,xb,yb) #range(1,11) #2.2.(4) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] else: #BRANCHING! sol['life_time_tip'][nom] = 0 sol['matrix_tip'].append([[xb,yb]]) sol['life_time_tip'].append(0) '''The Movement from branching''' branch = True nom = len(sol['matrix_tip'])-1 sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,set,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4, branch) #2.2.(5) if len(sol['backward_list']) > 0: sol['backward_count'].append(set['k']) # '''Create tip cell area''' # for tip in sol['tip_cell']: # sol['tip_cell_area'].append([tip[0]-2,tip[1]]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]]) # sol['tip_cell_area'].append([tip[0],tip[1]-2]) # sol['tip_cell_area'].append([tip[0],tip[1]+2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]+2]) # sol['tip_cell_area'].append([tip[0]+2,tip[1]-2]) # sol['tip_cell_area'].append([tip[0]-2,tip[1]-2]) sol['tip_cell_area'] = [] for i in sol['tip_cell']: sol['tip_cell_area'].append([i[0]+1, i[1]+1]) sol['tip_cell_area'].append([i[0]+1, i[1]-1]) sol['tip_cell_area'].append([i[0]-1, i[1]+1]) sol['tip_cell_area'].append([i[0]-1, i[1]-1]) # '''Record New Tip Cell''' # sol['tip_cell'] = [] # for nom in range(0,len(sol['matrix_tip'])): #dicek setiap tip # if not nom in sol['sp_stop']: #record only active sprout # sol['tip_cell'].append([sol['matrix_tip'][nom][-1][0],sol['matrix_tip'][nom][-1][1]]) return sol
def hybrid_tech(coef, set, sol): #2.2 n_sp = len(sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) #to save the value of 'n' at time step k (we are calculating at time step k+1) vn_o = [] #to record tip cell position for nom in range(0,n_sp): #dicek setiap tip if not nom in sol['sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][1] #get y position of last tip position vn_o.append([xb,yb]) dirr= movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 => go to direction_of_movement.py if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[4] == 0: #checking if there is space for tip cell to move sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb,yb]) sol['n'][xb,yb] = 0 else: '''Making list of prob''' list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = set_list_prob(dirr) #2.2.(1) '''The Movement''' sol,tipp,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4 = movement(sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(2) '''2.1 Branching Decision PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA1' if movi == True: sol['PP'].remove([xb,yb]) sol['pp'].pop((xb,yb)) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA2' #print sol['life_time_tip'][nom] if sol['life_time_tip'][nom] < coef['T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA3' # Probability of Branching using c list_prob = range(1,11)#prob_by_c(sol,xb,yb) #2.2.(4) tes = randint(1,10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #BRANCHING! #print 'YAYAYA4' sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb,yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' # The Movement from branching while tipp == 'stay': sol, tipp = movement_branch(tipp,sol,nom,xb,yb,list_prob_0,list_prob_1,list_prob_2,list_prob_3,list_prob_4) #2.2.(5) ''' '''Vector Velocity of stalk (Vb) Method 1:all towards tip cell''' #profile 1: \/\ for y in range(1,set['Ny'],2): for x in range(1,set['Nx'],2): vb_x = 0 vb_y = 0 for ind, vec in enumerate(vn_o): s = m.sqrt((x-vec[0])**2+(y-vec[1])**2) if s <= 2: h_s = 0 elif s <= 10: h_s = 0.5 + coef['m1']*(s-10) elif s <= 20: h_s = 2 + coef['m2']*(s-20) elif s <= 40: h_s = 0 + coef['m3']*(s-40) else: h_s = 0 if s != 0: vb_x += (vec[0]-x)*h_s/s #unit vector vb_y += (vec[1]-y)*h_s/s #unit vector sol['Vb_x'][x,y] = vb_x sol['Vb_y'][x,y] = vb_y #profile 2: / for y in range(1,set['Ny'],2): for x in range(1,set['Nx'],2): vb_x = 0 vb_y = 0 for ind, vec in enumerate(vn_o): s = m.sqrt((x-vec[0])**2+(y-vec[1])**2) if s <= 2: h_s = 0 elif s <= 50: h_s = 1 + coef['m1']*(s-50) else: h_s = 1 if s != 0: vb_x += (vec[0]-x)*h_s/s #unit vector vb_y += (vec[1]-y)*h_s/s #unit vector sol['Vb_x'][x,y] = vb_x sol['Vb_y'][x,y] = vb_y # print 'Tip cell position:', vn_o # print 'Velocity Vector stalk on [3,201]: [',sol['Vb_x'][3,201],',',sol['Vb_y'][3,201],']' return sol, n_o
def hybrid_tech_c(coef, set, sol): #2.2 n_sp = len( sol['matrix_tip']) #to save original number of tips before branching n_o = numpy.copy(sol['n']) sol['loc_anas_tt'] = [] sol['loc_anas_tb'] = [] for nom in range(0, n_sp): #dicek setiap tip if not nom in sol[ 'sp_stop']: #kalo dia sudah anastomosis, gak perlu branching dan move lg. xb = sol['matrix_tip'][nom][-1][ 0] #get x position of last tip position yb = sol['matrix_tip'][nom][-1][ 1] #get y position of last tip position '''Proliferation if sol['life_mit'][nom] >= coef['T_mitosis']: sol['life_mit'][nom] = 0 if sol['list_tip_movement'] == 'left': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] - 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'right': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] + 2 ys = sol['matrix_tip'][nom][-1][1] sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'down': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] -2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) elif sol['list_tip_movement'] == 'up': if [xb,yb] in sol['tip_cell']: sol['tip_cell'].remove([xb,yb]) xs = sol['matrix_tip'][nom][-1][0] ys = sol['matrix_tip'][nom][-1][1] + 2 sol['matrix_tip'][nom].append((xs,ys)) sol['n'][xs,ys] = 1 sol['tip_cell'].append([xs,ys]) Proliferation''' dirr = movement_dir(coef, set, sol, xb, yb, nom) #2.2.1 ok '''Checking The movement if another tip meet nom''' movi = False if [xb, yb] in sol['PP']: movi = True if sol['pp'][(xb, yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb, yb)] == 'right': dirr[1] == 0 elif sol['pp'][(xb, yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb, yb)] == 'down': dirr[4] == 0 ''' With No backward movement if sol['list_tip_movement'][nom] == 'left': dirr[2] == 0 if sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['list_tip_movement'][nom] == 'right': dirr[1] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['list_tip_movement'][nom] == 'down': dirr[4] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'up': dirr[3] == 0 elif sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 elif sol['list_tip_movement'][nom] == 'up': dirr[3] == 0 if sol['pp'][(xb,yb)] == 'left': dirr[2] == 0 elif sol['pp'][(xb,yb)] == 'down': dirr[4] == 0 elif sol['pp'][(xb,yb)] == 'right': dirr[1] == 0 ''' if dirr[1] == 0 and dirr[2] == 0 and dirr[3] == 0 and dirr[ 4] == 0: #if no space sol['sp_stop'].append(nom) sol['tip_cell'].remove([xb, yb]) else: '''Making list of prob''' list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = set_list_prob( dirr) #2.2.(1) '''The Movement''' sol, tipp, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4 = movement( sol, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4) #2.2.(2) '''2.1 Branching Decision''' PP = 'test' if tipp == 'stay' and PP == 'test': #not able to branch, PP untuk pertama kali sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA1' if movi == True: sol['PP'].remove([xb, yb]) sol['pp'].pop((xb, yb)) if dirr.count(0) >= 3: #no space to move sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA2' #print sol['life_time_tip'][nom] if sol['life_time_tip'][nom] < coef[ 'T_branch']: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #there is possibility to branch #print 'YAYAYA3' '''Probability of Branching using life time''' list_prob = range( 1, 11) #prob_by_c(sol,xb,yb) #2.2.(4) tes = randint(1, 10) if not tes in list_prob: #not able to branch sol['life_time_tip'][nom] += set['dt'] sol['life_mit'][nom] += set['dt'] else: #BRANCHING! #print 'YAYAYA4' sol['life_time_tip'][nom] = 0 sol['life_mit'][nom] += set['dt'] sol['matrix_tip'].append([(xb, yb)]) sol['life_time_tip'].append(0) sol['life_mit'].append(0) sol['list_tip_movement'].append('start') tipp = 'stay' '''The Movement from branching''' while tipp == 'stay': sol, tipp = movement_branch( tipp, sol, nom, xb, yb, list_prob_0, list_prob_1, list_prob_2, list_prob_3, list_prob_4) #2.2.(5) return sol, n_o