Skip to content

Commit f28bf8d

Browse files
committed
gt.format fixed
1 parent 9e87b42 commit f28bf8d

16 files changed

+158
-44
lines changed

CRAN-SUBMISSION

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 1.2.0
2-
Date: 2023-08-08 10:43:09 UTC
3-
SHA: 818caae241ff622440c90ebb6ddf40574a7670ad
1+
Version: 1.3.0
2+
Date: 2024-09-20 12:14:48 UTC
3+
SHA: 15152248a448defd590b98fc1f49df0e92d1cd0b

DESCRIPTION

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: rCNV
22
Type: Package
33
Title: Detect Copy Number Variants from SNPs Data
4-
Version: 1.3.9000
5-
Date: 2024-04-30
4+
Version: 1.3.900
5+
Date: 2024-09-20
66
Language: en-US
77
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")))
88
Maintainer: Piyal Karunarathne <piyalkarumail@yahoo.com>
@@ -20,7 +20,7 @@ Suggests:
2020
knitr,
2121
testthat (>= 3.0.0),
2222
covr
23-
##VignetteBuilder: knitr
23+
VignetteBuilder: knitr
2424
Config/testthat/edition: 3
2525
Roxygen: list(markdown = TRUE)
2626
URL: https://piyalkarum.github.io/rCNV/, https://cran.r-project.org/package=rCNV

