Title: | Read Ethoscope Data |
---|---|
Description: | Handling of behavioural data from the Ethoscope platform (Geissmann, Garcia Rodriguez, Beckwith, French, Jamasb and Gilestro (2017) <DOI:10.1371/journal.pbio.2003026>). Ethoscopes (<http://gilestrolab.github.io/ethoscope/>) are an open source/open hardware framework made of interconnected raspberry pis (<https://www.raspberrypi.org>) designed to quantify the behaviour of multiple small animals in a distributed and real-time fashion. The default tracking algorithm records primary variables such as xy coordinates, dimensions and speed. This package is part of the rethomics framework <http://rethomics.github.io/>. |
Authors: | Quentin Geissmann [aut, cre] |
Maintainer: | Quentin Geissmann <[email protected]> |
License: | GPL-3 |
Version: | 0.3.3 |
Built: | 2025-02-28 06:03:47 UTC |
Source: | https://github.com/rethomics/scopr |
This function is used to obtain experimental information – such as time and date of the experiment,
acquisition device, and version of the software –
embedded in a result file (.db
) generated by the ethoscope platform.
experiment_info(FILE)
experiment_info(FILE)
FILE |
the name of the input file |
a list containing fields for metadata entries
load_ethoscope – to load the actual data
list_result_files – to list available files
These functions augment metadata so it can be subsequently loaded (with load_ethoscope).
link_ethoscope_metadata_remote(x, remote_dir, result_dir, index_file = "index.txt", overwrite_local = FALSE, verbose = TRUE) link_ethoscope_metadata(x, result_dir = NULL, index_file = NULL)
link_ethoscope_metadata_remote(x, remote_dir, result_dir, index_file = "index.txt", overwrite_local = FALSE, verbose = TRUE) link_ethoscope_metadata(x, result_dir = NULL, index_file = NULL)
x |
object such as a data.frame, or the name of a file (see detail) |
remote_dir |
the url of the result directory on the data server |
result_dir |
the directory where all data are saved |
index_file |
the name of an index_file, in |
overwrite_local |
whether to download all files.
The default, |
verbose |
whether to print progress (a logical) |
These function will augment metadata from two different types of inputs (x
):
A data.frame (recomended)
In this case, the function will try to match requested data with data available on result_dir
.
The provided data.table has typically one row per requested individual and the columns
(not necessarily in this order):
machine_name
– the name of the machine in which the individual was (e.g. "ETHOSCOPE_001"
)
date
– the start date of the experiment formatted as "YYYY-MM-DD"
region_id
– the ROI in which the animal was. When not provided, all regions are queried.
time
– the start time of the experiment formatted as "HH:MM:SS".
When not provided, and multiple experiment for the same machine exist, only the last one is loaded.
???
– any number of arbitrary columns* to associate conditions
/treatments
/genotypes
/... to the previous columns.
The name of a CSV file that contains a table as described in 1
.
A vector of .db
files to be read.
a data.table::data.table with the same rows as x, and extra columns for further data loading
metadata tutorial – how to work with metadata
load_ethoscope – to load the actual data
list_result_files – to list available file
# Metadata with no region_id -> all regions will be loaded with the same metadata dir <- paste0(scopr_example_dir(), "/ethoscope_results/") data(no_region_id_metadata) metadata <- link_ethoscope_metadata(no_region_id_metadata, dir) print(metadata) # Metadata with region_id -> only stated regions will be loaded with specific metadata data(region_id_metadata) metadata <- link_ethoscope_metadata(region_id_metadata, dir) print(metadata) ## Not run: # If your files are stored on a remote server, # this will download to a local directory only the needed files REMOTE <- "ftp://a/remote/server/" LOCAL_DIR <- "/where/I/store/the/data/" metadata <- link_ethoscope_metadata_remote(region_id_metadata, REMOTE, LOCAL_DIR) ## End(Not run)
# Metadata with no region_id -> all regions will be loaded with the same metadata dir <- paste0(scopr_example_dir(), "/ethoscope_results/") data(no_region_id_metadata) metadata <- link_ethoscope_metadata(no_region_id_metadata, dir) print(metadata) # Metadata with region_id -> only stated regions will be loaded with specific metadata data(region_id_metadata) metadata <- link_ethoscope_metadata(region_id_metadata, dir) print(metadata) ## Not run: # If your files are stored on a remote server, # this will download to a local directory only the needed files REMOTE <- "ftp://a/remote/server/" LOCAL_DIR <- "/where/I/store/the/data/" metadata <- link_ethoscope_metadata_remote(region_id_metadata, REMOTE, LOCAL_DIR) ## End(Not run)
This function discovers all ethoscope result files and put them in a data.table::data.table. This is useful to figure out when and which experiments were performed.
list_result_files(result_dir, index_file = NULL)
list_result_files(result_dir, index_file = NULL)
result_dir |
the root directory where all data are saved, or the path to a remote directory. |
index_file |
the name of an index_file, in |
a data.table::data.table.
Each row is a single experimental file, and columns describe details such as its path
, start date
and time
,
and the name and id of the ethoscope used.
load_ethoscope – to load the actual data
experiment_info – to show the metadata of a specific experiment
This function is used to import behavioural data generated
by the ethoscope platform.
That is it loads multiple .db
files into a single R
behavr::behavr table.
load_ethoscope(metadata, min_time = 0, max_time = Inf, reference_hour = NULL, verbose = TRUE, columns = NULL, cache = NULL, ncores = 1, FUN = NULL, ...)
load_ethoscope(metadata, min_time = 0, max_time = Inf, reference_hour = NULL, verbose = TRUE, columns = NULL, cache = NULL, ncores = 1, FUN = NULL, ...)
metadata |
data.table::data.table used to load data (see detail) |
min_time , max_time
|
load only data between |
reference_hour |
hour, in the day, to use as ZT0 reference. When unspecified, time will be relative to the start of the experiment. |
verbose |
whether to print progress (a logical) |
columns |
optional vector of columns to be selected from the db file.
Time (t) is always implicitly selected.
When |
cache |
the name of a local directory to cache results for faster subsequent data loading. |
ncores |
number of cores to use for optional parallel processing (experimental). |
FUN |
function (optional) to transform the data from each individual immediately after is has been loaded. |
... |
extra arguments to be passed to |
the linked metadata should be generated using link_ethoscope_metadata.
A behavr table. In addition to the metadata, it contains the data, with the columns:
id
– autogenerated unique identifier, one per animal
t
– time (s)
Several variables recorded by ethoscopes (position, angle, width/height and others), or computed by FUN
.
Distance units (e.g. xy position, height/width) are expressed as a fraction of the width of the ROI they originate from.
behavr tutorial – how to work with the obtained behavr table
behavr::behavr – to understand the output format
experiment_info – to show information about a file/experiment
list_result_files – to list available files
dir <- paste0(scopr_example_dir(), "/ethoscope_results/") data(region_id_metadata) metadata <- link_ethoscope_metadata(region_id_metadata, dir) print(metadata) # Default data loading dt <- load_ethoscope(metadata) dt # We use reference hour to set zt0 to 09:00 GMT dt <- load_ethoscope(metadata, reference_hour=9) dt # Only load x and y positions dt <- load_ethoscope(metadata, columns=c("x", "y"), reference_hour=9) dt # apply function whilst loading the data dt <- load_ethoscope(metadata, reference_hour=9, FUN=head) dt
dir <- paste0(scopr_example_dir(), "/ethoscope_results/") data(region_id_metadata) metadata <- link_ethoscope_metadata(region_id_metadata, dir) print(metadata) # Default data loading dt <- load_ethoscope(metadata) dt # We use reference hour to set zt0 to 09:00 GMT dt <- load_ethoscope(metadata, reference_hour=9) dt # Only load x and y positions dt <- load_ethoscope(metadata, columns=c("x", "y"), reference_hour=9) dt # apply function whilst loading the data dt <- load_ethoscope(metadata, reference_hour=9, FUN=head) dt
test
) per experiment.
Implicitly, 20 individuals are in each experiment
It serves as a simple example.Simple toy metadata defining three experiments, with one condition (test
) per experiment.
Implicitly, 20 individuals are in each experiment
It serves as a simple example.
no_region_id_metadata
no_region_id_metadata
An object of class data.frame
with 3 rows and 4 columns.
Quentin Geissmann
test
) is linked to the experiments, and another condition (treatment
) is per individual.
It serves as a simple example.
#'Simple toy metadata experimental conditions for 15 individuals in three experiments.
the condition (test
) is linked to the experiments, and another condition (treatment
) is per individual.
It serves as a simple example.
#'
region_id_metadata
region_id_metadata
An object of class data.frame
with 15 rows and 6 columns.
Quentin Geissmann
scopr
comes with a sample DAM2 files in its inst/extdata
directory. scopr_example
allow make them easy to access.
scopr_example(path = NULL) scopr_example_dir()
scopr_example(path = NULL) scopr_example_dir()
path |
Name of file. If |
# list all files scopr_example()
# list all files scopr_example()