Skip to content

Commit

Permalink
Merge pull request #17 from fdechaumont/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
fdechaumont authored May 24, 2024
2 parents 1db992c + a65583e commit 4b66ff9
Show file tree
Hide file tree
Showing 12 changed files with 991 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/codestream.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/lmt-analysis.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions LMT/experimental/Animal_LMTtoolkit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'''
Created by Nicolas Torquet at 16/02/2024
[email protected]
Copyright: CNRS - INSERM - UNISTRA - ICS - IGBMC
CNRS - Mouse Clinical Institute
PHENOMIN, CNRS UMR7104, INSERM U964, Université de Strasbourg
Code under GPL v3.0 licence
Code derived from Animal code
Compatible with LMT-toolkit
'''


from lmtanalysis.Animal import *




class AnimalToolkit(Animal):

def __init__(self, ID, RFID, NAME=None, GENOTYPE=None, TREATMENT=None, AGE=None, SEX=None, STRAIN=None, SETUP=None,
conn=None, animalType=AnimalType.MOUSE):
self.baseId = ID
self.RFID = RFID
self.genotype = GENOTYPE
self.name = NAME
self.age = AGE
self.sex = SEX
self.strain = STRAIN
self.setup = SETUP
self.treatment = TREATMENT
self.conn = conn
self.detectionDictionary = {}
self.parameters = None
self.setAnimalType(animalType)


def getTrajectory(self, maskingEventTimeLine=None):
keyList = sorted(self.detectionDictionary.keys())

if maskingEventTimeLine != None:
keyList = maskingEventTimeLine.getDictionary()

trajectory = {}

for key in keyList:
coordinates = self.detectionDictionary.get(key)
trajectory[key] = (coordinates.massX, -coordinates.massY)

return trajectory



class AnimalPoolToolkit(AnimalPool):
"""
Manages an experiment.
"""

def __init__(self):
AnimalPool.__init__(self)



def loadAnimals(self, conn):

print("Loading animals.")
cursor = conn.cursor()
self.conn = conn

# check experiment parameters

# Check the number of row available in base
query = "SELECT * FROM ANIMAL"
cursor.execute(query)
field_names = [i[0] for i in cursor.description]
# print("Fields available in lmtanalysis: ", field_names)

rows = cursor.fetchall()

cursor.close()

self.animalDictionary.clear()
print("----------------")
print(type(field_names))
for row in rows:
animal = None
animalPrep = {}
for index, field in enumerate(field_names):
animalPrep[field] = row[index]
animal = AnimalToolkit(**animalPrep, conn=conn)

if (animal != None):
self.animalDictionary[animal.baseId] = animal
print(animal)
else:
print("Animal loader : error while loading animal.")

def getSexList(self):
sexes = {}

for k in self.animalDictionary:
animal = self.animalDictionary[k]
sexes[animal.sex] = True

return sexes.keys()
3 changes: 3 additions & 0 deletions LMT/lmtanalysis/ParametersMouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ class ParametersMouse():
(114,353)
]

''' Margin to define whole cage area without a border in cm '''
CAGE_MARGIN = 3

5 changes: 5 additions & 0 deletions LMT/lmtanalysis/ParametersRat.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ class ParametersRat():
(114,353)
]

''' Margin to define whole cage area without a border in cm '''
# TODO check value for the rat
CAGE_MARGIN = 6


69 changes: 69 additions & 0 deletions LMT/lmtanalysis/ZoneArena.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'''
Created by Nicolas Torquet at 14/02/2024
[email protected]
Copyright: CNRS - INSERM - UNISTRA - ICS - IGBMC
CNRS - Mouse Clinical Institute
PHENOMIN, CNRS UMR7104, INSERM U964, Université de Strasbourg
Code under GPL v3.0 licence
'''


from Parameters import getAnimalTypeParameters


