Batch Adjustment

Load Packages

library(“ggplot2”) library(“gridExtra”) library(“edgeR”) library(“UpSetR”) library(“sva”)

sva::ComBat_seq

Set Directory

dir <- “~/Desktop/Feature-Counts/Unadjusted/”

Load Feature Counts (All Samples)

counts <-read.csv(paste0(dir, “counts-prunved-v1-no3months.csv”), sep=“,”, stringsAsFactors = F, header = T)

Save Feature Counts as Matrix

counts_matrix <- as.matrix(counts)

List Corresponding Sample Batch Number

batch_list <- c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5)

List Corresponding Sample Age

cov1_age <- c(9, 9, 9, 9, 12, 12, 12, 12, 12, 12, 15, 15, 15, 15, 15, 15, 18, 18, 18, 6, 6, 6, 6, 6, 6, 15, 15, 15, 15, 15, 15, 12, 12, 18, 18, 18, 18, 18, 18, 18, 18, 21, 21, 21, 21, 21, 9, 9, 6, 9, 24, 6, 9, 12, 21, 24, 6, 9, 12, 21, 24, 6, 12, 21, 9, 12, 21, 6, 9, 21, 9, 12, 21, 6, 18, 18, 9)

List Corresponding Sample Sex (F=2, M=3)

cov2_Sex <- c(2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2)

List Corresponding Sample Strain (AD=1, WT=0)

Cov3_Strain <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0)

Bind Sample Variables

covar_mat <- cbind(cov1_age, cov2_Sex, Cov3_Strain)

Format Counts for Combat Seq

head(counts_matrix)

dim(counts_matrix)

counts_no_names <- counts[,2:78]

count_matrix_mine <- as.matrix(counts_no_names)

Run ComBat Seq to Adjust Feature Counts

adjusted_counts <- ComBat_seq(count_matrix_mine, batch=batch_list, group=NULL, covar_mod=covar_mat)

write csv file for Complete Results

write.csv(as.data.frame(adjusted_counts), file = paste0(dir,“Adjusted-Counts-pruned-V1-Sex-Edit-no3months.csv”), quote = FALSE, row.names = T, col.names = T, sep = “,”)