R Under development (unstable) (2024-02-16 r85931 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("PSCBS") PSCBS v0.67.0 successfully loaded. See ?PSCBS for help. > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > # Simulating copy-number data > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > set.seed(0xBEEF) > > # Number of loci > J <- 1000 > > mu <- double(J) > mu[200:300] <- mu[200:300] + 1 > mu[350:400] <- NA # centromere > mu[650:800] <- mu[650:800] - 1 > eps <- rnorm(J, sd=1/2) > y <- mu + eps > x <- sort(runif(length(y), max=length(y))) * 1e5 > w <- runif(J) > w[650:800] <- 0.001 > > ## Create multiple chromosomes > data <- knownSegments <- list() > for (cc in 1:3) { + data[[cc]] <- data.frame(chromosome=cc, y=y, x=x) + knownSegments[[cc]] <- data.frame( + chromosome=c( cc, cc, cc), + start =x[c( 1, 350, 401)], + end =x[c(349, 400, J)] + ) + } > data <- Reduce(rbind, data) > str(data) 'data.frame': 3000 obs. of 3 variables: $ chromosome: int 1 1 1 1 1 1 1 1 1 1 ... $ y : num 0.295 0.115 -0.194 -0.392 -0.518 ... $ x : num 55168 593204 605649 630624 746896 ... > knownSegments <- Reduce(rbind, knownSegments) > str(knownSegments) 'data.frame': 9 obs. of 3 variables: $ chromosome: int 1 1 1 2 2 2 3 3 3 $ start : num 55168 34194740 41080533 55168 34194740 ... $ end : num 34142178 41044125 99910827 34142178 41044125 ... > > message("*** segmentByCBS() via futures ...") *** segmentByCBS() via futures ... > > > message("*** segmentByCBS() via futures with 'future' attached ...") *** segmentByCBS() via futures with 'future' attached ... > library("future") > oplan <- plan() > > strategies <- c("sequential", "multisession") > > ## Test 'future.batchtools' futures? > pkg <- "future.batchtools" > if (require(pkg, character.only=TRUE)) { + strategies <- c(strategies, "batchtools_local") + } Loading required package: future.batchtools Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'future.batchtools' > > message("Future strategies to test: ", paste(sQuote(strategies), collapse=", ")) Future strategies to test: 'sequential', 'multisession' > > fits <- list() > for (strategy in strategies) { + message(sprintf("- segmentByCBS() using '%s' futures ...", strategy)) + plan(strategy) + fit <- segmentByCBS(data, seed=0xBEEF, verbose=TRUE) + fits[[strategy]] <- fit + stopifnot(all.equal(fit, fits[[1]])) + } - segmentByCBS() using 'sequential' futures ... Segmenting by CBS... Segmenting multiple chromosomes... Number of chromosomes: 3 Random seed temporarily set (seed=c(48879), kind="L'Ecuyer-CMRG") Produced 3 seeds from this stream for future usage Chromosome #1 ('Chr01') of 3... Segmenting by CBS... Chromosome: 1 Random seed temporarily set (seed=c(10407, 1066287653, -51199871, 161854402, -1995183193, 1503453565, -747102133), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Chromosome #1 ('Chr01') of 3...done Chromosome #2 ('Chr02') of 3... Segmenting by CBS... Chromosome: 2 Random seed temporarily set (seed=c(10407, 1797822437, 388243314, 91406689, -519578635, -1381924756, 1089253019), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Chromosome #2 ('Chr02') of 3...done Chromosome #3 ('Chr03') of 3... Segmenting by CBS... Chromosome: 3 Random seed temporarily set (seed=c(10407, -821273412, -52578226, 1415511586, 721384351, -665928286, 1316562960), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Chromosome #3 ('Chr03') of 3...done Segmenting multiple chromosomes...done Segmenting by CBS...done list() - segmentByCBS() using 'multisession' futures ... Segmenting by CBS... Segmenting multiple chromosomes... Number of chromosomes: 3 Random seed temporarily set (seed=c(48879), kind="L'Ecuyer-CMRG") Produced 3 seeds from this stream for future usage Chromosome #1 ('Chr01') of 3... Chromosome #1 ('Chr01') of 3...done Chromosome #2 ('Chr02') of 3... Chromosome #2 ('Chr02') of 3...done Chromosome #3 ('Chr03') of 3... Random seed temporarily set (seed=c(10407, 1066287653, -51199871, 161854402, -1995183193, 1503453565, -747102133), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Random seed temporarily set (seed=c(10407, 1797822437, 388243314, 91406689, -519578635, -1381924756, 1089253019), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Chromosome #3 ('Chr03') of 3...done Segmenting by CBS... Chromosome: 3 Random seed temporarily set (seed=c(10407, -821273412, -52578226, 1415511586, 721384351, -665928286, 1316562960), kind="L'Ecuyer-CMRG") Segmenting by CBS...done Segmenting multiple chromosomes...done Segmenting by CBS...done list() > > > message("*** segmentByCBS() via futures with known segments ...") *** segmentByCBS() via futures with known segments ... > fits <- list() > dataT <- subset(data, chromosome == 1) > for (strategy in strategies) { + message(sprintf("- segmentByCBS() w/ known segments using '%s' futures ...", strategy)) + plan(strategy) + fit <- segmentByCBS(dataT, knownSegments=knownSegments, seed=0xBEEF, verbose=TRUE) + fits[[strategy]] <- fit + stopifnot(all.equal(fit, fits[[1]])) + } - segmentByCBS() w/ known segments using 'sequential' futures ... Segmenting by CBS... Chromosome: 1 Random seed temporarily set (seed=c(48879), kind="L'Ecuyer-CMRG") Produced 3 seeds from this stream for future usage Segmenting by CBS...done list() - segmentByCBS() w/ known segments using 'multisession' futures ... Segmenting by CBS... Chromosome: 1 Random seed temporarily set (seed=c(48879), kind="L'Ecuyer-CMRG") Produced 3 seeds from this stream for future usage Segmenting by CBS...done list() > > message("*** segmentByCBS() via futures ... DONE") *** segmentByCBS() via futures ... DONE > > > ## Cleanup > plan(oplan) > rm(list=c("fits", "dataT", "data", "fit")) > > > proc.time() user system elapsed 1.59 0.12 4.28