Coder Social home page Coder Social logo

trackr's Introduction

Note

This package is getting more outdated every day and has never quite reached a stable or finished state. I currently don't have time to further develop it, as I don't work much on behavior right now. However, it can still be useful for various functions and has been used in published papers, so I am leaving it here available for now. Use at own risk.

trackr

This R package provides tools to analyze and visualize animal video tracking data.

Goals

Offer a framework for the analysis of tracking data that is independent to the tracking software used.

There are many tracking solutions available (both proprietary and free software), and many come with their own analysis tools. I believe it is more efficient to have one strong analysis framework for analysis, that can read in data from many trackers. This saves developers from having to offer analysis tools, and the user from re-learning if they make a switch. It can also enable wider adoption of trackers without native analysis tools, such as idTracker.

Offer a way to analyze animal tracking data within R.

R currently offers some of the best statistics and visualization packages out there, and trackr output easily works with them. R is also the main (and often only) language that many end users (biologists) already know, making it a logical choice in many cases.

Installation

You can install this package from within your R session using devtools.

# Install devtools if necessary
# install.packages('devtools')
devtools::install_github('Ax3man/trackr')

Currently supported trackers

Support for other trackers can be added. Please file an issue.

Performance

R is not typically known for lightning fast performance. However, trackr makes use of several packages that speed things up, and make code writing easier. Specifically, it uses data.table to read in large data files and dplyr for data manipulation.

Example code

As a quick example, let's read in some data of male guppy pairs.

library(trackr)
library(dplyr)

# You would read in your data like this:
# guppies <- read_idTracker(folder = 'data')
# But 'guppies' is included with the package, so you can now run:
tr <- as_tracks(guppies, frame_rate = 30, resolution = 1080)

We can get a quick overview by plotting the tracks.

plot(tr)

plot1

It's easy to apply filters to the data before plotting, and we can use the pipe operator (%>%) to chain commands together:

filter(tr, frame %in% 10000:11000, drop = TRUE) %>% plot()

plot1b

All plotting functions output ggplot objects, so they can be easily manipulated:

plot(tr) +
  ggplot2::facet_grid(trial ~ animal) +
  ggplot2::scale_color_manual(values = c('purple', 'limegreen'))

plot1c

If you'd like to see how the behavior changes over the course of a trial, you can use facet by time instead.

plot_time_facets(tr)

plot2 It looks like some periods are a bit more active than others.

Ok, so we have our trajectories, and most of it seems quite ok. Let's calculate some per frame statistics. We use the mutate syntax from dplyr.

tr <- mutate(tr,
             speed = speed(),
             acc = acceleration(),
             turn = angular_velocity())

Summmary statistics also work very similar to dplyr.

tr <- summarize(tr, 
                mean_speed = mean(speed, na.rm = TRUE),
                sum_abs_turn = sum(abs(turn), na.rm = TRUE))

# See summary statistics per animal:
tr$animal

# Source: local data frame [4 x 4]
# 
#    trial animal mean_speed sum_abs_turn
#   (fctr) (fctr)      (dbl)        (dbl)
# 1      a      1   2.092943     23557.73
# 2      a      2   2.569784     25572.35
# 3      b      1   2.675133     15169.35
# 4      b      2   4.018834     14620.87

# See summary statistics per trial:
tr$trial

# Source: local data frame [4 x 4]
# Groups: trial [?]
# 
#    trial mean_speed sum_abs_turn
#   (fctr)      (dbl)        (dbl)
# 1      a   2.331364     49130.07
# 2      b   3.346984     29790.21

trackr's People

Contributors

ax3man avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

digideskio

trackr's Issues

Error on Ctrax csv files saved in European Locale.

I have tried to read a large amount of Ctrax .csv files into tracker but I get an error message:

Error in names(x) <- do.call(paste0, as.list(new.names)) :
'names' attribute [6] must be the same length as the vector [1]

I can read multiple files using the same procedure with a small subset of these same files. Therefore, I assume that some of the .csv files that I provide must be incorrect, but currently is not possible to know which one is wrong without going back to the .csv files one by one. Is it possible to add that information to the error message?

Thanks!

Turn

Hi,
I downloaded your package and as I was going through it using your example data I came across this error:

Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'turn' of mode 'function' was not found

I have installed all the mentioned packages with the library function, and followed every single step you posted, also tried doing it all with my data but it still shows the same error, could you help me?

Thank you!
Ari

Trackr automatically compile information from different trials

The package is automatically combining data from different trials into one trial. I have realized that the way that I have named the files is causing this problem. For instance, I have several individuals from the same treatment which I have named XXXX1.1.csv; XXXX1.2.csv; XXXX1.3.csv, and the tracks from these individuals are then combined in the data as only one track. I have renamed the files using a numerical sequence and this problem disappear.

I attach an example with 9 files that get combined into only 6 tracks using the following code:

files<-list.files(startingDir, pattern="csv")
dat <- read_Ctrax(files, type = 'fixed')
tr <- as_tracks(dat, frame_rate = 30)
plot(tr)

tracktest.zip

Thanks!

Trial names may be bugged.

In some cases it appears that reading in single files or many files gives different outputs for some trials. Might be related only to plotting. Check Simons email.

Optimize collapse_identities.

For a large number of trials, with many mistakes, this function takes a long time. Have a look at data.table::foverlaps.

add_defaults_to_dots needs improvement

It should recognize when .dots are not function calls, and ideally should also fill in defaults for more complex expressions than single function calls.

summarize should check for existing columns?

d <- read_Ctrax(file = 'C:/Users/Wouter/Desktop/simon_test.csv')
d <- as_tracks(d, 30, '1080')
d <- mutate_(d, sp = speed())
d <- summarize(d, m = mean(sp, na.rm = TRUE))
d <- summarize(d, m = mean(sp, na.rm = TRUE))
d$trial

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.