R/TMM_normalz.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ index_to_mean <- function(x,indx, my_mean, al=NULL){
206206
#' }
207207
#'
208208
#' @examples
209-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
209+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
210210
#' vcf <- readVCF(vcf.file.path)
211211
#' df<-hetTgen(vcf,"AD-tot",verbose=FALSE)
212-
#' norm.fact(df)
212+
#' norm.fact(df)}
213213
#'
214214
#'
215215
#' @export

R/allele_tests.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#'
1616
#' @author Piyal Karunarathne
1717
#' @examples
18-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
18+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
1919
#' vcf <- readVCF(vcf.file.path=vcf.file.path)
2020
#' het.table<-hetTgen(vcf,"GT")
2121
#' ad.table<-hetTgen(vcf,"AD")
@@ -24,7 +24,7 @@
2424
#' frQ<-allele.freq(het.table,f.typ="ind")
2525
#'
2626
#' #for population-wise and both allele depth and genotype tables
27-
#' \dontrun{frQ<-allele.freq(list(AD=ad.table,GT=het.table),f.typ="pop")}
27+
#' frQ<-allele.freq(list(AD=ad.table,GT=het.table),f.typ="pop")}
2828
#'
2929
#' @export
3030
allele.freq<-function(gtt,f.typ=c("pop","ind"),verbose=TRUE){

R/bias.det.R

+2-4
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ get.pvals<-function(x,df,p.cal){
104104
#' }
105105
#'
106106
#' @examples
107-
#' \dontrun{
107+
#' \dontrun{data(ADtable)
108108
#' hz<-h.zygosity(vcf,verbose=FALSE)
109109
#' Fis<-mean(hz$Fis,na.rm = TRUE)
110-
#' data(ADtable)
111-
#' AI<-allele.info(ADtable,x.norm=ADnorm,Fis=0.11)
112-
#' }
110+
#' AI<-allele.info(ADtable,x.norm=ADnorm,Fis=Fis)}
113111
#'
114112
#' @export
115113
allele.info<-function(X,x.norm=NULL,Fis,method=c("MedR","QN","pca","TMM","TMMex"),logratioTrim = 0.3,sumTrim = 0.05,Weighting = TRUE,Acutoff = -1e+10,plot.allele.cov=TRUE,verbose = TRUE,parallel=FALSE,...){

R/raw_process.R

+120-7
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ maf_0<-function(h.table,AD=TRUE,verbose=TRUE,parallel=FALSE){
214214
#' @author Piyal Karunarathne
215215
#'
216216
#' @examples
217-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
218-
#' vcf <- readVCF(vcf.file.path)
217+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
218+
#' vcf <- readVCF(vcf.file.path)}
219219
#'
220220
#' @export
221221
readVCF <- function(vcf.file.path,verbose=FALSE){
@@ -231,7 +231,7 @@ readVCF <- function(vcf.file.path,verbose=FALSE){
231231
#' VariantsToTable: see details)
232232
#'
233233
#' @param vcf an imported vcf file in a list using \code{readVCF}
234-
#' @param info.type character. \code{AD}: allele depth value, {AD-tot}:total
234+
#' @param info.type character. \code{AD}: allele depth value, \code{AD-tot}:total
235235
#' allele depth, \code{DP}=unfiltered depth (sum), \code{GT}: genotype,
236236
#' \code{GT-012}:genotype in 012 format, \code{GT-AB}:genotype in AB format.
237237
#' Default \code{AD}, See details.
@@ -251,9 +251,9 @@ readVCF <- function(vcf.file.path,verbose=FALSE){
251251
#' @importFrom utils setTxtProgressBar txtProgressBar
252252
#' @importFrom parallel parSapply makeCluster clusterExport parLapply
253253
#' @examples
254-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
254+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
255255
#' vcf <- readVCF(vcf.file.path=vcf.file.path)
256-
#' het.table<-hetTgen(vcf)
256+
#' het.table<-hetTgen(vcf)}
257257
#'
258258
#' @export
259259
hetTgen <- function(vcf, info.type = c("AD", "AD-tot", "GT", "GT-012", "GT-AB", "DP"), verbose = TRUE, parallel = FALSE) {
@@ -429,9 +429,9 @@ hetTgen_cpp <- function(vcf, info.type = c("AD", "AD-tot", "GT", "GT-012", "GT-A
429429
#' Returns a data frame of allele depth or genotypes
430430
#'
431431
#' @examples
432-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
432+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
433433
#' vcf <- readVCF(vcf.file.path=vcf.file.path)
434-
#' missing<-get.miss(vcf,plot=TRUE)
434+
#' missing<-get.miss(vcf,plot=TRUE)}
435435
#'
436436
#' @export
437437
get.miss<-function(data,type=c("samples","snps"),plot=TRUE,verbose=TRUE,parallel=FALSE){
@@ -549,6 +549,119 @@ get.miss<-function(data,type=c("samples","snps"),plot=TRUE,verbose=TRUE,parallel
549549
#'
550550
#' @export
551551
gt.format <- function(gt,info,format=c("benv","bpass"),snp.subset=NULL,parallel=FALSE) {
552+
if(parallel) {
553+
numCores <- detectCores() - 1
554+
cl <- makeCluster(numCores)
555+
}
556+
557+
if(is.character(gt)) {
558+
gt <- as.data.frame(fread(gt))
559+
gts <- gt[,-c(1,2)]
560+
} else {
561+
gts <- gt[,-c(1:4)]
562+
}
563+
564+
if(is.character(info)) {
565+
if(length(info) == ncol(gts)) {
566+
info <- data.frame(population = info)
567+
} else {
568+
pop.col <- rep(NA, ncol(gts))
569+
for(i in seq_along(info)) {
570+
pop.col[grep(info[i], colnames(gts))] <- info[i]
571+
}
572+
info <- data.frame(population = pop.col)
573+
}
574+
}
575+
576+
# Ensure rownames match the original order
577+
rownames(gts) <- paste(gt$CHROM, gt$POS, sep = ".")
578+
579+
# Keep population order consistent with input `info`
580+
pp <- unique(info$population)
581+
pp <- pp[order(match(pp, info$population))] # Fix ordering issue
582+
583+
infos <- as.character(info$population)
584+
format <- match.arg(format, several.ok = TRUE)
585+
586+
# Ensure lgt follows original population order
587+
lgt <- split.data.frame(t(gts), f = factor(info$population, levels = pp))
588+
589+
if(any(format == "benv")) {
590+
message("Formating BayEnv")
591+
592+
if(parallel) {
593+
ppe <- parLapply(cl, lgt, function(X) {
594+
out <- apply(X, 2, function(x) {
595+
zero <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 0)
596+
one <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 1)
597+
return(as.data.frame(c(zero, one), col.names = FALSE))
598+
}, simplify = FALSE)
599+
do.call(rbind, out)
600+
})
601+
} else {
602+
ppe <- lapply_pb(lgt, function(X) {
603+
out <- apply(X, 2, function(x) {
604+
zero <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 0)
605+
one <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 1)
606+
return(as.data.frame(c(zero, one), col.names = FALSE))
607+
}, simplify = FALSE)
608+
do.call(rbind, out)
609+
})
610+
}
611+
612+
ppe <- do.call(cbind, ppe)
613+
} else {
614+
ppe <- NULL
615+
}
616+
617+
if(any(format == "bpass")) {
618+
message("Formating BayPass")
619+
620+
if(parallel) {
621+
ppp <- parLapply(cl, lgt, function(X) {
622+
out <- apply(X, 2, function(x) {
623+
zero <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 0)
624+
one <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 1)
625+
return(c(zero, one))
626+
}, simplify = FALSE)
627+
do.call(rbind, out)
628+
})
629+
} else {
630+
ppp <- lapply_pb(lgt, function(X) {
631+
out <- apply(X, 2, function(x) {
632+
zero <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 0)
633+
one <- sum((unlist(stringr::str_split(x, "/|\\|"))) == 1)
634+
return(c(zero, one))
635+
}, simplify = FALSE)
636+
do.call(rbind, out)
637+
})
638+
}
639+
640+
ppp <- do.call(cbind, ppp)
641+
642+
# Ensure column names preserve population order
643+
colnames(ppp) <- paste0(rep(pp, each = 2), "~", rep(c(1,2), ncol(ppp)/2))
644+
rownames(ppp) <- paste0(gt$CHROM, ".", gt$POS)
645+
646+
if(!is.null(snp.subset)) {
647+
rn <- sample(1:snp.subset, nrow(gts), replace = TRUE)
648+
rownames(gts) <- paste0(gt$CHROM, ".", gt$POS)
649+
chu.p <- split.data.frame(ppp, f = rn)
650+
} else {
651+
chu.p <- NULL
652+
}
653+
} else {
654+
ppp <- NULL
655+
}
656+
657+
if(parallel) { stopCluster(cl) }
658+
659+
return(list(baypass = ppp, bayenv = ppe, sub.bp = chu.p, pop = as.character(pp)))
660+
}
661+
662+
663+
664+
gt.format0 <- function(gt,info,format=c("benv","bpass"),snp.subset=NULL,parallel=FALSE) {
552665
if(parallel){numCores<-detectCores()-1
553666
cl<-makeCluster(numCores)}
554667

R/statistics.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ h.zygosity<-function(vcf,plot=FALSE,pops=NA,verbose=TRUE,parallel=FALSE){
171171
#' (2010).
172172
#'
173173
#' @examples
174-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
174+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
175175
#' vcf <- readVCF(vcf.file.path=vcf.file.path)
176-
#' relate<-relatedness(vcf)
176+
#' relate<-relatedness(vcf)}
177177
#'
178178
#' @export
179179
relatedness<-function(vcf,plot=TRUE,threshold=0.5,verbose=TRUE,parallel=FALSE){
@@ -286,9 +286,9 @@ relatedness<-function(vcf,plot=TRUE,threshold=0.5,verbose=TRUE,parallel=FALSE){
286286
#' @author Piyal Karunarathne
287287
#'
288288
#' @examples
289-
#' vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
289+
#' \dontrun{vcf.file.path <- paste0(path.package("rCNV"), "/example.raw.vcf.gz")
290290
#' vcf <- readVCF(vcf.file.path=vcf.file.path)
291-
#' statistics<-vcf.stat(vcf,plot=TRUE)
291+
#' statistics<-vcf.stat(vcf,plot=TRUE)}
292292
#'
293293
#' @export
294294
vcf.stat<-function(vcf,plot=TRUE,...){

cran-comments.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## R CMD check results
22

3+
* Fixes to the notes:
4+
1. "#VignetteBuilder" line was removed
5+
2. Date field was updated
6+
3. time taken for example >10 sec seems to be an internal wind-dev issue. I checked it manually with win-dev release and all examples execute in less than 10 seconds
7+
38
This is the third update of the package. Several changes have been made to two major functions and new updates have been added. They're as follows:
49

510
1. parallelization enabled with parallel package

man/allele.freq.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/allele.info.Rd

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get.miss.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/hetTgen.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/norm.fact.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/readVCF.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/relatedness.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/vcf.stat.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)