-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
202 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' addGeneAbundance | ||
#' | ||
#' Add the specified gene copy number to metadata | ||
#' | ||
#' @param stana stana object | ||
#' @param candSp candidate species | ||
#' @param IDs gene IDs to add | ||
#' @param target KO or genes | ||
#' @param how how to combine multiple IDs | ||
#' @param newCol new column name | ||
#' @param discNumeric convert discrete value to numeric | ||
#' @param disc discretize the abundance by the threshold. function for calculating | ||
#' threshold, like median | ||
#' @param convert conversion such as log10 | ||
#' @export | ||
#' @return stana object | ||
addGeneAbundance <- function(stana, candSp, IDs, | ||
target="KO", how=sum, newCol="gene", | ||
disc=NULL, discNumeric=TRUE, convert=NULL) { | ||
if (target=="KO") { | ||
ints <- intersect(row.names(stana@kos[[candSp]]), IDs) | ||
subMat <- stana@kos[[candSp]][ints, ] | ||
} else { | ||
ints <- intersect(row.names(stana@genes[[candSp]]), IDs) | ||
subMat <- stana@genes[[candSp]][ints, ] | ||
} | ||
if (length(IDs)>1) { | ||
adda <- apply(subMat, 2, how) | ||
} else { | ||
adda <- subMat | ||
} | ||
nm <- names(adda) | ||
if (!is.null(disc)) { | ||
thresh <- do.call(disc, list("x"=adda)) | ||
if (discNumeric) { | ||
adda <- as.numeric(adda > thresh) | ||
} else { | ||
adda <- adda > thresh | ||
} | ||
names(adda) <- nm | ||
} | ||
meta <- stana@meta | ||
if (!is.null(convert)) { | ||
adda <- do.call(convert, list(x=adda)) | ||
} | ||
meta[[newCol]] <- adda[row.names(stana@meta)] | ||
stana@meta <- meta | ||
return(stana) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.