def getZoneCoordinatesFromCornerCoordinatesOpenfieldArea(animalType = None):
parameters = getAnimalTypeParameters(animalType)
'''
parameters contains cornerCoordinatesOpenFieldArea attribute like:
cornerCoordinatesOpenFieldArea = [
(114,63),
(398,63),
(398,353),
(114,353)
]
'''
# coordinates of the whole cage: xa = 111, xb = 400, ya = 63, yb = 353
zoneCoordonates = {
'xa': parameters.cornerCoordinatesOpenFieldArea[0][0],
'xb': parameters.cornerCoordinatesOpenFieldArea[2][0],
'ya': parameters.cornerCoordinatesOpenFieldArea[0][1],
'yb': parameters.cornerCoordinatesOpenFieldArea[2][1]
}

return zoneCoordonates



def getSmallerZoneFromCornerCoordinatesAndMargin(margin, animalType = None):
'''
:param margin: in centimeters: has to be converted to pixels
'''
parameters = getAnimalTypeParameters(animalType)
scaleFactor = parameters.scaleFactor
marginInPixels = margin/scaleFactor
zoneCoordonates = {
'xa': parameters.cornerCoordinatesOpenFieldArea[0][0]+marginInPixels,
'xb': parameters.cornerCoordinatesOpenFieldArea[2][0]-marginInPixels,
'ya': parameters.cornerCoordinatesOpenFieldArea[0][1]+marginInPixels,
'yb': parameters.cornerCoordinatesOpenFieldArea[2][1]-marginInPixels
}
return zoneCoordonates


def getSmallerZoneFromGivenWholeCageCoordinatesAndMargin(margin, wholeCageCoordinates, animalType = None):
'''
:param margin: in centimeters: has to be converted to pixels
:param wholeCageCoordinates: has to be like {xa = 111, xb = 400, ya = 63, yb = 353}
'''
parameters = getAnimalTypeParameters(animalType)
scaleFactor = parameters.scaleFactor
marginInPixels = margin/scaleFactor
zoneCoordonates = {
'xa': wholeCageCoordinates['xa']+marginInPixels,
'xb': wholeCageCoordinates['xb']-marginInPixels,
'ya': wholeCageCoordinates['ya']+marginInPixels,
'yb': wholeCageCoordinates['yb']-marginInPixels
}
return zoneCoordonates


Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import random
from random import randint
from scipy.stats._morestats import shapiro
from scipy.stats.morestats import shapiro

def computeProfile(file, minT, maxT, behaviouralEventList):

Expand Down Expand Up @@ -1991,7 +1991,7 @@ def plotZScoreProfileAutoHorizontal(ax, cat, koDataframe, night, eventListForTes
n = 0
extension = 'no_night_{}'.format(os.path.splitext(os.path.basename(tail))[0])
#Compute profile2 data and save them in a text file
profileData[file][n] = computeProfilePair(file = file, minT=minT, maxT=maxT, behaviouralEventListSingle=behaviouralEventOneMouse, behaviouralEventListSocial=behaviouralEventOneMouse)
profileData[file][n] = computeProfilePair(file = file, minT=minT, maxT=maxT, behaviouralEventListSingle=behaviouralEventOneMouseSingle, behaviouralEventListSocial=behaviouralEventOneMouseSocial)


else:
Expand Down Expand Up @@ -2040,8 +2040,8 @@ def plotZScoreProfileAutoHorizontal(ax, cat, koDataframe, night, eventListForTes
n = 0
# Compute profile2 data
profileData[file][n] = computeProfilePairFromPause(file=file, experimentDuration=experimentDuration,
behaviouralEventListSingle=behaviouralEventOneMouse,
behaviouralEventListSocial=behaviouralEventOneMouse)
behaviouralEventListSingle=behaviouralEventOneMouseSingle,
behaviouralEventListSocial=behaviouralEventOneMouseSocial)

# Create a json file to store the computation
with open("{}/profile_data_pair_from_pause_{}_{}.json".format(head, extension, experimentDuration), 'w') as fp:
Expand Down
Loading

0 comments on commit 4b66ff9

Please sign in to comment.