Open Thejaswinisuso1 opened 1 year ago
Hi @Thejaswinisuso1, If you want to quantify:
# first, we can create a zt variable (i.e. t modulus one day)
dt[, zt := t %% behavr::hours(24)]
# then we compute the mean sleep in this interval, for each individual
dt[zt %between% behavr::hours(c(4, 8)) , .(siesta = mean(asleep)), by=key(dt)]
Note, you get siesta as a number between 0 and 1 , which is the proportion of time slept withing your selected time range (you can multiply that by 4h depending on how you want to express things)... Does it make sense? Regarding plotting, the easiest is to just show the time window you want from a larger plot:
pl <- ggetho(dt, aes(y = asleep), time_wrap = hours(24)) +
stat_pop_etho() +
coord_cartesian(xlim= hours(c(4,8)))
dt_curated[, zt := t %% behavr::hours(24)]
dt[zt %in% behavr::hours(c(4, 8)) , .(siesta = mean(asleep)), by=key(dt)]
pl <- ggetho(dt, aes(y = asleep), time_wrap = hours(24)) + stat_pop_etho() + coord_cartesian(xlim= hours(c(4,8)))
summary_dt <-
rejoin(dt_curated[xmv(genotype) %in% c(var.1) &
t %between% c(days(7),days(9)) ,
.(
sleep_fraction_siesta = mean(asleep)),
,by=id])
summary_dt
summary_dt_melted <- melt(summary_dt, measure.vars = patterns("sleepfraction"), variable.name = "phase", value.name = "sle ep_fraction")
ggplot(summary_dt_melted, aes(x=phase, y=sleep_fraction, fi ll=genotype)) + geom_boxplot(outlier.colour = NA) + scale_y_continuous(name= "Fraction of time sleeping",labels = scales::percent)
I rewrote it like this, but what I am getting is sleep during the whole day( averaging full day sleep= day time sleep+ Night time sleep), not sleep during ZT4-ZT8, which should be around 90% in my case. I have attached the images for your reference.
oops, i edited my code to use %between%
instead of %in%
. otherwise, your last plot does not apply coord_cartesian(xlim= hours(c(4,8)))
I am unsure i understand
var.1<-"CS"
###############################################################################################################################################################
DATA_DIR <- "/Users/thejaswinisusobhanan/Documents/Rethomics/Monitor 05:08:2022"
list.files(DATA_DIR, pattern= ".txt|.csv") setwd(DATA_DIR)
###############################################################################################################################################################
metadata <- fread("metadata1.csv")
metadata <- link_dam_metadata(metadata, result_dir = DATA_DIR)
metadata
###############################################################################################################################################################
dt <- load_dam(metadata) summary(dt)
###############################################################################################################################################################
dt <- load_dam(metadata, FUN = sleepr::sleep_dam_annotation)
ggetho(dt, aes(z=asleep)) + stat_ld_annotations(height = 1)+ stat_tile_etho()
ggetho(dt, aes(y=asleep)) + stat_pop_etho() + stat_ld_annotations()
ggetho(dt, aes(z=asleep), summary_time_window = mins(2)) + stat_ld_annotations(height = 1)+ stat_tile_etho()
ggetho(dt, aes(y=asleep), summary_time_window = mins(2)) + stat_pop_etho() + stat_ld_annotations()
###############################################################################################################################################################
dt_curated <- curate_dead_animals(dt) summary(dt_curated)
setdiff(dt[, id, meta=T], dt_curated[, id, meta=T])
###############################################################################################################################################################
ggetho(dt_curated, aes(z=asleep)) + stat_ld_annotations(height = 1)+ stat_tile_etho()
ggetho(dt_curated, aes(y=asleep)) + stat_pop_etho() + stat_ld_annotations()
ggetho(dt_curated[xmv(genotype) %in% c(var.1) & t %between% c(days(08),days(10) ) ], aes(y=asleep, colour=genotype)) + stat_pop_etho() + stat_ld_annotations(period = hours(24), l_duration = hours(12))
ggetho(dt_curated[xmv(genotype) %in% c(var.1) & t %between% c(days(08),days(10)) ], aes(y=asleep, colour=genotype), time_wrap = hours(24)) + stat_pop_etho() + stat_ld_annotations(period = hours(24), l_duration = hours(12)) + scale_y_continuous(name= "Fraction of time sleeping",labels = scales::percent)
###############################################################################################################################################################
dt_curated[, phase := ifelse(t %% hours(24) < hours(12), "L", "D")]
summary_dt <-
rejoin(dt_curated[xmv(genotype) %in% c(var.1) &
t %between% c(days(08),days(10)) ,
.(
sleep_fraction_all = mean(asleep),
sleep_fraction_l = mean(asleep[phase == "L"]),
sleep_fraction_d = mean(asleep[phase == "D"])
),
,by=id])
summary_dt
summary_dt_melted <- melt(summary_dt, measure.vars = patterns("sleepfraction"), variable.name = "phase", value.name = "sleep_fraction")
ggplot(summary_dt_melted, aes(x=phase, y=sleep_fraction, fill=genotype)) + geom_boxplot(outlier.colour = NA) + scale_y_continuous(name= "Fraction of time sleeping",labels = scales::percent)
summary_dt <-
rejoin(dt_curated[xmv(genotype) %in% c(var.1) &
t %between% c(days(7),days(9)) ,
.(
sleep_fraction_all = mean(asleep),
sleep_fraction_l = mean(asleep[phase == "L"]),
sleep_fraction_d = mean(asleep[phase == "D"])
),
,by=id])
summary_dt
dt_curated[, zt := t %% behavr::hours(24)]
dt[zt %between% behavr::hours(c(4, 8)) , .(siesta = mean(asleep)), by=key(dt)]
pl <- ggetho(dt, aes(y = asleep), time_wrap = hours(24)) + stat_pop_etho() + coord_cartesian(xlim= hours(c(4,8)))
summary_dt <-
rejoin(dt_curated[xmv(genotype) %in% c(var.1) &
t %between% c(days(7),days(9)) ,
.(sleep_fraction_siesta = mean(asleep)),
,by=id])
summary_dt
summary_dt_melted <- melt(summary_dt, measure.vars = patterns("sleepfraction"), variable.name = "phase", value.name = "sleep_fraction")
ggplot(summary_dt_melted, aes(x=phase, y=sleep_fraction, fill=genotype)) + geom_boxplot(outlier.colour = NA) + scale_y_continuous(name= "Fraction of time sleeping",labels = scales::percent)
Hello. I was trying to plot siesta (daytime sleep) only from ZT4-ZT8 (the peaking time points). But using rethomics, we can only plot from ZT0-ZT12 since they sum all day of sleep for a single channel. So can you help me to write a script using which I can quantify sleep during ZT4-ZT8? I appreciate any help you can provide. Theja