def getSingleEventTable(self, event_name): """ Returns pandas table containing all found events for given event name' * Primary mouse' meta data * Event start time * Event end time * Event duration Args: event_name (str): Event name e. g. Rearing Returns: DataFrame """ data = defaultdict(list) for animal in self.getAnimalList(): with mute_prints(): eventTimeLine = EventTimeLine(self.conn, event_name, idA=animal.baseId, minFrame=self.detectionStartFrame, maxFrame=self.detectionEndFrame) for e in eventTimeLine.getEventList(): data["RFID"] .append(f"{animal.name}_{animal.RFID}") data["name"] .append(f"{animal.name}") data["genotype"] .append(f"{animal.genotype}") data["event_name"] .append(event_name) data["start_sec"] .append(e.startFrame / oneSecond) data["end_sec"] .append(e.endFrame / oneSecond) data["duration"] .append(e.duration() / oneSecond) df = pd.DataFrame(data) df.insert(2, "time", pd.to_timedelta(df["start_sec"], unit="s")) return df.sort_values("time").reset_index(drop=True)
def getDyadicGenotypeGroupedEventTable(self, event_list): """ Returns pandas table containing all found events for given event name and the involved mice' genotype * Primary / secondary mice genotype * Event start time * Event end time * Event duration Args:computeEventFeatures event_name (str): Event name e. g. Rearing Returns: DataFrame """ data = defaultdict(list) animal_list = self.getAnimalList() for a in animal_list: if a.genotype is None: print("Genotype for all mice needs to be set... (aborting)") for event_name in tqdm(event_list, desc="Event..."): for A in animal_list: for B in animal_list: if A.baseId == B.baseId: continue with mute_prints(): eventTimeLine = EventTimeLine( self.conn, event_name, idA=A.baseId, idB=B.baseId, minFrame=self.detectionStartFrame, maxFrame=self.detectionEndFrame, ) event_list = eventTimeLine.getEventList() for e in event_list: data["genotype_primary"].append(f"{A.genotype}") data["genotype_secondary"].append(f"{B.genotype}") data["event_name"].append(event_name) data["start_sec"].append(e.startFrame / oneSecond) data["end_sec"].append(e.endFrame / oneSecond) data["duration"].append(e.duration() / oneSecond) df = pd.DataFrame(data) if len(df) == 0: return df df.insert(2, "time", pd.to_timedelta(df["start_sec"], unit="s")) return df.sort_values("time").reset_index(drop=True)
def getAllEventsTable(self): """ Returns pandas table containing all found events for all found event types' * Primary mouse' meta data * Events' start time * Events' end time * Events' duration Returns: DataFrame """ with mute_prints(): all_event_names = getAllEvents(connection=self.conn) event_table = pd.concat([self.getSingleEventTable(event_name) for event_name in all_event_names] , axis=0) return event_table.sort_values("time").reset_index(drop=True)
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)