-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from fdechaumont/dev
Merge dev to master
- Loading branch information
Showing
12 changed files
with
991 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.