-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComBatNorm.R
47 lines (32 loc) · 1.22 KB
/
ComBatNorm.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("sva")
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("bladderbatch")
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("snpStats")
library("sva")
library(devtools)
library(Biobase)
library(sva)
library(bladderbatch)
library(snpStats)
install.packages(c("devtools"))
---------------------------------------------------------
CombatNorm=read.csv("CombatNorm-Corrected.csv")
batch=read.csv("batch.csv")
# Check for missing values in batch$x
missing_values <- sum(is.na(batch$x))
# If there are missing values, remove them
if (missing_values > 0) {
batch <- na.omit(batch)
}
# Convert batch$x to a factor with two levels
batch$x <- factor(batch$x, levels = c(1, 2))
# Check the structure of batch$x after conversion
str(batch$x)
# Use ComBat after handling missing values
combat_data <- ComBat(dat = CombatNorm[,2:943], batch = batch$x)
write.csv(combat_data, file="C:/Users/Mona/Desktop/Stanford/Nima/Cord Blood Metabolomics Analysis/sva Normalization/combat_data.csv", row.names = TRUE)