annFUN error TOPGO
1
0
Entering edit mode
@eleonoraporcu-23265
Last seen 4.6 years ago

I’m trying to use the new version of topGO but R gives me an error that I’m not able to correct

Using the toy dataset I’m building the topGOdata object using annFUN.org as annotation

GOdata <- new("topGOdata", ontology = "BP", allGenes=geneList, annot = annFUN.org, mapping=org.Hs.eg, ID="Gene Symbol")

and I get this error:

Building most specific GOs ..... Error in as.character(x) : cannot coerce type 'closure' to vector of type 'character'

How can I solve that? I don’t have this error when I use annFUN.gene2GO as annotation

TOPGO annFUN error • 2.8k views
ADD COMMENT
0
Entering edit mode
Kevin Blighe ★ 4.0k
@kevin
Last seen 27 days ago
Republic of Ireland

Hey,

The error possibly relates to how you produced annFun.org, even though no error was returned when you ran the annFUN.org() command. Also, the mapping is usually specified, not in new(), but, rather, in annFUN.org() as mapping = 'org.Hs.eg.db'.

In addition, just to be sure, geneList should be a named numeric vector, usually of p-values, whose names relate to genes. In your case, they have to be gene symbols.

Finally, I think that ID should be ID = 'symbol'

Here is an example:

head(genes)
 ANXA2 DHCR24   GBE1    GLA  PRDX1 PSMD14 
     0      0      0      0      0      0 
tail(genes)
   CTTNBP2NL      METTL7B       AKR1C3      SLC5A11        TIMP4      PPP2R2C 
7.395843e-07 1.496372e-06 4.328879e-05 1.612348e-04 2.620590e-04 9.728924e-04 

range(genes)
[1] 0.0000000000 0.0009728924

require(topGO)
require(org.Hs.eg.db)

# function that returns TRUE/FALSE for p-values<0.05
selection <- function(allScore) {
  return(allScore < 0.05)
}

allGO2genes <- annFUN.org(
  whichOnto = 'BP',
  feasibleGenes = NULL,
  mapping = 'org.Hs.eg.db',
  ID = 'symbol')

GOdata <- new('topGOdata',
  ontology = 'BP',
  allGenes = genes,
  annot = annFUN.GO2genes,
  GO2genes = allGO2genes,
  geneSel = selection,
  nodeSize = 10)

I show this on Biostars: https://www.biostars.org/p/350710/#350712

Kevin

ADD COMMENT
0
Entering edit mode

thanks a lot, Kevin.

I used your code but I still don't menage to run TopGO.

Here my script where the input files are the list of universe genes (with ENSEMBLE id) and the list of relevant genes. So, I don't have any pvalue, only gene names in my files

cmd_args=commandArgs()

all<-cmd_args[3]

relevant<-cmd_args[4]

output<-cmd_args[5]

ont<-"BP"

library(topGO)

require(topGO)

require(org.Hs.eg.db)

A<-read.table(all,header=F,sep=" ",dec=".")

all.genes <-as.character(A[,1])

vector<-rep(1,length(all.genes))

names(vector)<- all.genes 

all.genes<- vector

B<-read.table(relevant,header=F,sep=" ",dec=".")

diff.genes <-as.character(B[,1])

go.enrichment <- function(total.gene.names, significant.genes, ont){

library(topGO)

relevant.genes <- factor(as.integer(total.gene.names %in% significant.genes))

names(relevant.genes) <- total.gene.names

relevant.genes<-as.vector(relevant.genes)

allGO2genes <- annFUN.org( whichOnto = 'BP', feasibleGenes = NULL, mapping = 'org.Hs.eg.db', ID = 'symbol')

GOdata <- new('topGOdata', ontology = 'BP', allGenes = total.gene.names, annot = annFUN.GO2genes, GO2genes = allGO2genes, geneSel = relevant.genes, nodeSize = 10)

test.stat<-new("classicCount", testStatistic= GOFisherTest, name= "Fisher Test")

    resultFisher <- getSigGroups(GOdata, test.stat)

allRes <- GenTable(GOdata, classic=resultFis, topNodes = 500) # make it bigger

    corrected <- p.adjust(as.numeric(allRes$classic), method="fdr")

    allRes$FDR <- corrected

  return(allRes)
}


out<-go.enrichment(all.genes,diff.genes,ont)

out<-as.data.frame(out)

outfile<-paste(output,"_",ont,".txt",sep="")

write.table(out,file=outfile,col.names=T,row.names=F,quote=F,sep="\t")

At the end I got this error:

