aboutsummaryrefslogtreecommitdiff
path: root/scripts/wgcna_analysis.R
blob: 8e90d7df5d308b8a79d51eafc6a1d4ccbec1a54e (plain)
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
# initial workspace setup

library(WGCNA);
stringsAsFactors = FALSE

# load expression data **assumes csv format row(traits)(columns info+samples)


wgcnaRawData <- read.csv(file = "wgcna_data.csv")

# transform expressionData

dataExpr <- as.data.frame(t(wgcnaRawData));



# data cleaning

# adopted from docs
gsg = goodSamplesGenes(dataExpr, verbose = 3);



if (!gsg$allOK)
{
# Optionally, print the gene and sample names that were removed:
if (sum(!gsg$goodGenes)>0)
printFlush(paste("Removing genes:", paste(names(datExpr0)[!gsg$goodGenes], collapse = ", ")));
if (sum(!gsg$goodSamples)>0)
printFlush(paste("Removing samples:", paste(rownames(datExpr0)[!gsg$goodSamples], collapse = ", ")));
# Remove the offending genes and samples from the data:
dataExpr <- dataExpr[gsg$goodSamples, gsg$goodGenes]
}