Unverified Commit bd8d0002 authored by Maximilian von der Linde's avatar Maximilian von der Linde Committed by GitHub
Browse files

InfiniteWhite-patch-3.2

final version of the uploaded code, last update of patch 3, so that patch 3 can then be merged to the master branch.
Functionality of both data types have been succesfully tested.
parent 4ce3bd53
################### Plotting functions for DTS data ######################
######## Plot torque and position data for each period ########
trq_pos_traces <- function(temp)
{
##modify a_Pos to introduce gaps between -180 and 180
pos <- temp$a_pos
for(p in 2:nrow(temp))
{
if (abs(as.numeric(pos[p]))>1950 && sign(as.numeric(pos[p]))!=sign(as.numeric(pos[p-1]))) {pos[p-1]="NA"}
}
par(mar=c(5, 4, 4, 4) + 0.1)
traces <- plot(x = temp$time, y = temp$a_pos, type = "n", axes=FALSE, xaxs = "i", yaxs = "i", ylim=c(-2047,2048), ylab = "",xlab="")
#shade quadrants
rect(temp$time[1],-1538,temp$time[nrow(temp)],-512, col = "grey95")
rect(temp$time[1],512,temp$time[nrow(temp)],1538, col = "grey95")
par(new=TRUE)
plot(x = temp$time, y = pos, type = "l", col="red3", xaxs = "i", yaxs = "i", ylim=c(-2047,2048), ylab = "position[arb.units]",xlab="time [ms]")
par(new=TRUE)
plot(x = temp$time, temp$torque, type = "l", col="blue", xaxs = "i", ylim=c(-500,500), main = paste("Fly Traces", flyname, "Period", i), axes=F, xlab=NA, ylab="")
lines(c(temp$time[1],temp$time[nrow(temp)]),c(0,0),type="l",lty=1,lwd=1, col="black")
axis(4)
mtext("torque [arb_units]", side = 4, line = 3)
return(traces)
}
dytraces <- function(rawdata)
{
traces <- dygraph(rawdata, main = paste("Time Traces", flyname)) %>%
dySeries("a_pos", label = "position", color = "darkred") %>%
dySeries("torque", axis = 'y2', color = "blue") %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Position [arb_units]", valueRange = c(-2048,2048)) %>%
dyOptions(gridLineColor = "lightgrey") %>%
dyAxis("y2", label = "Torque [arb_units]", independentTicks = TRUE, valueRange = c(-700,700), drawGrid = FALSE) %>%
dyOptions(includeZero = TRUE) %>%
dyRangeSelector()
return(traces)
}
############ Function to plot several plots into a single plot #########
multiplot <- function(..., plotlist = NULL, file, cols = 1, layout = NULL)
{
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots == 1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
############ Function to annotate plots after stats #########
#Wilcoxon annotations
wilcox.annotate <- function(boxes, wilcoxon)
{
annotate("text",
x=boxes,
y=1.1,
label=paste("p=",wilcoxon[boxes]))
}
#samplesizes annotations
samplesizes.annotate <- function(boxes, samplesizes)
{
annotate("text",
x=boxes,
y=-1.1,
label=paste("N=", samplesizes[boxes]))
}
########### Function to calculate False Positive Risk
#======================================================
calc.FPR = function(samplesizes,pval,prior,delta1){
sdiff=sqrt(1/samplesizes[1] + 1/samplesizes[2])
df=samplesizes[1]+samplesizes[2]-2
# Note FPR doesn't need calculation of power for p-equals case
#
#under H0, use central t distribution
tcrit=qt((1-pval/2),df,ncp=0)
x0=tcrit
y0=dt(x0,df,0)
#
# under H1 use non-central t distribution
ncp1=delta1/sdiff #non-centrality paramater
x1=x0 #tcrit
y1=dt(x1,df,ncp=ncp1)
# Calc false positive risk
p0=2*y0
p1=y1
FPR=((1-prior)*p0)/(((1-prior)*p0) + prior*p1)
FPR
output=c(FPR,x0,y0,x1,y1)
return(output)
################### Plotting functions for DTS data ######################
######## Plot torque and position data for each period ########
trq_pos_traces <- function(temp)
{
##modify a_Pos to introduce gaps between -180 and 180
pos <- temp$a_pos
for(p in 2:nrow(temp))
{
if (abs(as.numeric(pos[p]))>1950 && sign(as.numeric(pos[p]))!=sign(as.numeric(pos[p-1]))) {pos[p-1]="NA"}
}
par(mar=c(5, 4, 4, 4) + 0.1)
traces <- plot(x = temp$time, y = temp$a_pos, type = "n", axes=FALSE, xaxs = "i", yaxs = "i", ylim=c(-2047,2048), ylab = "",xlab="")
#shade quadrants
rect(temp$time[1],-1538,temp$time[nrow(temp)],-512, col = "grey95")
rect(temp$time[1],512,temp$time[nrow(temp)],1538, col = "grey95")
par(new=TRUE)
plot(x = temp$time, y = pos, type = "l", col="red3", xaxs = "i", yaxs = "i", ylim=c(-2047,2048), ylab = "position[arb.units]",xlab="time [ms]")
par(new=TRUE)
plot(x = temp$time, temp$torque, type = "l", col="blue", xaxs = "i", ylim=c(-500,500), main = paste("Fly Traces", flyname, "Period", i), axes=F, xlab=NA, ylab="")
lines(c(temp$time[1],temp$time[nrow(temp)]),c(0,0),type="l",lty=1,lwd=1, col="black")
axis(4)
mtext("torque [arb_units]", side = 4, line = 3)
return(traces)
}
dytraces <- function(rawdata)
{
traces <- dygraph(rawdata, main = paste("Time Traces", flyname)) %>%
dySeries("a_pos", label = "position", color = "darkred") %>%
dySeries("torque", axis = 'y2', color = "blue") %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Position [arb_units]", valueRange = c(-2048,2048)) %>%
dyOptions(gridLineColor = "lightgrey") %>%
dyAxis("y2", label = "Torque [arb_units]", independentTicks = TRUE, valueRange = c(-700,700), drawGrid = FALSE) %>%
dyOptions(includeZero = TRUE) %>%
dyRangeSelector()
return(traces)
}
dytraces_platform <- function(rawdata)
{
traces <- dygraph(rawdata, main = paste("Time Traces", flyname)) %>%
dySeries("arena", label = "position", color = "darkred") %>%
dySeries("fly", axis = 'y2', color = "blue") %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", label = "Arena Position [arb_units]") %>%
dyOptions(gridLineColor = "lightgrey") %>%
dyAxis("y2", label = "Fly [arb_units]", independentTicks = TRUE, drawGrid = FALSE) %>%
dyOptions(includeZero = TRUE) %>%
dyRangeSelector()
return(traces)
}
############ Function to plot several plots into a single plot #########
multiplot <- function(..., plotlist = NULL, file, cols = 1, layout = NULL)
{
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots == 1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
#source: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
############ Function to annotate plots after stats #########
#Wilcoxon annotations
wilcox.annotate <- function(boxes, wilcoxon)
{
annotate("text",
x=boxes,
y=1.1,
label=paste("p=",wilcoxon[boxes]))
}
#samplesizes annotations
samplesizes.annotate <- function(boxes, samplesizes)
{
annotate("text",
x=boxes,
y=-1.1,
label=paste("N=", samplesizes[boxes]))
}
########### Function to calculate False Positive Risk
#======================================================
calc.FPR = function(samplesizes,pval,prior,delta1){
sdiff=sqrt(1/samplesizes[1] + 1/samplesizes[2])
df=samplesizes[1]+samplesizes[2]-2
# Note FPR doesn't need calculation of power for p-equals case
#
#under H0, use central t distribution
tcrit=qt((1-pval/2),df,ncp=0)
x0=tcrit
y0=dt(x0,df,0)
#
# under H1 use non-central t distribution
ncp1=delta1/sdiff #non-centrality paramater
x1=x0 #tcrit
y1=dt(x1,df,ncp=ncp1)
# Calc false positive risk
p0=2*y0
p1=y1
FPR=((1-prior)*p0)/(((1-prior)*p0) + prior*p1)
FPR
output=c(FPR,x0,y0,x1,y1)
return(output)
}
\ No newline at end of file
......@@ -43,20 +43,33 @@ grouped.poshistos <- list() #Position histograms for group in a list of length
grouped.flyhistos <- list()
grouped.flyhistosL <- list() #Platform position histograms for group in a list of length NofPeriods
grouped.flyhistosR <- list() #Platform position histograms for group in a list of length NofPeriods
grouped.flytraces <- list() #Platform position traces in a list of length NofGroups
grouped.PIprofiles <- list() #PIProfile data frames in a list of length NofGroups
grouped.periods <- list() #Period designs in a list of length NofGroups
grouped.spectra <- list() #Power spectra in a list of length NofGroups
#create empty list for individual fly names in each group for display in project evaluation
exp_groups <- list()
for(x in 1:NofGroups)
{
xml_list = paste(project.path, project.data[["resources"]][[x]][["data"]], sep = "/")
grp_title = project.data[["resources"]][[x]][["title"]] #collect title of the group
grp_description = project.data[["resources"]][[x]][["description"]] #collect description of the group
xml_list = paste(project.path, project.data[["resources"]][[x]][["data"]], sep = "/") #create list of file names
#create/empty lists for collecting all single fly data by period
period.data <- list() #data grouped by period
grouped.data <- list() #total data grouped
grouped.data.periodsL <- list() #total data grouped by left or right turning arena for platform
grouped.data.periodsR <- list()
grouped.data.tracesL <- list() #mean trace of left or right Periods
grouped.data.tracesR <- list()
grouped.data.flyL <- list()
grouped.data.flyR <- list()
speclist <- list()
#vectors for pooled platform period traces
flytracesL <- list()
flytracesR <- list()
#start evaluating
if(MultiFlyDataVerification(xml_list)==TRUE) # make sure all flies in a group have the identical experimental design
......@@ -87,15 +100,17 @@ if(MultiFlyDataVerification(xml_list)==TRUE) # make sure all flies in a group ha
#create/empty plot lists
poshistos <- list()
trqhistos <- list()
flyhistos <- list() #still needed?
flyhistos <- list()
flyhistosR <- list()
flyhistosL <- list()
#vectors for pooled platform periods
optomotoL_flydata <- c()
optomotoR_flydata <- c()
flyhistosL.rawdata <- list()
flyhistosR.rawdata <- list()
flytraces <- list()
#vectors for pooled platform period histograms
optomotoL_flydata <- list() #unused?
optomotoR_flydata <- list() #unused?
periodL <- data.frame() #these empty data frames are needed if no Platform data is used
periodR <- data.frame()
flytracesL_data_frame <- data.frame()
flytracesR_data_frame <- data.frame()
#### call RMarkdown for single fly evaluations ################################################
single_fly_path <- paste(start.wd, "single_fly.Rmd", sep = "/")
rmarkdown::render(single_fly_path,
......@@ -110,11 +125,15 @@ if(MultiFlyDataVerification(xml_list)==TRUE) # make sure all flies in a group ha
##add period data to grouped data
grouped.data[[l]] <- period.data
grouped.data.periodsL[[l]] <- list(periodL)
grouped.data.periodsL[[l]] <- list(periodL) #special lists for left and right p_opomtor periods
grouped.data.periodsR[[l]] <- list(periodR)
xml_list[[l]] = paste('<a href="',flyname,'_descr_anal.html">', flyname,'</a>', sep = '') #create link to each single fly evaluation HTML document to be used in project evaluation
} #for number of flies in xml_list
exp_groups[[x]] <- c(grp_title, grp_description, xml_list) #add name and description and file links to dataframe to be used in project evaluation document
########### plot graphs for all experiments #####################
##pool all data except "optomotor" by period
......@@ -164,11 +183,50 @@ if(MultiFlyDataVerification(xml_list)==TRUE) # make sure all flies in a group ha
}
## pool all torque/platform and position data into single data.frame
for (n in 1:length(grouped.data.periodsL)) {
grouped.data.flyL[[n]] <- grouped.data.periodsL[[n]][[1]]$fly
grouped.data.flyR[[n]] <- grouped.data.periodsR[[n]][[1]]$fly
}
## make final data frames for plotting
#for histogram with all fly data
all.data <- do.call(rbind, pooled.data)
if (sequence$type[1]=="OptomotoL"||sequence$type[1]=="OptomotoR") {
#for histogram with all fly data sorted by left turning arena
all.data.periodsL <- data.frame(unlist(grouped.data.flyL))
names(all.data.periodsL) <- "fly"
all.data <- do.call(rbind, pooled.data)
all.data.periodsL <- data.frame(grouped.data.periodsL[[l]])
all.data.periodsR <- data.frame(grouped.data.periodsR[[l]])
#for histogram with all fly data sorted by right turning arena
all.data.periodsR <- data.frame(unlist(grouped.data.flyR))
names(all.data.periodsR) <- "fly"
#for multiple traces graph with mean trace of each period in left/right
#fit "flytraces" list for the "data.frame()" function
flytracesL <- lapply(flytracesL, function(x) {
length(x) <- min(lengths(flytracesL)); x})
flytracesR <- lapply(flytracesR, function(x) {
length(x) <- min(lengths(flytracesR)); x})
#create data frame for pooled traces plot
fly <- unlist(flytracesL)
period <- rep(c(1:length(flytracesL)), each=length(flytracesL[[1]]))
time <- rep(seq(0, (length(flytracesL[[1]])-1)*10, by=10), times=length(flytracesL))
all.data.periodL <- data.frame(fly, period, time)
#create data frame for pooled traces plot
fly <- unlist(flytracesR)
period <- rep(c(1:length(flytracesR)), each=length(flytracesR[[1]]))
time <- rep(seq(0, (length(flytracesR[[1]])-1)*10, by=10), times=length(flytracesR))
all.data.periodR <- data.frame(fly, period, time)
#for mean traces graph of all left/right periods
all.data.flytracesL <- rowMeans(data.frame(flytracesL))
all.data.flytracesL <- data.frame(all.data.flytracesL, seq(0, (length(all.data.flytracesL)-1)*10, by=10))
names(all.data.flytracesL) <- c("fly", "time")
all.data.flytracesR <- rowMeans(data.frame(flytracesR))
all.data.flytracesR <- data.frame(all.data.flytracesR, seq(0, (length(all.data.flytracesR)-1)*10, by=10))
names(all.data.flytracesR) <- c("fly", "time")
}
## plot pooled histograms for all flies over all periods
if(sequence$type[1]=="fs"||sequence$type[1]=="color"||sequence$type[1]=="optomotor") {
......@@ -193,17 +251,42 @@ if(MultiFlyDataVerification(xml_list)==TRUE) # make sure all flies in a group ha
xlim(-5,2) +
ggtitle("Pooled P_Pos Histogram")
flyhistos[[NofPeriods+2]] <- ggplot(data=all.data.periodsL, aes_string(all.data.periodsL$optomotoL_flydata)) +
flyhistos[[NofPeriods+2]] <- ggplot(data=all.data.periodsL, aes_string(all.data.periodsL$fly)) +
geom_histogram(binwidth=0.0175) +
labs(x="fly [arb units]", y="frequency") +
xlim(-5,2) +
ggtitle("Pooled P_Pos Histogram\n(left turning arena)")
flyhistos[[NofPeriods+3]] <- ggplot(data=all.data.periodsR, aes_string(all.data.periodsR$optomotoR_flydata)) +
flyhistos[[NofPeriods+3]] <- ggplot(data=all.data.periodsR, aes_string(all.data.periodsR$fly)) +
geom_histogram(binwidth=0.0175) +
labs(x="fly [arb units]", y="frequency") +
xlim(-5,2) +
ggtitle("Pooled P_Pos Histogram\n(right turning arena)")
flytraces[[1]] <- ggplot(data=all.data.periodL, aes_string(y = all.data.periodL$fly, x = all.data.periodL$time, colour = all.data.periodL$period)) +
geom_line(aes_string(group = all.data.periodL$period)) +
scale_color_gradientn(colours=rainbow(4)) +
geom_smooth() +
labs(x="time (ms)", y="fly") +
ggtitle("Multi Traces\n(left turning arena)")
flytraces[[2]] <- ggplot(data=all.data.periodR, aes_string(y = all.data.periodR$fly, x = all.data.periodR$time, colour = all.data.periodR$period)) +
geom_line(aes_string(group = all.data.periodR$period)) +
scale_color_gradientn(colours=rainbow(4)) +
geom_smooth() +
labs(x="time (ms)", y="fly") +
ggtitle("Multi Traces\n(right turning arena)")
flytraces[[3]] <- ggplot(data=all.data.flytracesL, aes_string(x=all.data.flytracesL$time, y=all.data.flytracesL$fly)) +
geom_line() +
ggtitle("Pooled traces\n(left turning arena)") +
labs(x="time(ms)", y="fly")
flytraces[[4]] <- ggplot(data=all.data.flytracesR, aes_string(x=all.data.flytracesR$time, y=all.data.flytracesR$fly)) +
geom_line() +
ggtitle("Pooled traces\n(right turning arena)") +
labs(x="time(ms)", y="fly")
}
} else {print("You have selected files with differing metadata")}
......@@ -220,11 +303,8 @@ trqhistos <- list() #empty torque histograms
#Platform Histograms
grouped.flyhistos[[x]] = flyhistos #add platform histograms to list of grouped p_position histograms
flyhistos <- list() #empty list of p_position histograms
# grouped.flyhistosL[[x]] = flyhistosL #add platform histograms to list of grouped p_position histograms for left turning arena
# flyhistosL <- list()
# grouped.flyhistosR[[x]] = flyhistosR #add platform histograms to list of grouped p_position histograms for right turning arena
# flyhistosR <- list()
grouped.flytraces[[x]] <- flytraces #add platform traces to list of grouped p_position traces
flytraces <- list() #empty list of p_position traces
#Position Histograms
grouped.poshistos[[x]] = poshistos #add torque histograms to list of grouped position histograms
......
......@@ -30,7 +30,7 @@ source("readXMLdatafile.R")
source("DTS_plotfunctions.R")
```
<center><h1><i>Drosophila</i> Time Series Project Data Evaluation Sheet</h1></center>
<center><h1><i>Drosophila</i> Time Series Project Evaluation Sheet</h1></center>
<center><h2>for time series data set: "<b>`r paste(project.data$title)`</b>"</h2></center>
### 1. Metadata:
......@@ -55,7 +55,19 @@ type_no_platform <- isFALSE(sequence$type[1] == "OptomotoL" | sequence$type[1] =
type_is_platform <- isTRUE(sequence$type[1] == "OptomotoL" | sequence$type[1] == "OptomotoR")
```
### 3. Torque Histograms:
### 3. Experimental groups and single fly evaluations:
**Number of experimental groups:** `r paste(NofGroups)`
```{r singleflydata, eval=TRUE, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE}
exp_groups <- as.data.frame(t(plyr::ldply(exp_groups, rbind))) #make dataframe from list
colnames(exp_groups) <- as.character(unlist(exp_groups[1,])) # make group names to column names
#tidy the dataframe up a little
exp_groups = exp_groups[-1,]
rownames(exp_groups) <- NULL
kable(exp_groups) #plot table with links to individual fly evaluations
```
### 4. Torque Histograms:
```{r TorqueHistograms, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 12, fig.width = 8, comment=NA, results='asis'}
for(x in 1:NofGroups)
......@@ -66,7 +78,7 @@ type_is_platform <- isTRUE(sequence$type[1] == "OptomotoL" | sequence$type[1] ==
}
```
### 3. Platform Histograms:
### 4. Platform Histograms and Pooled Traces:
```{r PlatformHistogram, eval=type_is_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 12, fig.width = 8, comment=NA, results='asis'}
for(x in 1:NofGroups)
......@@ -74,18 +86,13 @@ type_is_platform <- isTRUE(sequence$type[1] == "OptomotoL" | sequence$type[1] ==
cat("<center><h4>",project.data[["resources"]][[x]][["title"]],"</h4></center>")
flyhistos <- grouped.flyhistos[[x]]
multiplot(plotlist = flyhistos, cols=4)
#
# cat("<center><h4>",project.data[["resources"]][[x]][["title"]],"</h4></center>")
# flyhistosL <- grouped.flyhistosL[[x]]
# multiplot(plotlist = flyhistosL, cols=4)
#
# cat("<center><h4>",project.data[["resources"]][[x]][["title"]],"</h4></center>")
# flyhistosR <- grouped.flyhistosR[[x]]
# multiplot(plotlist = flyhistosR, cols=4)
flytraces <- grouped.flytraces[[x]]
multiplot(plotlist = flytraces, cols = 2)
}
```
### 4. Position Histograms:
### 5. Position Histograms:
```{r PositionHistogram, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 12, fig.width = 8, comment=NA, results='asis'}
for(x in 1:NofGroups)
......@@ -96,7 +103,7 @@ type_is_platform <- isTRUE(sequence$type[1] == "OptomotoL" | sequence$type[1] ==
}
```
### 5. Fourier Spectrum Analysis
### 6. Fourier Spectrum Analysis
```{r spectra, eval=TRUE, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 6, fig.width = 8}
spectemp <- do.call("rbind", grouped.spectra) #create single data.frame with grouping variable from list of groups
......@@ -124,7 +131,7 @@ print(ggplot(spectemp, aes(x=freq, y=mean, group = group)) +
```
### 6. Performance Index bar plot with SEM:
### 7. Performance Index bar plot with SEM:
```{r PIbar, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 8, fig.width = 8}
PIplots <- list()
......@@ -156,7 +163,7 @@ for(x in 1:NofGroups)
grid.arrange(grobs = PIplots, nrow=NofGroups)
```
### 7. Performance Index box&dotplot with notches:
### 8. Performance Index box&dotplot with notches:
```{r BoxWithNotch, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 8, fig.width = 8}
for(x in 1:NofGroups)
......@@ -174,7 +181,7 @@ for(x in 1:NofGroups)
grid.arrange(grobs = PIplots, nrow=NofGroups)
```
### 8. Performance Index box&dotplot without notches:
### 9. Performance Index box&dotplot without notches:
```{r BoxNoNotch, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 8, fig.width = 8}
for(x in 1:NofGroups)
......@@ -192,7 +199,7 @@ for(x in 1:NofGroups)
grid.arrange(grobs = PIplots, nrow=NofGroups)
```
### 9. Performance Index Violin Plot:
### 10. Performance Index Violin Plot:
```{r Violin, eval=type_no_platform, echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 8, fig.width = 8}
for(x in 1:NofGroups)
......@@ -237,7 +244,7 @@ wil <- isTRUE(project.data[["statistics"]][["single.groups"]][["data"]]==1) ###d
```
```{r Wilcoxon, eval=(wil & type_no_platform), echo=FALSE, error=FALSE, message=FALSE, warning=FALSE, fig.align = "center", fig.height = 6, fig.width = 8, comment=NA, results='asis'}
cat("### 10. Statistical Tests of single groups against zero:")
cat("### 11. Statistical Tests of single groups against zero:")
wilcoxon<-numeric()
for(x in 1:NofGroups){wilcoxon[x] = signif(wilcox.test(PIstat[[x]])$p.value, 3)} #test all groups against zero
......@@ -273,7 +280,7 @@ two <- isTRUE(project.data[["statistics"]][["two.groups"]][["data"]]==1 || NofGr
```
```{r Utest, eval=(two & type_no_platform), echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, fig.align = "center", fig.height = 6, fig.width = 8, comment=NA, results='asis'}
cat("### 11. Statistical Tests between two groups:")
cat("### 12. Statistical Tests between two groups:")
utest = signif(wilcox.test(PIstat[[1]],PIstat[[2]])$p.value, 3) #compare the two groups with a U-test and collect p-value
w.statistic = signif(wilcox.test(PIstat[[1]],PIstat[[2]])$statistic, 3)
......
......@@ -49,7 +49,6 @@ source("DTS_plotfunctions.R")
#check if number of periods in metadata is true
if (ncol(periods) != NofPeriods) {
NofPeriods = ncol(periods)
print("sequence$type metadata faulty, function will still be working correctly")
}
colnames(periods)<-sprintf("Period %s",1:NofPeriods)
......@@ -88,7 +87,7 @@ source("DTS_plotfunctions.R")
temp <- rawdata[rawdata$period == i, ]
if (sequence$type[i] == "OptomotoL" || sequence$type[i] == "OptomotoR") {
keeps = c("a_pos","fly")
keeps = c("arena","fly")
} else {
keeps = c("a_pos","torque")
}
......@@ -109,7 +108,8 @@ source("DTS_plotfunctions.R")
labs(x="fly [arb units]", y="frequency") +
xlim(-3.2, 0) +
ggtitle(paste(flyname, "Period", i, "OptomotoR"))
optomotoR_flydata <- c(optomotoR_flydata, period.data[[i]]["fly"], recursive = TRUE, use.names = FALSE)
#for later histograms of pooled periods
optomotoR_flydata[countR] <- c(period.data[[i]]["fly"])
countR = countR+1
} else if (sequence$type[i] == "OptomotoL") {
flyhistosL[[countL]] <- ggplot(data=temp, aes_string(temp$fly)) +
......@@ -117,7 +117,7 @@ source("DTS_plotfunctions.R")
labs(x="fly [arb units]", y="frequency") +
xlim(-3.2, 0) +
ggtitle(paste(flyname, "Period", i, "OptomotoL"))
optomotoL_flydata <- c(optomotoL_flydata, period.data[[i]]["fly"], recursive = TRUE, use.names = FALSE)
optomotoL_flydata[countL] <- c(period.data[[i]]["fly"])
countL = countL+1