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()
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import *
from lmtanalysis.Event import EventTimeLine

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)
import sqlite3
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour

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)

        # filter detection by animalSpeed (speed is in centimeters per second)
        animalPool.filterDetectionByInstantSpeed(30, 70)

        # plot and show trajectory
        animalPool.plotTrajectory(
            title="Trajectories filtered by speed (between 30 to 70 cm/s) ")
import sqlite3
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour

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)

        # filter detection by animalSpeed (speed is in centimeters per second)
        animalPool.filterDetectionByInstantSpeed(0, 2)

        # plot and show trajectory
        animalPool.plotTrajectory(
            title="Trajectories filtered by speed (max 2) ")
@author: Fab
'''

import sqlite3
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour

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, lightLoad=True)

        # plot and show trajectory
        animalPool.plotTrajectory()
Beispiel #8
0
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour, oneMinute

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=10 * oneMinute)

        # filter detection by area (in cm from the top left of the cage)
        animalPool.filterDetectionByArea(0, 30, 25, 50)

        # loop over all animals in this database
        for animal in animalPool.getAnimalList():

            animal.plotTrajectory3D()
import sqlite3
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour, oneMinute

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=10 * oneMinute)

        # filter detection by area (in cm from the top left of the cage)
        animalPool.filterDetectionByArea(0, 30, 25, 50)

        # plot and show trajectory
        animalPool.plotTrajectory(title="Trajectories filtered by area")
Beispiel #10
0
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import *
from lmtanalysis.Event import EventTimeLine, plotMultipleTimeLine

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 )
        
        eventTimeLineList = []
        for a in animalPool.getAnimalDictionnary():
            for b in animalPool.getAnimalDictionnary():        
                eventTimeLine = EventTimeLine( connection, "Oral-genital Contact", idA = a, idB = b, minFrame = 0, maxFrame = oneHour )
                eventTimeLineList.append( eventTimeLine )        
                    
        plotMultipleTimeLine( eventTimeLineList )
            
Beispiel #11
0
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import *
from lmtanalysis.Event import EventTimeLine, plotMultipleTimeLine

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 )
        animalPool.loadDetection( 0, 3*24*oneHour )
        
        min = 0
        max = 24*oneHour        
        for animal in animalPool.getAnimalList():
            bt = animal.getBodyThreshold( tmin= min, tmax = max )
            bs = animal.getMedianBodyHeight( tmin= min , tmax = max )
            print (  "min:\t" , str(min), "\tmax:\t", str(max), "\tAnimal:\t" , str(animal.baseId), "\tBT:\t " , str(bt) , "\tBS:\t" , str(bs) )

        min = 24*oneHour    
        max = 2*24*oneHour        
        for animal in animalPool.getAnimalList():
Beispiel #12
0
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import *
from lmtanalysis.Event import EventTimeLine

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",
                                      minFrame=0,
                                      maxFrame=oneHour)

        eventTimeLine.plotTimeLine()
Beispiel #13
0
if __name__ == '__main__':

    #ask the user for database to process
    files = getFilesToProcess()

    minT = 6 * oneHour
    #maxT = 3*oneDay
    maxT = (6 + 1) * oneHour

    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)
        animalPool.loadDetection(0, 1 * oneHour)
        '''
        min = 0
        max = 24*oneHour        
        for animal in animalPool.getAnimalList():
            bt = animal.getBodyThreshold( tmin= min, tmax = max )
            bs = animal.getMedianBodyHeight( tmin= min , tmax = max )
            print (  "min:\t" , str(min), "\tmax:\t", str(max), "\tAnimal:\t" , str(animal.baseId), "\tBT:\t " , str(bt) , "\tBS:\t" , str(bs) )

        print("---")
        for start in range( 0,24 ):
            print("**********")
from lmtanalysis.FileUtil import getFilesToProcess
from lmtanalysis.Animal import AnimalPool
from lmtanalysis.Measure import oneHour, oneMinute

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=10 * oneMinute)

        # filter detection by area (in cm from the top left of the cage)
        animalPool.filterDetectionByArea(0, 30, 25, 50)

        # loop over all animals in this database
        for animal in animalPool.getAnimalList():

            # print RFID of animal
            print("Animal : ", animal.RFID)