Error in "Relating the consensus modules to female set-specific modules"
1
0
Entering edit mode
@bahmanikmsuedu-23146
Last seen 3.5 years ago
Michigan State University

Hi, I'm new in WGCNA, and trying to learn. I'm using the second tutorial (female vs male), but in the third section of the tutorial (Relating the consensus modules to female set-specific modules) when I try to execute all pairwaise comparisons using the code chunk 4:

for (fmod in 1:nFemMods) for (cmod in 1:nConsMods) { femMembers = (femaleColors == femModules[fmod]); consMembers = (moduleColors == consModules[cmod]); pTable[fmod, cmod] = -log10(fisher.test(femMembers, consMembers, alternative = "greater")$p.value); CountTbl[fmod, cmod] = sum(femaleColors == femModules[fmod] & moduleColors == consModules[cmod]) }

I get an error saying that in fisher test, x and y should be same length. I don't know why I am getting this error, and after trying different things, the only reason that comes to my mind is maybe because gsg function removed different number of genes from my female and male groups (58 genes removed from female data, but 17 genes removed from male data). Can this be a reason for the error? If yes, what do I need to do about it? If not, what might be the reason? Thanks for any help/advice,

WGCNA • 1.0k views
ADD COMMENT
2
Entering edit mode
@peter-langfelder-4469
Last seen 20 hours ago
United States

You need to restrict the femaleColors and moduleColors to the same genes. Something like (I haven't tested the code so try to understand it and make it work if I wrote a typo):

load(file = "FemaleLiver-01-dataInput.RData")

femGenes = colnames(datExpr)
consGenes = mtd.colnames(multiExpr)
common = intersect(femGenes, consGenes)
femaleColors.common = femaleColors[match(common, femGenes)];
moduleColors.common = moduleColors[match(common, consGenes)];

then run the overlap code with femaleColors.common and moduleColors.common instead of femaleColors and moduleColors.

ADD COMMENT
0
Entering edit mode

It worked. Thank you very much

ADD REPLY
0
Entering edit mode

Hi, I am also new to WGCNA. I am also getting the same error i.e. "Error in fisher.test(femMembers, consMembers, alternative = "greater") : 'x' and 'y' must have at least 2 levels". I tried the above solution but it could not solve the error as my femaleColors and moduleColors have same number of genes, if this was creating issue. The script says

for (fmod in 1:nFemMods) for (cmod in 1:nConsMods) { femMembers = (femaleColors.common == femModuleLabels[fmod]); consMembers = (moduleColors.common == consModules[cmod]); pTable[fmod, cmod] = -log10(fisher.test(femMembers, consMembers, alternative = "greater")$p.value); CountTbl[fmod, cmod] = sum(femaleColors.common == femModules[fmod] & moduleColors.common == consModules[cmod]) }

femMembers and consMembers in my case are logicals having TRUE and FALSE. Is it okay? How can fisher.test be applied on logicals?

Please help. Thanks in advance.

ADD REPLY
0
Entering edit mode

I am having the same error as in the first post. I applied the code from Peter and after running the code I get:

Error in fisher.test(femMembers, consMembers, alternative = "greater") : 
  'x' and 'y' must have at least 2 levels

In my case femMembers and conMembers are logicals but empty....

EDIT: I solved the problem, maybe it will be useful for someone else - my error was because of loading not the right file! I forgot to load the Input data first.

Here is my code corrected:

lnames = load("/Users/annamariabugaj/Desktop/BIG_WGCNA/42_HPC-02-networkConstruction-auto.RData")
lnames

# To avoid this error: Error in fisher.test(femMembers, consMembers, alternative = "greater") : 
# 'x' and 'y' must have the same length
#run the code below:

load(file = "/Users/annamariabugaj/Desktop/BIG_WGCNA/42_HPC-01-dataInput.RData")

femGenes = colnames(datExpr)
consGenes = mtd.colnames(multiExpr)
common = intersect(femGenes, consGenes)
femaleColors.common = femaleColors[match(common, femGenes)];
moduleColors.common = moduleColors[match(common, consGenes)];

# Rename variables to avoid conflicts
femaleLabels = moduleLabels;
femaleColors = moduleColors;
femaleTree = geneTree;
femaleMEs = orderMEs(MEs, greyName = "ME0");


#=====================================================================================
#
#  Code chunk 3
#
#=====================================================================================


lnames = load("Consensus-NetworkConstruction-auto.RData")
lnames



#=====================================================================================
#
#  Code chunk 4
#
#=====================================================================================


# Isolate the module labels in the order they appear in ordered module eigengenes
femModuleLabels = substring(names(femaleMEs), 3)
consModuleLabels = substring(names(consMEs[[1]]$data), 3)
# Convert the numeric module labels to color labels
femModules = labels2colors(as.numeric(femModuleLabels))
consModules = labels2colors(as.numeric(consModuleLabels))
# Numbers of female and consensus modules
nFemMods = length(femModules)
nConsMods = length(consModules)
# Initialize tables of p-values and of the corresponding counts
pTable = matrix(0, nrow = nFemMods, ncol = nConsMods);
CountTbl = matrix(0, nrow = nFemMods, ncol = nConsMods);
# Execute all pairwaise comparisons
# code with COMMON
for (fmod in 1:nFemMods)
  for (cmod in 1:nConsMods)
  {
    femMembers = (femaleColors.common == femModules[fmod]);
    consMembers = (moduleColors.common == consModules[cmod]);
    pTable[fmod, cmod] = -log10(fisher.test(femMembers, consMembers, alternative = "greater")$p.value);
    CountTbl[fmod, cmod] = sum(femaleColors.common == femModules[fmod] & moduleColors.common ==
                                 consModules[cmod])
ADD REPLY

Login before adding your answer.

Traffic: 718 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6