rethomics / sleepr Goto Github PK
View Code? Open in Web Editor NEWAnalyse sleep from movement (e.g. in Drosophila)
Home Page: http://rethomics.github.io
Analyse sleep from movement (e.g. in Drosophila)
Home Page: http://rethomics.github.io
dt <- toy_dam_data()
sleep_dam_annotation(dt) ## OK
dt[, sleep_dam_annotation(.SD), by=id] ## FAILS
Error in `[.data.table`(data, , .(t = t, moving = activity > 0), by = key(data)) :
by=c(...), key(...) or names(...) must evaluate to 'character'
This contrast with boot_analysis that does work regardless
we need a function to remove artefactual data after an animal has died
For variables such as moving
, asleep
,... we can save a lot of ram using bits instead of logical:
See https://cran.r-project.org/web/packages/bit/index.html
Dear Gilestro lab
Thank you for developing sleepr and making it publicly available for free. It’s great!
I had a question regarding your max_velocity_detector annotation function, which you use in sleep_annotation to determine the level of activity of a fly in time_window_length
seconds.
The logic you implement consists of retrieving the distance computed live on the ethoscopes, and you then divide by the time passed since the previous frame. This time difference is expressed in the dt
column, which you compute in the beginning of the function
Line 44 in 59949e3
Line 47 in 59949e3
Line 74 in 59949e3
Which according to the supplementary material in your PLOS One article https://journals.plos.org/plosbiology/article/file?id=10.1371/journal.pbio.2003026.s005&type=supplementary is designed to correct for the problem
that resulting velocity computation depended on the frame rate of the processed video
i.e. you correct the velocity taking into account the FPS.
However, by having a close look to the code, I would argue that what you effectively do is instead getting the distance again and then normalizing with a. The result of this operation is called velocity_corrected
, but it is basically a distance normalized by a. You then select the maximum value in time_window_length
and if the maximum is bigger than 1 i.e. the original distance dist
is greater than a, the fly is annotated as moving for that block of time, and not moving otherwise.
Wouldn’t it be more correct to omit line 74 and just check if the velocity is greater than a? Or maybe divide again by dt (and not multiply). Under my reasoning, the fact that the velocity is multiplied with dt does not only not correct the velocity but also makes the time between frames irrelevant because it takes the magnitudes to the distance space, and not the velocity space.
This question is related to issue gilestrolab/ethoscope#97 in the ethoscope repository. We are trying to find what is the problem and misannotation could be one of the culprits.
Once again, thank you very much!
Best,
Antonio
a = "a"
b = "b"
dt <- data.table(t = c(1:5,10:15),
y = c(a,a,a,b,a,b,a,a,a,b,b))
dt
bdt <- bout_analysis(y, dt)
expected <- rbind(
data.table( y=a,
t=c(1,5,8),
duration=c(3,5,3)),
data.table( y=b,
t=c(4,7,11),
duration=c(1,1,2))
)[,.SD, keyby=t]
bdt <- bdt[, .(t,y,duration)][,.SD, keyby=t]
results are shifted. Here, we get a bout of "b" lasting 5. It would make sense to roll forward, not backward so we have a bout of "a" lasting 5, starting at t=5
dt
t y
1: 1 a
2: 2 a
3: 3 a
4: 4 b
5: 5 a
6: 10 b
7: 11 a
8: 12 a
9: 13 a
10: 14 b
11: 15 b
> bdt
t y duration
1: 1 a 2
2: 3 b 1
3: 4 a 1
4: 5 b 5
5: 10 a 3
6: 13 b 2
seq.default(from = d_small[1, t], to = d_small[.N, t], by = time_window_length) :
'to' must be of length 1
Seems like d_small[.N, t]
could return a vector of length != 1...?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.