Skip to content

Commit c727794

Browse files
committed
seqVCF2GDS: error message saved in a file
1 parent 306b7ba commit c727794

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import(gdsfmt)
3131
importFrom(stats, median, sd)
3232
importFrom(parallel, clusterApply, clusterApplyLB, clusterCall, detectCores,
3333
makeCluster, makeForkCluster, mclapply, stopCluster)
34-
importFrom(utils, read.table, flush.console, write.table, str, tail,
35-
type.convert)
34+
importFrom(utils, capture.output, flush.console, read.table, write.table,
35+
str, tail, type.convert)
3636
importFrom(digest, digest)
3737

3838
importFrom(S4Vectors, DataFrame, SimpleList)

R/ConvVCF2GDS.R

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -841,23 +841,50 @@ seqVCF2GDS <- function(vcf.fn, out.fn, header=NULL,
841841
# unlimit the last one
842842
psplit[[2L]][length(psplit[[2L]])] <- -1L
843843

844+
# show information
845+
update_info <- function(i)
846+
{
847+
.cat(" |> ", i, " [", .tm(), " done]")
848+
flush.console()
849+
NULL
850+
}
851+
if (!isTRUE(verbose)) update_info <- "none"
852+
853+
# reset memory before calling parallel
854+
gc(FALSE, reset=TRUE, full=TRUE)
855+
844856
# conversion in parallel
845857
seqParallel(parallel, NULL, FUN = function(
846858
vcf.fn, header, storage.option, info.import, fmt.import,
847859
genotype.var.name, ignore.chr.prefix, scenario, optim,
848860
raise.err, ptmpfn, psplit, variant_count)
849861
{
850862
i <- process_index # the process id, starting from one
851-
SeqArray::seqVCF2GDS(vcf.fn, ptmpfn[i], header=oldheader,
852-
storage.option=storage.option, info.import=info.import,
853-
fmt.import=fmt.import, genotype.var.name=genotype.var.name,
854-
ignore.chr.prefix=ignore.chr.prefix,
855-
start = psplit[[1L]][i], count = psplit[[2L]][i],
856-
variant_count=variant_count,
857-
optimize=optim, scenario=scenario, raise.error=raise.err,
858-
digest=FALSE, parallel=FALSE, verbose=FALSE)
859-
invisible() # return
860-
}, split="none",
863+
tryCatch(
864+
{
865+
SeqArray::seqVCF2GDS(vcf.fn, ptmpfn[i], header=oldheader,
866+
storage.option=storage.option, info.import=info.import,
867+
fmt.import=fmt.import,
868+
genotype.var.name=genotype.var.name,
869+
ignore.chr.prefix=ignore.chr.prefix,
870+
start = psplit[[1L]][i], count = psplit[[2L]][i],
871+
variant_count=variant_count,
872+
optimize=optim, scenario=scenario,
873+
raise.error=raise.err,
874+
digest=FALSE, parallel=FALSE, verbose=FALSE)
875+
i # return the process index
876+
}, error = function(e) {
877+
# capture full traceback
878+
trace <- capture.output({
879+
cat("Error: ", e$message, "\n", sep="")
880+
traceback()
881+
})
882+
con <- file(paste0(ptmpfn[i], ".progress.txt"), open="at")
883+
writeLines(trace, con)
884+
close(con)
885+
stop(e$message)
886+
})
887+
}, split = "none", .combine = update_info,
861888
vcf.fn=vcf.fn, header=header, storage.option=storage.option,
862889
info.import=info.import, fmt.import=fmt.import,
863890
genotype.var.name=genotype.var.name,
@@ -876,7 +903,7 @@ seqVCF2GDS <- function(vcf.fn, out.fn, header=NULL,
876903

877904

878905
#######################################################################
879-
# create a GDS file
906+
# create a new GDS file
880907

881908
gfile <- createfn.gds(out.fn)
882909
on.exit({ if (!is.null(gfile)) closefn.gds(gfile) }, add=TRUE)

0 commit comments

Comments
 (0)