Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module completeness with pre-computed KOs #27

Open
ccgallen opened this issue Apr 22, 2024 · 0 comments
Open

Module completeness with pre-computed KOs #27

ccgallen opened this issue Apr 22, 2024 · 0 comments

Comments

@ccgallen
Copy link

Hi! Thanks for developing this package. I would like to recreate the module completeness heatmap in your documentation here using my own results of kegg mapper. I have lists of KO numbers for each genome and I'd like to visualize them. I am having trouble working with the code below. What exactly are the objects mf and candspid? They seem to be file lists, but of what file types?

Do you have suggestions for how to use the for loop with pre-computed KOs and avoid the mapper step?

Thanks!
Carmen

## Load pre-computed KOs, and recursively perform completeness calculation.
mf <- list.files("../")
mf <- mf[startsWith(mf, "M")]
annos <- list()

candspid <- list.files("../species_dir")
candspid <- sample(candspid, 10)

## Obtain EC to KO mapping file from KEGG REST API
mapper <- data.table::fread("https://rest.kegg.jp/link/ec/ko", header=FALSE)

suppressMessages(
  for (i in candspid) {
    mcs <- NULL
    df <- read.table(paste0("../species_dir/",i), sep="\t", header=1)
    fid <- paste0("ec:",df[df$ontology=="ec",]$function_id)
    kos <- mapper[mapper$V2 %in% fid,]$V1 |> strsplit(":") |> sapply("[",2) |> unique()
    for (mid in mf) {
      mc <- module_completeness(module(mid, directory="../"),
                                query = kos)
      mcs <- c(mcs, mc$complete |> mean()) ## Mean of blocks
    }
    annos[[as.character(i)]] <- mcs
  }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant