Skip to content

Commit

Permalink
new functions and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piyalkarum committed Apr 29, 2024
1 parent eed21a4 commit a0b318a
Show file tree
Hide file tree
Showing 55 changed files with 177 additions and 111 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: rCNV
Type: Package
Title: Detect Copy Number Variants from SNPs Data
Version: 1.2.9000
Date: 2023-08-01
Version: 1.3.9000
Date: 2024-04-30
Language: en-US
Authors@R: c(person(given="Piyal",family="Karunarathne", email="piyalkarumail@yahoo.com", role = c("aut", "cre"),comment = c(ORCID = "0000-0002-1934-145X")),person(given="Qiujie",family="Zhou", email="qiujie.zhou@ebc.uu.se", role = c("aut"),comment = c(ORCID = "0000-0001-7351-2371")),person("Klaus", "Schliep", email="klaus.schliep@gmail.com", role = c("aut"), comment = c(ORCID = "0000-0003-2941-0161")),person(given="Pascal", family="Milesi", role = "aut",comment = c(ORCID = "0000-0001-8580-4291")))
Maintainer: Piyal Karunarathne <piyalkarumail@yahoo.com>
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rCNV 1.3.0 (third update)
* vstPermutation function added
* maf modified to remove multi-allelic sites
* FIT correction added

