jokergoo / simplifyEnrichment

Simplify functional enrichment results
https://jokergoo.github.io/simplifyEnrichment
Other
108 stars 16 forks source link

GO_similarity error #107

Closed sugiYag closed 1 day ago

sugiYag commented 1 month ago

hi

now, I found some GO terms and I wanna get some information using the GO_similarity function in the simplifyEnrichment package.

I found a tutorial about that https://jokergoo.github.io/simplifyEnrichment/reference/simplifyGO.html

As it is on this site, I have written the code accordingly but got an error when I run

mat = [GO_similarity]

this code.

the error is as follow : Error: unable to find an inherited method for function 'Lkeys' for signature 'x = "list"'

I could not find any reference for this error.

so, please let me know how to solve it

PavelEG commented 1 month ago

Did you find a solution? I'm getting the same error.

sugiYag commented 1 month ago

yes. i solved the problem.

to solve it, you should change the source code and modify the 'similarity_GO.R' file. there are many functions including GO_similarity change the code as follows:

GO_similarity = function(go_id, ont = NULL, db = 'org.Hs.eg.db', measure = "Rel",
   remove_orphan_terms = FALSE) {

   if(is.null(ont)) {
      ont = guess_ont(go_id, db)
      if(is.null(ont)) {
         stop_wrap("Cannot determine which GO ontology (BP/CC/MF) you are using. Please manualy set `ont` argument.")
      }
      message(qq("You haven't provided value for `ont`, guess it as `@{ont}`."))
   }

   hash = digest::digest(list(ont = ont, db = db))
   if(hash == env$semData_hash) {
      semData = env$semData
   } else {
      suppressMessages(semData <- godata(annoDb = db, ont = ont))
      env$semData_hash = hash
      env$semData = semData
   }

   # Use `names` instead of `Lkeys`
   go_removed = setdiff(go_id, names(getFromNamespace("getAncestors", "GOSemSim")(semData@ont)))

   if(length(go_removed)) {
      message(qq("@{length(go_removed)}/@{length(go_id)} GO term@{ifelse(length(go_removed) == 1, ' is', 's are')} removed."))
   }
   go_id = setdiff(go_id, go_removed)

   go_sim = termSim(go_id, go_id, method = measure, semData = semData)
   go_sim[is.na(go_sim)] = 0

   go_sim[lower.tri(go_sim)]  = t(go_sim)[lower.tri(go_sim)]

   if(remove_orphan_terms) {
      go_sim_tmp = go_sim
      diag(go_sim_tmp) = 0
      l = rowSums(go_sim_tmp) == 0
      if(any(l)) {
         message(qq("@{sum(l)} GO term@{ifelse(sum(l) == 1, ' is', 's are')} removed because @{ifelse(sum(l) == 1, 'it has', 'they have')} zero similarity to all other terms."))
         go_sim = go_sim[l, l, drop = FALSE]
      }
   }

   attr(go_sim, "measure") = measure
   attr(go_sim, "ontology") = paste0("GO:", ont)
   return(go_sim)
}
PavelEG commented 4 weeks ago

Wow many thanks!.

Hayao-jp commented 3 weeks ago

I got the same problem but I have no idea to execute sugiYag's modified code because I am beginner of R. Could anyone tell me how to use the code...

sugiYag commented 1 week ago

@Hayao-jp

I received an email from the developer of the 'simplifyEnrichment' package, and they mentioned that they fixed the error. Please update the package and try again.

Hayao-jp commented 1 week ago

@sugiYag thank you so much! I update package and finish execution completely with no errors.