Skip to content

Commit

Permalink
update exportInteractive
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Dec 13, 2023
1 parent ebfa0aa commit dbc272f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions R/exportInteractive.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ exportInteractive <- function(stana, out=".", db="uhgg", calcko=TRUE,
if (calcko) {
for (sp in species) {
if (is.null(stana@kos[[sp]])) {
qqcat("Summarizing abundances @{sp}\n")
ko_tbl <- summariseAbundance(stana,sp = sp,
checkEGGNOG(annot_file=stana@eggNOG[[sp]],
"KEGG_ko"),
how="mean")
stana@kos[[sp]] <- ko_tbl
if (!is.null(stana@eggNOG[[sp]])) {
qqcat("Summarizing abundances @{sp}\n")
ko_tbl <- summariseAbundance(stana,sp = sp,
checkEGGNOG(annot_file=stana@eggNOG[[sp]],
"KEGG_ko"),
how="mean")
stana@kos[[sp]] <- ko_tbl
}
} else {
qqcat("Using pre-computed KO table\n")
}
Expand All @@ -52,13 +54,17 @@ exportInteractive <- function(stana, out=".", db="uhgg", calcko=TRUE,
}
treLen <- sum(sapply(stana@treeList, function(x) !is.null(x)))
koLen <- length(stana@kos)

## If no metadata is available in meta slot:
meta <- NULL
for (i in names(stana@cl)) {
meta <- rbind(meta,
cbind(stana@cl[[i]],
rep(i, length(stana@cl[[i]]))))
}
meta <- meta |> data.frame() |> `colnames<-`(c("label","group"))
row.names(meta) <- meta[["label"]]

qqcat("Tree number: @{treLen}, KO number: @{koLen}\n")
qqcat("Exporting ... \n")
if (!dir.exists(out)) {
Expand All @@ -77,7 +83,9 @@ exportInteractive <- function(stana, out=".", db="uhgg", calcko=TRUE,
for (i in names(stana@kos)) {
if (i %in% species) {
ko <- stana@kos[[i]]
write.table(ko, ppaste0(out,"/data/",dataset_name,"/KOs/", i, ".txt"), sep="\t", quote=FALSE)
if (!is.null(ko)) {
write.table(ko, ppaste0(out,"/data/",dataset_name,"/KOs/", i, ".txt"), sep="\t", quote=FALSE)
}
}
}
write.table(meta, paste0(out,"/data/",dataset_name,"/metadata.tsv"), sep="\t", quote=FALSE)
Expand Down

0 comments on commit dbc272f

Please sign in to comment.