Skip to content

Commit

Permalink
combineGenes
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Oct 25, 2023
1 parent 506f401 commit 0440b07
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(checkEGGNOG)
export(checkPATRIC)
export(checkPATRICSimple)
export(cnDiscretize)
export(combineGenes)
export(combineSeqs)
export(compareGenes)
export(consensusSeq)
Expand Down
32 changes: 32 additions & 0 deletions R/combineGenes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' combineGenes
#'
#' (experimental) use common genes across multiple datasets to
#' merge gene copy numbers
#'
#' @param stana_list stana list
#' @param species species ID
#' @export
#' @return new stana object
combineGenes <- function(stana_list, species, argList=list(), output_seq=FALSE) {
if (!is.list(stana_list)) {stop("Please provide list of stana object")}
each_ID <- lapply(stana_list, function(x) x@genes[[species]] |> row.names())
intersected <- Reduce(intersect, each_ID)
if (length(intersected)==0) {stop("No common genes")}

qqcat("Common genes: @{length(intersected)}\n")

merged <- do.call(cbind, lapply(stana_list, function(x) x@genes[[species]][intersected,]))

## Metadata
new_stana <- new("stana")
new_stana@genes[[species]] <- merged
cls <- lapply(stana_list, function(x) x@cl)
cls <- do.call(c, cls)
new_stana@ids <- species
new_stana@type <- stana@type
new_stana@cl <- cls
new_stana@colors <- getColors(cls)

return(new_stana)
}

3 changes: 2 additions & 1 deletion R/compareGenes.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
#' @export
#' @return ggplot
#'
compareGenes <- function(stana, species, geneID=NULL, cl=NULL, argList=list(),
compareGenes <- function(stana, species=NULL, geneID=NULL, cl=NULL, argList=list(),
verbose_zero=FALSE) {
if (is.null(cl)) { cl <- stana@cl}
if (is.null(species)) {species <- stana@clearGenes[1]}
midas_merge_dir <- stana@mergeDir
geneDf <- stana@genes[[species]]
incSamples <- intersect(colnames(geneDf), unlist(cl))
Expand Down
20 changes: 20 additions & 0 deletions man/combineGenes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/compareGenes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0440b07

Please sign in to comment.