def process(file): print("**********************") print(file) print("**********************") connection = sqlite3.connect(file) animalPool = AnimalPool() animalPool.loadAnimals(connection) # show the mask of animals at frame 300 animalPool.showMask(300)
def process(file, dataframe, expListToCheck, expListToCheckForPause, expListToCheckForRfid): print(file) #open the database file connection = sqlite3.connect(file) c = connection.cursor() pool = AnimalPool() pool.loadAnimals(connection) if len(pool.animalDictionnary.keys()) > 1: print('More than one animal in this experiment. Please check.') expListToCheck.append(file) elif len(pool.animalDictionnary.keys()) == 1: query = "SELECT PAUSED FROM FRAME WHERE PAUSED = '1'" c.execute(query) rows = c.fetchall() print('existing paused frames: ', rows) if len(rows) == 0: # get the RFID of the tracked animal in the database rfidDatabase = pool.animalDictionnary[1].RFID print('RFID database: ', rfidDatabase) #attribute the corresponding frame number to be changed count = 0 for rfidTable in dataframe['RFID']: #print('RFID table: ', rfidTable) if rfidTable in rfidDatabase: print('RFID: ', rfidTable, rfidDatabase) frameToPause = dataframe[dataframe['RFID'] == rfidTable]['paused_frame'].item() print('paused frame: ', frameToPause) count = 1 if count == 0: print('This RFID is not referenced in the table.') print(file, rfidDatabase) expListToCheckForRfid.append(file) else: #modify the PAUSED status in the database for the corresponding framenumber query = "UPDATE FRAME SET PAUSED = '1' WHERE FRAMENUMBER = {}".format( frameToPause) c.execute(query) else: print('Paused frames already exist; please check') expListToCheckForPause.append(file) connection.commit() c.close() connection.close()
def set_genotype(files): if files is None: print("No files selected (aborting)") return for file in files: print("\n\nFile: ", file) print("-" * 80) if not os.path.exists(file): print(" ! File does not exist... (skipping)") continue with mute_prints(): connection = sqlite3.connect(file) pool = AnimalPool() pool.loadAnimals(connection) print( f"Setting genotype of {len(pool.getAnimalList())} mice, press [Enter] to keep existing one):" ) for animal in sorted(pool.getAnimalList(), key=lambda a: a.name): genotype = input( f" * {animal.name}_{animal.RFID} [{animal.genotype}]: ") genotype = genotype.strip() if len(genotype) > 0: print( f" - setting {animal.name}_{animal.RFID} to '{genotype}'" ) animal.setGenotype(genotype) else: print(f" - keeping genotype {animal.genotype}") print("Genotype saved in database.") print("-" * 120)
if __name__ == '__main__': #ask the user for database to process files = getFilesToProcess() for file in files: # connect to database connection = sqlite3.connect(file) # create an animalPool, which basically contains your animals animalPool = AnimalPool() # load infos about the animals animalPool.loadAnimals(connection) # load all detection (positions) of all animals for the first hour animalPool.loadDetection(start=0, end=oneHour) eventTimeLine = EventTimeLine(connection, "Oral-genital Contact", idA=1, idB=2, minFrame=0, maxFrame=oneHour) print("Event list for label ", eventTimeLine.eventNameWithId) print("for animal 1:", animalPool.getAnimalDictionnary()[1].RFID) print("for animal 2:", animalPool.getAnimalDictionnary()[2].RFID) print("Number of events:", len(eventTimeLine.getEventList()))