*Error in (function (cl, name, valueClass)  : 
  assignment of an object of class “character” is not valid for @‘geneSelectionFun’ in an object of class “topGOdata”; is(value, "function") is not TRUE
Calls: go.enrichment ... new -> initialize -> initialize -> .local -> <Anonymous>
Execution halted*
ADD REPLY
0
Entering edit mode

Hey again, the problem is that the value passed to geneSel should be a function - you are passing to it another named vector of values.

If you take a look at my code again, you'll see that I am passing the following function to geneSel:

# function that returns TRUE/FALSE for p-values<0.05
selection <- function(allScore) {
  return(allScore < 0.05)
}

This function will be applied to, in your case, the total.gene.names variable. It is essentially used to filter your input gene list by, for example, p-value < 0.05 (my function). Here is an example:

# function that returns TRUE/FALSE for p-values<0.05
selection <- function(allScore) {
  return(allScore < 0.05)
}

pvalues <- c(1,0.05,0.1,1,1,0.0005,0.004,0.05,0.064)
selection(pvalues)
[1] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
ADD REPLY
0
Entering edit mode

Thanks a lot for clarifying this.

I modified my code as:

selection <- function(total.gene.names,significant.genes) {return(total.gene.names %in% significant.genes)}

allGO2genes <- annFUN.org( whichOnto = 'BP', feasibleGenes = NULL, mapping = 'org.Hs.eg.db', ID = 'symbol')

GOdata <- new('topGOdata', ontology = 'BP', allGenes = total.gene.names, annot = annFUN.GO2genes, GO2genes = allGO2genes, geneSel = selection, nodeSize = 10)

and now I got a new error

*Error in if is.na(index) || index < 0 || index > length(nd)) stop("vertex is not in graph: ",  : 
  missing value where TRUE/FALSE needed
Calls: go.enrichment ... buildLevels -> getGraphRoot -> sapply -> adj -> adj
Execution halted*
ADD REPLY
0
Entering edit mode

I see - that may not function as expected because the selection function will only accept one parameter.

Just to recap: the object passed to allGenes should be a named vector of p-values or other values, such as fold changes. In your case, therefore, your total.gene.names variable should look something like this:

   head(total.gene.names)
     ANXA2 DHCR24   GBE1    GLA  PRDX1 PSMD14 
         0      0      0      0      0      0 
   tail(total.gene.names)
       CTTNBP2NL      METTL7B       AKR1C3      SLC5A11        TIMP4      PPP2R2C 
    7.395843e-07 1.496372e-06 4.328879e-05 1.612348e-04 2.620590e-04 9.728924e-04

------

The function passed to geneSel will be applied to total.gene.names and should return a boolean vector of values.

In your case, you may want to use:

selection <- function(genes) {
  return(names(genes) %in% names(significant.genes))
  }

Then test it to see what it produces:

selection(total.gene.names)

What is the output? - it should return a vector of TRUE|FALSE

This assumes that both total.gene.names significant.genes are named vectors of p-values or fold changes.

If you still have problems, you could post the output of total.gene.names and significant.genes

ADD REPLY
0
Entering edit mode

Correct,

head(all.genes)

ENSG00000238009 ENSG00000157999 ENSG00000198157 ENSG00000227288 ENSG00000186831 ENSG00000226261

          1               1               1               1               1               1

selection(all.genes) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

[13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

[25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

[37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

[49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

[61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE

[73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE .....

GOdata <- new('topGOdata', ontology = 'BP', allGenes = all.genes, annot = annFUN.GO2genes, GO2genes = allGO2genes, geneSel = selection(all.genes), nodeSize = 10)

assignment of an object of class “logical” is not valid for @‘geneSelectionFun’ in an object of class “topGOdata”; is(value, "function") is not TRUE Calls: go.enrichment ... new -> initialize -> initialize -> .local -> <anonymous> Execution halted

ADD REPLY
0
Entering edit mode

Ah, this should now work:

GOdata <- new('topGOdata',
  ontology = 'BP',
  allGenes = all.genes,
  annot = annFUN.GO2genes,
  GO2genes = allGO2genes,
  geneSel = selection,
  nodeSize = 10)

I changed geneSel = selection(all.genes) to geneSel = selection

ADD REPLY
0
Entering edit mode

no :(

Build GO DAG topology .......... ( 0 GO terms and 0 relations. ) Error in if is.na(index) || index < 0 || index > length(nd)) stop("vertex is not in graph: ", : missing value where TRUE/FALSE needed Calls: go.enrichment ... buildLevels -> getGraphRoot -> sapply -> adj -> adj Execution halted

ADD REPLY
0
Entering edit mode

Ah, looks like you are using Ensembl gene IDs. So, you need to use:

allGO2genes <- annFUN.org(whichOnto = 'BP',
  feasibleGenes = NULL,
  mapping = 'org.Hs.eg.db',
  ID = 'ensembl')
ADD REPLY
0
Entering edit mode

Apparently it cannot read my genes...

**Annotating nodes ............... ( 12920 genes annotated to the GO terms. )

         -- Classic Algorithm -- 

     the algorithm is scoring 0 nontrivial nodes
     parameters: 
         test statistic: Fisher Test

Warning message: In .local(object, test.stat, ...) : No enrichment can pe performed - there are no feasible GO terms!**

ADD REPLY
0
Entering edit mode

I think that it was able to read the genes but could not find any enriched term that passed the basic thresholds.

You could try to reduce the value of nodeSize to 5. Also, does anything come up for the other ontologies:

whichOnto = 'CC'
whichOnto = 'MF'

Otherwise, you may have to explore other tests other than Fisher's.

I usually run these functions like this:

allGO2genes <- annFUN.org(whichOnto = 'BP',
  feasibleGenes = NULL, mapping = 'org.Hs.eg.db', ID = 'ensembl')
GOdata <- new('topGOdata', ontology = 'BP',
  allGenes = rankedGenes, annot = annFUN.GO2genes,
  GO2genes = allGO2genes, geneSel = selection, nodeSize = 10)

# In order to make use of the rank information, use Kolmogorov-Smirnov (K-S) test
results.ks <- runTest(GOdata, algorithm = 'classic', statistic = 'ks')
goEnrichment <- GenTable(GOdata,
  KS = results.ks, orderBy = 'KS', topNodes = length(results.ks@score))
goEnrichment <- goEnrichment[goEnrichment$KS < 1.00,]
goEnrichment <- goEnrichment[,c('GO.ID','Term','KS')]
ADD REPLY
0
Entering edit mode

If I use KS test I have the same warning message

  • No enrichment can pe performed - there are no feasible GO terms!*

And it's not possible as I'm testing genes well known to belong to pathways related to lipids

ADD REPLY

Login before adding your answer.

Traffic: 574 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