setwd("R_WGCNA/Demo_Yu2021NatPlant")
library(WGCNA)
library(DESeq2)
# The following setting is important, do not omit.
options(stringsAsFactors = FALSE);
#===============================================================================
#
# Download the files
#
#==============================================================================
# Step 1: Download files from https://github.com/PengYuMaize/Yu2021NaturePlants
# Rename the sample ID in the "gene_counts_table" and "sample_info" files, so that they look alike
# Rename for the sample ID start with "787_" and "78371A_"
# or you may just download my modified "gene_counts_table_WGCNA_LC.txt" for smooth tutorial experience
#===============================================================================
#
# Read the gene counts table and plot the sample tree
#
#===============================================================================
#setwd("~/Yupeng")
# Read the gene counts table
data0=read.table("gene_counts_table_WGCNA_LC.txt",header=T,row.names=1,sep="\t")
# Normalization with log2(FPKM+1)
sample_metadata = read.csv(file = "sample_info.csv")
dataExpr_deseq <- DESeqDataSetFromMatrix(countData = data0[,-181],colData = sample_metadata,design = ~ Zone)
mcols(dataExpr_deseq)$basepairs = data0$geneLengt1
fpkm_matrix = fpkm(dataExpr_deseq)
datExpr = t(log2(fpkm_matrix+1))
head(datExpr[1:5,1:5]) # samples in row, genes in column
match(sample_metadata$sample_ID, colnames(data0))
datExpr <- datExpr[,1:5000]
# Calculate sample distance and cluster the samples
sampleTree = hclust(dist(datExpr), method = "average");
# plot sample tree
pdf(file = "1-n-sampleClustering.pdf", width = 40, height = 9);
par(cex = 1.3);
par(mar = c(0,4,2,0))
plot(sampleTree, main = "Sample clustering to detect outliers", sub="", xlab="",
cex.lab = 1.5,cex.axis = 1.5, cex.main = 2)
dev.off()
#===============================================================================
#
# Choose soft threshold parameter
#
#===============================================================================
# Choose a set of soft threshold parameters
powers = c(c(1:20), seq(from = 22, to=30, by=2))
sft = pickSoftThreshold(datExpr, powerVector = powers, verbose = 5)
did you try loading
library(WGCNA)
before running the function ? Post your code relevant to your query always.library(WGCNA) has already been loaded...still i am getting this error
Are you sure
library(WGCNA)
did not produce any error ?Error: package or namespace load failed for ‘WGCNA’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called ‘impute’
i am getting this error while loading WGCNA
Install impute and you should be fine