Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageruby
titleScript R Merge CSV files and plot all data
collapsetrue
#Select the Input and the Output folder
Input <- "/Users/nicolas/Desktop/Input_Results-1/"
Output<-"/Users/nicolas/Desktop/Output/"
require("ggpubr")
#Get the list of CSV files
FileList<-list.files(path=Input, full.names=TRUE, pattern=".*csv")

#Merge the file into one big data
for (FileI in 1:length(FileList)){
  data<-read.csv(FileList[FileI])
  if (FileI==1){
    BigData<-data
  }else{
    BigData<-rbind(BigData,data)
  }
  
}
# then the rest is the same than the previous script
data<-BigData

List<-strsplit(as.character(data$Label), ':')

#Add Filename and Group to the data
data$Filename<-as.factor(sapply(List, "[[", 1))
Group<-strsplit(as.character(data$Filename), '_')
data$Group<-as.factor(sapply(Group, "[[", 1))
# Make Ch as a factor
data$Ch<-as.factor(data$Ch)

write.csv(data, paste0(Output,"ParticulesDetected-Cells_All -Measurements.csv"), row.names = FALSE)

#Create a list of plots
ListofPlots<-list()
i=1;

for(ColI in 3:(ncol(data)-2)){
  if(!is.factor(data[[ColI]])){
    for (ChI in 1:nlevels(data$Ch)){
   Graph<-   ggboxplot(
        data[data$Ch==ChI,], x = "Group", y = colnames(data[ColI]),
        color = "Group", palette = c("#4194fa", "#db51d4"),
        add = "jitter", title=paste0(colnames(data[ColI])," of Channel ", ChI)
      )+stat_compare_means(method = "t.test")
   ListofPlots[[i]]<-Graph
i=i+1
  }
  }
}

#Export the graphs
ggexport(
  plotlist = ListofPlots, filename = paste0(Output,"Graphs_individual.pdf"), 
  verbose=TRUE
)

...

This script will save the merged data in a single csv file. Usign your favourite spreadsheet manager you will be able to create a table and summarize the data with a pivot table to get the number of cells per group.


ControlTest
12251360

There are slighly more cells in the test than in the control. If we look at the number of detected cells per image we can confirm that there are more cells in the test conditions than in the control conditions. There are two images that have less celss than others in the control. We can go back to the detection to check those.

...

Looking at p-values (statistical significiance) only significance) is good approach but it is not enough. One We should also look at the biological sgnificiance significance of the numbers.For  For example the roundess is statiscially different between the control and test but this difference is really small. What does it mean biologically that the test cells are a tiny bit less circular. In this specific case : nothing much. So we can safely forget about it to focus on more important issuethings. 


This can easily be done since we have generated a CSV file gathering all the data Detected-Cells_All-Measurements.csv


Code Block
languageruby
titleR Script Create Graph with Descriptive Statistics
collapsetrue
# Prompt for the input CSV file from ImageJ measurements
Input<-file.choose()

# You must cange this path to match your computer
Output<-"/Users/nicolas/Desktop/Output/"

data<-read.csv(Input)

data$Ch<-as.factor(data$Ch)



require("ggpubr")
#Create a list of plots
ListofPlots<-list()
i=1;

for(ColI in 3:(ncol(data)-2)){
  if(is.numeric(data[[ColI]]) || is.integer(data[[ColI]])){
    for (ChI in 1:nlevels(data$Ch)){
      Graph<-ggsummarystats(
        data[data$Ch==ChI,], x = "Group", y=colnames(data[ColI]),
        ggfunc = ggviolin, digits = 2,
        color = "Group", palette = c("#4194fa", "#db51d4"),
        summaries=c("n", "mean","sd","ci"), add="mean_sd", title=paste0(colnames(data[ColI])," of Channel ", ChI))
      ListofPlots[[i]]<-Graph
      i=i+1
    }
  }
}

#Export the graphs
ggexport(
  plotlist = ListofPlots, filename = paste0(Output,"Graphs_Individual_Descriptive Stats.pdf"), 
  verbose=TRUE
)



Then for all the variables that are statically different between control and test groups we can have a closer look at the data.