nightEventTimeLine = EventTimeLineCached(connection, file, "night", minFrame=tmin, maxFrame=tmax) n = 1 header = [ "file", "event", "RFID_A", "geno_A", "RFID_B", "geno_B", "minTime", "maxTime", "dur", "nb" ] for name in header: text_file.write("{}\t".format(name)) text_file.write("{}\n".format("night")) for eventNight in nightEventTimeLine.getEventList(): minT = eventNight.startFrame maxT = eventNight.endFrame print("Night: ", n) for behavEvent in behaviouralEventTwoMice: print("computing {} density".format(behavEvent)) for animal in pool.animalDictionnary: animalDiffGeno = [] animalSameGeno = [] for animal in pool.animalDictionnary: if (pool.animalDictionnary[animal].baseId ==
pool.loadAnimals( connection ) if nightComputation == "T": minT = tmin maxT = tmax n = 0 #Compute profile data and save them in a text file profileData[file][n] = computeProfile(file = file, minT=minT, maxT=maxT, night=n) text_file.write( "\n" ) print("Profile data saved.") elif nightComputation == "N": nightEventTimeLine = EventTimeLineCached( connection, file, "night", minFrame=tmin, maxFrame=tmax ) n = 1 for eventNight in nightEventTimeLine.getEventList(): minT = eventNight.startFrame maxT = eventNight.endFrame print("Night: ", n) #Compute profile data and save them in a text file profileData[file][n] = computeProfile(file=file, minT=minT, maxT=maxT, night=n) text_file.write( "\n" ) n+=1 print("Profile data saved.") elif nightComputation == "D": dayEventTimeLine = EventTimeLineCached( connection, file, "day", minFrame=tmin, maxFrame=tmax ) d = 1 for eventDay in dayEventTimeLine.getEventList(): minT = eventDay.startFrame maxT = eventDay.endFrame
def reBuildEvent(connection, file, tmin=None, tmax=None, pool=None): pool = AnimalPool() pool.loadAnimals(connection) #pool.loadDetection( start = tmin, end = tmax ) ''' load contact matrix ''' contact = {} group3In = {} group3Out = {} for idAnimalA in range(1, 5): contact[idAnimalA] = EventTimeLineCached(connection, file, "Contact", idAnimalA, minFrame=tmin, maxFrame=tmax) group3In[idAnimalA] = EventTimeLine(connection, "Group 3 make", idAnimalA, loadEvent=False) group3Out[idAnimalA] = EventTimeLine(connection, "Group 3 break", idAnimalA, loadEvent=False) ''' process group ''' for idAnimalA in range(1, 5): for idAnimalB in range(1, 5): for idAnimalC in range(1, 5): ''' check impossible combination (avoid 2 animals with same id) ''' test = {} test[idAnimalA] = True test[idAnimalB] = True test[idAnimalC] = True if not len(test.keys()) == 3: continue ''' process group ''' group3 = EventTimeLineCached(connection, file, "Group3", idAnimalA, idAnimalB, idAnimalC, minFrame=tmin, maxFrame=tmax) eventList = group3.getEventList() for event in eventList: t = event.startFrame - 1 if (not contact[idAnimalA].hasEvent(t)): group3In[idAnimalA].addPunctualEvent(t) if (not contact[idAnimalB].hasEvent(t)): group3In[idAnimalB].addPunctualEvent(t) if (not contact[idAnimalC].hasEvent(t)): group3In[idAnimalC].addPunctualEvent(t) t = event.endFrame + 1 if (not contact[idAnimalA].hasEvent(t)): group3Out[idAnimalA].addPunctualEvent(t) if (not contact[idAnimalB].hasEvent(t)): group3Out[idAnimalB].addPunctualEvent(t) if (not contact[idAnimalC].hasEvent(t)): group3Out[idAnimalC].addPunctualEvent(t) ''' save all ''' for idAnimal in range(1, 5): group3In[idAnimal].endRebuildEventTimeLine(connection) group3Out[idAnimal].endRebuildEventTimeLine(connection) # log process from lmtanalysis.TaskLogger import TaskLogger t = TaskLogger(connection) t.addLog("Build Event Group3 Make Break", tmin=tmin, tmax=tmax) print("Rebuild event finished.")
def computeSpeedDurationPerEvent(animalData, files, tmin, tmax, eventToTest=None): print("Compute the speed and duration of specific events ") for file in files: connection = sqlite3.connect(file) pool = AnimalPool() pool.loadAnimals(connection) pool.loadDetection(tmin, tmax, lightLoad=True) rfidList = [] for animal in pool.animalDictionnary.keys(): print("computing individual animal: {}".format(animal)) rfid = pool.animalDictionnary[animal].RFID rfidList.append(rfid) group = rfidList[0] for n in range(1, len(rfidList)): group = group + '-' + rfidList[n] animalData[file] = {} nightEventTimeLine = EventTimeLineCached(connection, file, "night", minFrame=tmin, maxFrame=tmax) n = 1 for eventNight in nightEventTimeLine.getEventList(): minT = eventNight.startFrame maxT = eventNight.endFrame print("Night: ", n) animalData[file][n] = {} for animal in pool.animalDictionnary.keys(): print("computing individual animal: {}".format(animal)) rfid = pool.animalDictionnary[animal].RFID print("RFID: {}".format(rfid)) animalData[file][n][rfid] = {} # store the animal animalData[file][n][rfid]["animal"] = pool.animalDictionnary[ animal].name animalObject = pool.animalDictionnary[animal] animalData[file][n][rfid]["file"] = file animalData[file][n][rfid]['genotype'] = pool.animalDictionnary[ animal].genotype animalData[file][n][rfid]['sex'] = pool.animalDictionnary[ animal].sex animalData[file][n][rfid]['strain'] = pool.animalDictionnary[ animal].strain animalData[file][n][rfid]['age'] = pool.animalDictionnary[ animal].age animalData[file][n][rfid]['group'] = group print("computing individual event: {}".format(eventToTest)) behavEventTimeLine = EventTimeLineCached(connection, file, eventToTest, animal, minFrame=minT, maxFrame=maxT) animalData[file][n][rfid]['DurationSpeed'] = [] animalData[file][n][rfid]['speed'] = [] for event in behavEventTimeLine.getEventList(): results = getDurationSpeed(event=event, animal=animalObject) #print('duration, speed: ', results) animalData[file][n][rfid]['DurationSpeed'].append(results) animalData[file][n][rfid]['speed'].append(results[1]) n += 1 connection.close() with open("durationSpeedData_{}.json".format(eventToTest), 'w') as jFile: json.dump(animalData, jFile, indent=3) print("json file created for all data")