def trajBuilder(new_sol): stories = ordonnancement(new_sol); res = {} for plate in stories: res.update({plate : {}}) for well in stories[plate]: print plate, well ensembleTraj = fHacktrack2.ensTraj() res[plate].update({well:ensembleTraj}) # print ensembleTraj.numMitoses # print ensembleTraj.lstTraj num = 0; l=[0] beginningFrames=[0,128,129,75] for index in stories[plate][well]: print "INDEX ", index solC = stories[plate][well][index] if type(solC.truth)==str: l.append(index+1) continue singlets = solC.singlets nextSinglets = solC.nextSinglets result =filter(lambda x: x[1]==1, zip(solC.hypotheses, solC.truth)) for hyp in result: s, t = hyp[0]; source = [] ; target = []; if type(s)==np.int32 and s!=-1: source.append(filter(lambda x: x.label == s, singlets)[0]) elif type(s)==tuple: for c in s: source.append(filter(lambda x: x.label == c, singlets)[0]) if type(t)==np.int32 and t!=-1: target.append(filter(lambda x: x.label == t, nextSinglets)[0]) elif type(t)==tuple: for c in t: target.append(filter(lambda x: x.label == c, nextSinglets)[0]) incoming = len(source) ; outcoming= len(target) mit = (outcoming>1) # if mit: pdb.set_trace() num+=1 if incoming == 0: # print "APPEAR" for c in target: newTraj= fHacktrack2.trajectoire(num, c.center[0], c.center[1], index+1, c.label) newTraj.longueurs=[index+1] newTraj.fractions=[1] ensembleTraj.add(newTraj) num+=1 continue elif outcoming ==0: # print "DISAPPEAR" if index in l: #pdb.set_trace()#en fait ce sont au moins les trajectoires qui commencent en 0 et finissent en 0 ie les apparitions disparitions en 0 for c in source: newTraj = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) newTraj.longueurs = [index] newTraj.fractions=[1] ensembleTraj.add(newTraj) num+=1 continue elif incoming == 1: # print "FROM ONE" c = source[0] incomingTraj = ensembleTraj.findLabelFrame(c.label, index) if outcoming <= len(incomingTraj): first = True; ll=[]; lf=[] # for traj in incomingTraj: # ll.extend(traj.longueurs) # lf.extend(traj.fractions) # if ll==[] and index>0: # pdb.set_trace() for traj in incomingTraj: try: t = target.pop() except IndexError: continue else: traj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) # traj.longueurs = ll; traj.fractions = lf if first: numC = traj.numCellule if mit: # print "ajout mitose" traj.mitose=1; traj.numCellule = numC; first = False #traj.ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 else: i = 0; first = True; ll=[]; lf=[] # for traj in incomingTraj: # ll.extend(traj.longueurs) # lf.extend(traj.fractions) # if ll==[] and index>0: # pdb.set_trace() for t in target: try: incomingTraj[i].ajoutPoint(t.center[0], t.center[1], index+1, t.label) # incomingTraj[i].longueurs = ll; incomingTraj[i].fractions = lf if first: numC = incomingTraj[i].numCellule if mit: # print "ajout mitose" incomingTraj[i].mitose=1; incomingTraj[i].numCellule = numC; first = False #incomingTraj[i].ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 i+=1 except IndexError: if not mit: #ici on n'y arrive a t=0 quand aucune trajectoire n'est initialise if index not in beginningFrames: pdb.set_trace() num+=1 newTraj = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) newTraj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) newTraj.longueurs=[index]; newTraj.fractions = [1] if first: numC = num if mit: newTraj = fHacktrack2.trajectoire(numC, c.center[0], c.center[1], index, c.label) newTraj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) newTraj.longueurs = incomingTraj[0].longueurs if incomingTraj !=[] else [index] newTraj.fractions = incomingTraj[0].fractions if incomingTraj !=[] else [1] #pdb.set_trace() # print "ajout mitose" newTraj.mitose=1 first = False #newTraj.ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 #pdb.set_trace() ensembleTraj.add(newTraj) elif incoming >1: if outcoming>1: raise # print "FROM MORE THAN ONE" t = target[0]; tt=None if index not in beginningFrames: tt=[]; ll=[]; lf=[] for c in source: incomingTraj = ensembleTraj.findLabelFrame(c.label, index) tt.append(incomingTraj[0]) k=0 for lon in incomingTraj[0].longueurs: ll.append(lon) lf.append(incomingTraj[0].fractions[k]/float(incoming)) k+=1 # if ll==[] and index>0: # pdb.set_trace() i=0 for c in source: try: trajC = tt[i] trajC.longueurs = ll; trajC.fractions = lf # pdb.set_trace() except: #on tombe ici a t=0 mais est-ce qu'on y tombe apres ? if index not in beginningFrames: pdb.set_trace() num+=1 trajC = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) trajC.longueurs=[index for bb in range(incoming)]; trajC.fractions = [1/float(incoming) for bb in range(incoming)] ensembleTraj.add(trajC) finally: trajC.ajoutPoint(t.center[0], t.center[1], index+1, t.label) i+=1 #incomingTraj[0].ajoutMomentInteressant(c.center[0], c.center[1], index) return res
def lireDot(nomDot): fDot = open(nomDot, "r") mesLignes=fDot.readlines() fDot.close() del mesLignes[0:3] mesLignes.reverse() continuer = True ensembleTraj = fHacktrack2.ensTraj() print ensembleTraj.numMitoses print ensembleTraj.lstTraj trajCourante = fHacktrack2.trajectoire(0,0,0,0,0) frameSuivante =-1 idSuivante =-1 while continuer: ligneCourante=mesLignes.pop() if ("#AAAAAA" in ligneCourante): continuer = False continue decomp = ligneCourante.split(" ") decomp[0]=decomp[0][1:-1] frameCourante = int(decomp[0].split("_")[0]) idCourante = int(decomp[0].split("_")[1]) decomp[2]=decomp[2][1:-1] # if idCourante==105 and frameCourante ==1: # pdb.set_trace() if (int(frameCourante) != int(frameSuivante) or int(idCourante) != int(idSuivante)): if frameSuivante!=-1 and idSuivante!=-1: trajCourante.ajoutPoint(0,0, frameSuivante, idSuivante) trajectoires = ensembleTraj.trouver(trajCourante.numCellule) lstPointsTotale = [] for trajec in trajectoires.lstTraj: for element in trajec.lstPoints.keys(): #print element lstPointsTotale.append(element) #if lstPointsTotale <> []: print lstPointsTotale if (frameCourante, idCourante) in lstPointsTotale or (frameCourante, idCourante) in trajCourante.lstPoints.keys(): #print "mitose", frameCourante, idCourante trajCourante.mitose = 1 ensembleTraj.numMitoses +=1 if (frameCourante, idCourante) in trajCourante.lstPoints.keys(): trajCourante.ajoutPoint(0, 0, frameCourante, idCourante) ensembleTraj.ajouter(trajCourante) num = trajCourante.numCellule # print num trajCourante.supp() trajCourante = fHacktrack2.trajectoire(num, 0,0, frameCourante, idCourante) trajCourante.mitose = 1 else: # print "nouvelle trajectoire", frameCourante, idCourante ensembleTraj.ajouter(trajCourante) num = trajCourante.numCellule+1 trajCourante.supp() trajCourante = fHacktrack2.trajectoire(num, 0,0, frameCourante, idCourante) # print trajCourante.lstPoints else: # print "ajout point" trajCourante.ajoutPoint(0, 0, frameCourante, idCourante) # print trajCourante.lstPoints frameSuivante = int(decomp[2].split("_")[0]) idSuivante = int(decomp[2].split("_")[1]) ensembleTraj.ajouter(trajCourante) return ensembleTraj
def trajBuilder(new_sol, training=False): stories = tracking.ordonnancement(new_sol); res = {} global movie_length for plate in stories: res.update({plate : {}}) movie_length.update({plate : {}}) for well in stories[plate]: print plate, well ensembleTraj = fHacktrack2.ensTraj() res[plate].update({well:ensembleTraj}) movie_length[plate].update({well : max(stories[plate][well].keys())+1}) # print ensembleTraj.numMitoses # print ensembleTraj.lstTraj num = 0; l=[0]; mergeList=-1; trajC=None for index in stories[plate][well]: print " INDEX ", index, solC = stories[plate][well][index] if type(solC.truth)==str: l.append(index+1) continue singlets = solC.singlets nextSinglets = solC.nextSinglets result =filter(lambda x: x[1]==1, zip(solC.hypotheses, solC.truth)) for hyp in result: #print hyp #if index==86: pdb.set_trace() s, t = hyp[0]; source = [] ; target = []; if type(s) in [np.int32, np.uint16] and s!=-1: source.append(filter(lambda x: x.label == s, singlets)[0]) elif type(s)==tuple: for c in s: source.append(filter(lambda x: x.label == c, singlets)[0]) if type(t) in [np.int32, np.uint16] and t!=-1: target.append(filter(lambda x: x.label == t, nextSinglets)[0]) elif type(t)==tuple: for c in t: target.append(filter(lambda x: x.label == c, nextSinglets)[0]) incoming = len(source) ; outcoming= len(target) mit = (outcoming>1) # if mit: pdb.set_trace() num+=1 if incoming == 0: # print "APPEAR" for c in target: newTraj= fHacktrack2.trajectoire(num, c.center[0], c.center[1], index+1, c.label) newTraj.longueurs=[index+1] newTraj.fractions=[1] ensembleTraj.add(newTraj) num+=1 continue elif outcoming ==0: # print "DISAPPEAR" if index in l: #pdb.set_trace()#en fait ce sont au moins les trajectoires qui commencent en 0 et finissent en 0 ie les apparitions disparitions en 0 for c in source: newTraj = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) newTraj.longueurs = [index] newTraj.fractions=[1] ensembleTraj.add(newTraj) num+=1 continue elif incoming == 1: # print "FROM ONE" c = source[0] incomingTraj = ensembleTraj.findLabelFrame(c.label, index) if outcoming <= len(incomingTraj): first = True; ll=[]; lf=[] # for traj in incomingTraj: # ll.extend(traj.longueurs) # lf.extend(traj.fractions) # if ll==[] and index>0: # pdb.set_trace() for traj in incomingTraj: try: t = target.pop() except IndexError: continue else: traj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) # traj.longueurs = ll; traj.fractions = lf if first: numC = traj.numCellule if mit: # print "ajout mitose" traj.split(index); traj.numCellule = numC; first = False #traj.ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 else: i = 0; first = True; ll=[]; lf=[] # for traj in incomingTraj: # ll.extend(traj.longueurs) # lf.extend(traj.fractions) # if ll==[] and index>0: # pdb.set_trace() for t in target: try: incomingTraj[i].ajoutPoint(t.center[0], t.center[1], index+1, t.label) # incomingTraj[i].longueurs = ll; incomingTraj[i].fractions = lf if first: numC = incomingTraj[i].numCellule trajC = incomingTraj[i] mergeList = incomingTraj[i].fusion if mit: # print "ajout mitose" incomingTraj[i].split(index); incomingTraj[i].numCellule = numC; first = False #incomingTraj[i].ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 i+=1 except IndexError: if not mit: #ici on y arrive a t=0 quand aucune trajectoire n'est initialise ou cas de split a quatre sorti du TS if index>0 and training==False: pdb.set_trace() num+=1 newTraj = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) newTraj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) newTraj.longueurs=[index]; newTraj.fractions = [1] if first: numC = num if index>0 and training==False: print hyp pdb.set_trace() if mit: #ici, quand j'ai une mitose je copie toute la trajectoire precedente dans la nouvelle OU PAS ? newTraj = fHacktrack2.trajectoire(numC, c.center[0], c.center[1], index, c.label) newTraj.ajoutPoint(t.center[0], t.center[1], index+1, t.label) newTraj.longueurs = incomingTraj[0].longueurs if incomingTraj !=[] else [index] newTraj.fractions = incomingTraj[0].fractions if incomingTraj !=[] else [1] #print id(trajC), numC, hyp, mergeList #pdb.set_trace() newTraj.fusion=list(mergeList) if type(mergeList)==list else mergeList #pdb.set_trace() # print "ajout mitose" newTraj.split(index) first = False #newTraj.ajoutMomentInteressant(c.center[0], c.center[1], index) ensembleTraj.numMitoses+=1 #pdb.set_trace() ensembleTraj.add(newTraj) elif incoming >1: if outcoming>1: raise # print "FROM MORE THAN ONE" t = target[0]; tt=None if index>0: tt=[]; ll=[]; lf=[] for c in source: incomingTraj = ensembleTraj.findLabelFrame(c.label, index) try: tt.append(incomingTraj[0]) except IndexError: pass else: k=0 for lon in incomingTraj[0].longueurs: ll.append(lon) lf.append(incomingTraj[0].fractions[k]/float(incoming)) k+=1 # if ll==[] and index>0: # pdb.set_trace() i=0 for c in source: try: trajC = tt[i] trajC.longueurs = ll; trajC.fractions = lf # pdb.set_trace() except: #on tombe ici a t=0 mais est-ce qu'on y tombe apres ? oui si on calcule les trajectoires du training #set pcq il y a des evenements elimines par defaut (mvt a quatre) if index>0 and training==False: pdb.set_trace() num+=1 trajC = fHacktrack2.trajectoire(num, c.center[0], c.center[1], index, c.label) trajC.longueurs=[index for bb in range(incoming)]; trajC.fractions = [1/float(incoming) for bb in range(incoming)] ensembleTraj.add(trajC) finally: trajC.ajoutPoint(t.center[0], t.center[1], index+1, t.label) #print id(trajC), trajC.numCellule, trajC.fusion #pdb.set_trace() trajC.merge(index) i+=1 #incomingTraj[0].ajoutMomentInteressant(c.center[0], c.center[1], index) return res