Skip to content

Commit

Permalink
Added read_bonsai and light testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikkel Roald-Arbøl committed Oct 24, 2024
1 parent 3f721af commit 3a50d45
Show file tree
Hide file tree
Showing 11 changed files with 1,143 additions and 8 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Imports:
lifecycle,
rlang,
stringi,
tidyselect,
vroom,
zoo
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(clean_kinematics)
export(ensure_file_has_expected_headers)
export(ensure_file_has_headers)
export(read_animalta)
export(read_bonsai)
export(read_deeplabcut)
export(read_idtracker)
export(read_movement)
Expand All @@ -22,6 +23,7 @@ export(validate_time)
export(validate_trackball)
import(circular)
import(dplyr)
import(tidyselect)
importFrom(circular,circular)
importFrom(circular,is.circular)
importFrom(cli,cli_abort)
Expand Down
35 changes: 35 additions & 0 deletions R/read_bonsai.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' Read centroid tracking data from Bonsai
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' @param path Path to a Bonsai data file
#' @import dplyr
#' @import tidyselect
#' @importFrom vroom vroom
#'
#' @return a movement dataframe
#' @export
read_bonsai <- function(path) {
# There can be tracking from multiple ROIs at the same time
# We need to check everything matches expectations
# We should be able to use only a single timestamp (should be the same across all ROIs)
validate_files(path, expected_suffix = "csv")
data <- vroom::vroom(
path,
delim = ",",
show_col_types = FALSE
) |>
suppressMessages() |>
dplyr::select(tidyselect::contains(c("Timestamp", "Centroid"))) |>
dplyr::rename(time = tidyselect::contains("Timestamp"),
x = tidyselect::contains("X"),
y = tidyselect::contains("Y")) |>
dplyr::mutate(keypoint = factor("centroid")) |>
dplyr::relocate("keypoint", .after = .data$time)

attributes(data)$spec <- NULL
attributes(data)$problems <- NULL

return(data)
}
4 changes: 2 additions & 2 deletions R/read_deeplabcut.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' @param data A DeepLabCut data frame
#' @param path Path to a DeepLabCut data file
#'
#' @return a movement dataframe
#' @export
read_deeplabcut <- function(data) {
read_deeplabcut <- function(path) {
cli::cli_abort("`read_deeplabcut` has not yet been implemented. Coming soon!")
}
4 changes: 2 additions & 2 deletions R/read_sleap.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' @param data A SLEAP data frame
#' @param path A SLEAP data frame
#'
#' @return a movement dataframe
#' @export
read_sleap <- function(data) {
read_sleap <- function(path) {
cli::cli_abort("`read_sleap` has not yet been implemented. Coming soon!")
}
17 changes: 17 additions & 0 deletions man/read_bonsai.Rd

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

4 changes: 2 additions & 2 deletions man/read_deeplabcut.Rd

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

4 changes: 2 additions & 2 deletions man/read_sleap.Rd

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

49 changes: 49 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@
],
"Hash": "9fe98599ca456d6552421db0d6772d8f"
},
"boot": {
"Package": "boot",
"Version": "1.3-30",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"graphics",
"stats"
],
"Hash": "96abeed416a286d4a0f52e550b612343"
},
"circular": {
"Package": "circular",
"Version": "0.5-1",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"boot",
"mvtnorm",
"stats"
],
"Hash": "3cf8da958fff9dcb209dd1e549a60a05"
},
"cli": {
"Package": "cli",
"Version": "3.6.3",
Expand Down Expand Up @@ -207,6 +232,17 @@
],
"Hash": "7ce2733a9826b3aeb1775d56fd305472"
},
"mvtnorm": {
"Package": "mvtnorm",
"Version": "1.3-1",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"stats"
],
"Hash": "77c61d51ce0f36e3c1a76e6b295aab31"
},
"pillar": {
"Package": "pillar",
"Version": "1.9.0",
Expand Down Expand Up @@ -279,6 +315,19 @@
],
"Hash": "3eec01f8b1dee337674b2e34ab1f9bc1"
},
"stringi": {
"Package": "stringi",
"Version": "1.8.4",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"stats",
"tools",
"utils"
],
"Hash": "39e1144fd75428983dc3f63aa53dfa91"
},
"tibble": {
"Package": "tibble",
"Version": "3.2.1",
Expand Down
Loading

0 comments on commit 3a50d45

Please sign in to comment.