-
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
3 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#' doL0 | ||
#' | ||
#' feature selection of classification between category | ||
#' using snv frequency and gene matrix, based on L0Learn | ||
#' | ||
#' @param stana stana object | ||
#' @param species candidate species ID | ||
#' @param cl named list of category | ||
#' @param target default to snps | ||
#' @param mat if target is not snps, provide preprocessed gene matrix | ||
#' otherwise the raw gene matrix is used. | ||
#' @param deleteZeroDepth delete zero depth SNV | ||
#' @param argList passed to L0Learn() | ||
#' @return L0Learn object | ||
#' @import ggplot2 | ||
#' @export | ||
doL0 <- function(stana, species, cl=NULL, doFix=TRUE, | ||
target="genes", mat=NULL, whichToCount="ec_description", argList=list(), | ||
deleteZeroDepth=FALSE) { | ||
if (length(argList)==0) { | ||
qqcat("Penalty is set to L0L2 by default") | ||
argList[["penalty"]] <- "L0L2"} | ||
if (is.null(cl)) { | ||
qqcat("Using grouping from the slot\n") | ||
cl <- stana@cl | ||
} | ||
if (target!="snps" & is.null(mat)){ | ||
qqcat("If needed, please provide preprocessed matrix of genes to `mat`\n") | ||
filtDf <- stana@genes[[species]] | ||
} else if (target=="snps"){ | ||
filtDf <- stana@snps[[species]] | ||
if (deleteZeroDepth) { | ||
filtDf <- filtDf[rowSums(filtDf==-1)==0,] | ||
qqcat("After filtering `-1`, position numbers: @{dim(filtDf)[1]}\n") | ||
} | ||
} else { | ||
qqcat("Proceeding with provided matrix\n") | ||
filtDf <- mat | ||
} | ||
qqcat("Feature number: @{dim(filtDf)[1]}\n") | ||
transDf <- data.frame(t(filtDf), check.names=FALSE) | ||
transDf <- transDf[intersect(row.names(transDf), cl |> unlist() |> unique()),] | ||
gr <- NULL | ||
for (cn in rownames(transDf)){ | ||
for (clm in seq_along(cl)){ | ||
if (cn %in% cl[[clm]]) { | ||
gr <- c(gr, names(cl)[clm]) | ||
} | ||
} | ||
} | ||
|
||
|
||
qqcat("Performing L0Learn\n") | ||
argList[["x"]] <- transDf |> as.matrix() | ||
argList[["y"]] <- as.factor(gr) | ||
l0res <- do.call("L0Learn.cvfit", argList) | ||
return(l0res) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.