# rCNV 1.2.0 (second update)
* relatedness function optimized
Expand Down
2 changes: 1 addition & 1 deletion R/detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ dupGet<-function(data,test=c("z.het","z.05","z.all","chi.het","chi.05","chi.all"
#data check
data<-as.data.frame(data)
if(!any(colnames(data)=="propHet")){
stop("please provide the data with the output of allele.info()")
stop("please provide the output of allele.info()")
} else {
if(!(any(colnames(data)=="eH.pval"))) {
ht<-sig.hets(data,plot=F,verbose=verbose)
Expand Down
66 changes: 44 additions & 22 deletions R/raw_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,37 +133,59 @@ gg<-function(x){
#' a bi-allelic matrix when loci are multi-allelic
#'
#' @param h.table allele depth table generated from the function \code{hetTgen}
#' @param AD logical. If TRUE a allele depth table similar to \code{hetTgen}
#' output will be returns; If \code{FALSE}, individual AD values per SNP will be
#' @param drop.multi logical. If TRUE, all the sites with more than two allele will be
#' dropped. If FALSE \code{default}, the the two alleles with the highest allele
#' frequencies will be retained. See details for more information.
#' @param AD logical. If TRUE, an allele depth table similar to \code{hetTgen}
#' output will be returned; If \code{FALSE}, individual AD values per SNP will be
#' returned in a list.
#' @param verbose logical. Show progress
#'
#' @return A data frame or a list of minimum allele frequency removed allele depth
#'
#' @details
#' This function either drops all sites with more than two alleles or keep alleles \code{drop.multi=TRUE}
#' with the highest allele frequencies in the case of multi-allelic sites \code{drop.multi=FALSE}.
#' Note that, in the latter case, all sites will be retained, essentially assuming that multi-allelic sites
#' are also bi-allelic by dropping the alleles with minimum frequencies.
#' This function can only be used on the output of the \code{hetTgen()}. If you need to remove the multi-allelic sites
#' from the vcf, use \code{rCNV:::non_bi_rm()} function. We recommend using other programs (e.g., vcftools, GATK, etc.) for removing multiallelic sites faster.
#'
#'
#' @author Piyal Karunarathne
#'
#' @examples
#' \dontrun{mf<-maf(ADtable)}
#'
#' @export
maf<-function(h.table,AD=TRUE,verbose=TRUE){
htab<-h.table[,-c(1:3)]
if(verbose){
glt<-apply_pb(htab,1,function(X){
gg<-do.call(rbind,lapply(X,function(x){as.numeric(strsplit(x,",")[[1]])}))
while(ncol(gg)>2){gg<-gg[,-which.min(colMeans(proportions(gg,1),na.rm=T))]}
if(AD){return(paste0(gg[,1],",",gg[,2]))}else{return(gg)}
})
}else{
glt<-apply(htab,1,function(X){
gg<-do.call(rbind,lapply(X,function(x){as.numeric(strsplit(x,",")[[1]])}))
if(ncol(gg)>2)gg<-gg[,-which.min(colMeans(proportions(gg,1),na.rm=T))]
if(AD){return(paste0(gg[,1],",",gg[,2]))}else{return(gg)}
})
maf<-function(h.table,drop.multi=FALSE,AD=TRUE,verbose=TRUE){
h.table<-data.frame(h.table)
warning(paste0("There are ",sum(nchar(h.table$ALT)>1),"multi-allelic sites"))
if(drop.multi){
h.table<-h.table[-which(nchar(h.table$ALT)>1),] # drop multi-allelic sites
message(paste0("\n",sum(nchar(h.table$ALT)>1),"multi-allelic sites were removed"))
return(h.table)
} else { # drop alleles with maf when multi-allelic
htab<-h.table[,-c(1:4)]
if(verbose){
glt<-apply_pb(htab,1,function(X){suppressWarnings({
gg<-do.call(rbind,lapply(X,function(x){as.numeric(strsplit(x,",")[[1]])}))
while(ncol(gg)>2){gg<-gg[,-which.min(colMeans(proportions(gg,1),na.rm=T))]}
if(AD){return(paste0(gg[,1],",",gg[,2]))}else{return(gg)}
})
})
}else{
glt<-apply(htab,1,function(X){
gg<-do.call(rbind,lapply(X,function(x){as.numeric(strsplit(x,",")[[1]])}))
if(ncol(gg)>2)gg<-gg[,-which.min(colMeans(proportions(gg,1),na.rm=T))]
if(AD){return(paste0(gg[,1],",",gg[,2]))}else{return(gg)}
})
}
glt<-data.frame(h.table[,1:4],t(glt))
colnames(glt)<-colnames(h.table)
message("Minimum frequency alleles were removed in multi-allelic sites")
return(glt)
}
glt<-data.frame(h.table[,1:3],t(glt))
colnames(glt)<-colnames(h.table)
return(glt)
}


Expand Down Expand Up @@ -225,7 +247,7 @@ hetTgen <- function(vcf,info.type=c("AD","AD-tot","GT","GT-012","GT-AB","DP"),ve
if(inherits(vcf,"list")){vcf<-vcf$vcf}
if(inherits(vcf,"data.frame")){vcf<-data.table::data.table(vcf)}
if(any(nchar(vcf$ALT)>1)){
warning("vcf file contains multi-allelic variants: only bi-allelic SNPs allowed\nUse maf() to remove non-bi-allilic snps")
warning("vcf file contains multi-allelic variants: \nonly bi-allelic SNPs allowed\nUse maf() to remove non-bi-allilic snps or drop minumum frequency alleles")
}
if(inherits(vcf,"list")){vcf<-vcf$vcf}

Expand Down Expand Up @@ -512,9 +534,9 @@ ad.correct<-function(het.table,gt.table=NULL,odd.correct=TRUE,verbose=TRUE){
x<-gt.table[,n]
Y<-data.frame(do.call(cbind,data.table::tstrsplit(X,",")))
y<-which(x=="0/0" & Y$X2>0)
rr<-range(Y$X2[y])#range of depth in miss classified snps
rr<-range(Y$X2[y])#range of depth in mis classified snps
Y[y,]<-0
ll<-length(y)#number of miss classifications
ll<-length(y)#number of mis classifications
out<-paste0(Y$X1,",",Y$X2)
return(out)
})
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

4 changes: 2 additions & 2 deletions docs/articles/rCNV.html

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

2 changes: 1 addition & 1 deletion docs/authors.html

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

2 changes: 1 addition & 1 deletion docs/index.html

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

4 changes: 3 additions & 1 deletion docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
rCNV: rCNV.html
last_built: 2024-03-19T12:12Z
last_built: 2024-04-29T12:37Z

2 changes: 1 addition & 1 deletion docs/reference/ADnorm.html

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

2 changes: 1 addition & 1 deletion docs/reference/ADtable.html

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

Binary file modified docs/reference/Rplot003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/reference/ad.correct.html

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

2 changes: 1 addition & 1 deletion docs/reference/allele.freq.html

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

2 changes: 1 addition & 1 deletion docs/reference/allele.info.html

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

2 changes: 1 addition & 1 deletion docs/reference/alleleINF.html

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

2 changes: 1 addition & 1 deletion docs/reference/cnv.html

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

2 changes: 1 addition & 1 deletion docs/reference/cpm.normal.html

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

2 changes: 1 addition & 1 deletion docs/reference/depthVsSample.html

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

2 changes: 1 addition & 1 deletion docs/reference/dup.plot.html

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

2 changes: 1 addition & 1 deletion docs/reference/dup.validate.html

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

2 changes: 1 addition & 1 deletion docs/reference/dupGet.html

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

2 changes: 1 addition & 1 deletion docs/reference/exportVCF.html

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

2 changes: 1 addition & 1 deletion docs/reference/get.miss.html

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

2 changes: 1 addition & 1 deletion docs/reference/gt.format.html

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

2 changes: 1 addition & 1 deletion docs/reference/h.zygosity.html

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

2 changes: 1 addition & 1 deletion docs/reference/hetTgen.html

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

Loading

0 comments on commit a0b318a

Please sign in to comment.