Chapter 4 R Script Walkthrough
This section of the manual will provide an overview of the steps taken in the R script, starting with the inputs required for the script to function.
4.1 Necessary R Packages
Below are the packages required for the pipeline to run. Run the section below in R in order to install all necessary packages.
install.packages('tidyverse')
install.packages('readr')
install.packages('stringr')
install.packages('dplyr')
install.packages('rqdatatable')
install.packages('rlist')
install.packages('ggplot2')
install.packages('gridExtra')
install.packages('ggsignif')
install.packages('ggpubr')
install.packages('paletteer')
install.packages('plyr')
install.packages('knitr')
install.packages('data.table')
install.packages('plotly')
install.packages('clinUtils')
install.packages('rlist')
install.packages('rmdformats')
4.2 Input Parameters
Input the relevant parameters into the coloc_wrapper function of the R code. There is an example input file in the Github repository.
coloc_wrapper(image_directory="/Users/samboulger/Desktop/Manual Counts/",
results_directory="/Users/samboulger/Desktop/Manual Counts/",
metadata_directory='/Users/samboulger/Desktop/Data/',
CoMarker_directory='/Users/samboulger/OneDrive - Nexus365/Imperial/CoMarker Script/',
DNA=TRUE,
ROI=TRUE,
number_marker=2,
reference_marker="Iba1",
marker1="CD68",
marker2='HLA-DR',
marker3='',
marker4='',
marker5='',
region_of_interest='Ab',
outcome='trem2_all',
remove_outliers=TRUE,
outliers_threshold='3.5')
Specify the image directory, results directory, metadata directory, the directory in which the CoMarker folder is stored, as well as whether there are DNA and ROI markers (TRUE or FALSE), the number of markers, the reference markers, colocalisation markers, region of interest, and the outcome (from the metadata). Leave blank any sections that are not required, such as any additional markers or region_of_interest if you selected to not have one.
It is important to ensure that ‘CoMarker_directory’ is set to the directory of the main folder on your device. The main folder must include the ‘Functions’ and ‘HTML Reports’ folders. This naming is crucial for the R script to run.
The wrapper function will either need to be sourced or ran before the function will operate.
4.3 Quality Control
The script has a built-in image-flagging section which identifies images containing extreme count outliers. The threshold for detecting outliers is to be specified by the user (to be inputted as the number of standard deviations from the mean), as well as whether to remove the flagged images from the analysis. A table of the detected images is presented in the output report. More often than not, images with flagged counts are of poor quality and should not be considered in the analysis.
4.4 HTML Output
Once the R script has finished running, a report named ‘CoMarker_Analysis_Report’ will be created in a report folder within the results directory. Open this report in the web browser and you will be able to easily visualise the analysis.
The report is separated into sections for each marker, as well as a section highlighting any significant results. By using the table of contents, the user can quickly skip to a desired section.
Box plots are created for pretty much every useful ROI-reference marker-colocalisation marker combination. On each box plot, statistical significance is annotated, such that:
ns = non-significant
* = p<0.05
** = p<0.01
*** = p<0.001
The report will be overwritten if the analysis is repeatedly performed on the same folder - renaming the report will prevent it from being deleted when a new one is produced.