-
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.
Merge pull request #23 from CostaLab/devel
Merging the recent changes into the master branch.
- Loading branch information
Showing
73 changed files
with
787 additions
and
167 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
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,32 @@ | ||
#'CalculateQuality | ||
#'@description | ||
#'We calculate the quality per variant. | ||
#'@import MatrixGenerics SummarizedExperiment | ||
#'@param SE SummarizedExperiment object. | ||
#'@param chromosome_prefix List of matrices for the alternative reads. | ||
#'@export | ||
CalculateQuality <- function(SE, variants = rownames(reads_alt), chromosome_prefix = "chrM"){ | ||
variants <- gsub(paste0(chromosome_prefix, "_"), "", variants) | ||
qualities <- lapply(c("A", "T", "C", "G"), function(x){ | ||
fwrev <- cbind(assays(SE)[[paste0(x, "_counts_fw")]], assays(SE)[[paste0(x, "_counts_rev")]]) | ||
qualities_fwrev <- cbind(assays(SE)[[paste0(x, "_qual_fw")]], assays(SE)[[paste0(x, "_qual_rev")]]) | ||
variants_use <- strsplit(variants, "") | ||
variants_use <- sapply(variants_use, tail, n = 1) | ||
variants_use <- variants_use == x | ||
variants_use_names <- variants[variants_use] | ||
variants_use <- as.numeric(gsub("_.*", "", variants_use_names)) | ||
variants_use_names <- paste0(chromosome_prefix, "_", variants_use_names) | ||
fwrev <- fwrev[variants_use,] | ||
rownames(fwrev) <- variants_use_names | ||
qualities_fwrev <- qualities_fwrev[variants_use,] | ||
rownames(qualities_fwrev) <- variants_use_names | ||
fwrev <- fwrev > 0 | ||
qualities_fwrev <- qualities_fwrev * fwrev | ||
qualities <- apply(qualities_fwrev, 1, sum) / rowSums(fwrev > 0) | ||
qualities[qualities == 0] <- NA | ||
return(qualities) | ||
}) | ||
qualities <- unlist(qualities) | ||
qualities <- qualities[paste0(chromosome_prefix, "_", variants)] | ||
return(qualities) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#'GetVariantInfo | ||
#'@description | ||
#'We get the genotyping information for a set of variants. | ||
#'The function returns a matrix with the values from the specified assay. | ||
#'@import SummarizedExperiment | ||
#'@param SE SummarizedExperiment object. | ||
#'@param information The assay with the desired information. Default: consensus | ||
#'@param variants A vector of variants. | ||
#'@param cells A vector of cell IDs. On default all cells are returned. Default: NULL | ||
#'@export | ||
GetVariantInfo <- function(SE, information = "consensus", variants = NULL, cells = NULL){ | ||
# We check if a vector of variants has been supplied. | ||
if(is.null(variants)){ | ||
stop("Error: You forgot to supply a vector of variants.") | ||
} | ||
# We check if the variants are actually in a vector. | ||
if(!is.vector(variants)){ | ||
stop("Error: Your variants are not in a vector.") | ||
} | ||
# We check if all variants are in the SE object. | ||
variants_check <- variants %in% rownames(SE) | ||
if(!all(variants_check)){ | ||
variants_check <- sum(variants_check) | ||
stop(paste0("Only ", variants_check, " of ", length(variants), " are in the SE object.")) | ||
} | ||
# We check if the requested assay is actually present. | ||
assay_check <- information %in% names(assays(SE)) | ||
if(!assay_check){ | ||
stop("The assay you wants is not present in the object.") | ||
} | ||
res <- assays(SE)[[information]][variants, , drop = FALSE] | ||
# We subset the result to only include the cells of interest. | ||
# We check if the cells vector is not NULL. | ||
if(!is.null(cells)){ | ||
# We check if all cell IDs are in the SE object. | ||
cell_check <- cells %in% colnames(SE) | ||
if(!all(cell_check)){ | ||
stop(paste0("Error: Only ", sum(cell_check), " cells are present in the object.")) | ||
} else{ | ||
res <- res[, cells, drop = FALSE] | ||
} | ||
} | ||
return(res) | ||
} |
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.