Running 'calmateByThetaAB.R' [2s]
  Running 'calmateByTotalAndFracB.R' [151s]
  Running 'fitCalMaTe.R' [180s]
  Running 'fitCalMaTeMedians.R' [1s]
  Running 'testScriptCalMaTe1.R' [173s]
  Running 'thetaAB2TotalAndFracB.R' [157s]
Running the tests in 'tests/calmateByTotalAndFracB.R' failed.
Complete output:
  > library("calmate")
  Loading required package: R.utils
  Loading required package: R.oo
  Loading required package: R.methodsS3
  R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
  R.oo v1.26.0 (2024-01-24 05:12:50 UTC) successfully loaded. See ?R.oo for help.
  
  Attaching package: 'R.oo'
  
  The following object is masked from 'package:R.methodsS3':
  
      throw
  
  The following objects are masked from 'package:methods':
  
      getClasses, getMethods
  
  The following objects are masked from 'package:base':
  
      attach, detach, load, save
  
  R.utils v2.12.3 (2023-11-18 01:00:02 UTC) successfully loaded. See ?R.utils for help.
  
  Attaching package: 'R.utils'
  
  The following object is masked from 'package:utils':
  
      timestamp
  
  The following objects are masked from 'package:base':
  
      cat, commandArgs, getOption, isOpen, nullfile, parse, use, warnings
  
  Loading required package: aroma.core
  Loading required package: R.filesets
  R.filesets v2.15.1 (2024-01-24 17:22:49 UTC) successfully loaded. See ?R.filesets for help.
  
  Attaching package: 'R.filesets'
  
  The following object is masked from 'package:R.utils':
  
      validate
  
  The following objects are masked from 'package:base':
  
      append, readLines
  
  Loading required package: R.devices
  R.devices v2.17.2 (2024-01-29 13:30:11 UTC) successfully loaded. See ?R.devices for help.
  aroma.core v3.3.1 (2024-02-19 08:40:02 UTC) successfully loaded. See ?aroma.core for help.
  
  Attaching package: 'aroma.core'
  
  The following objects are masked from 'package:base':
  
      .Machine, colMeans, colSums, library, require, write
  
  calmate v0.13.0 (2022-03-08 23:00:03 UTC) successfully loaded. See ?calmate for help.
  > 
  > message("*** calmateByTotalAndFracB() ...")
  *** calmateByTotalAndFracB() ...
  > 
  > # Load example (thetaA,thetaB) signals
  > path <- system.file("exData", package="calmate")
  > theta <- loadObject("thetaAB,100x2x40.Rbin", path=path)
  > 
  > # Transform to (total,fracB) signals
  > data <- thetaAB2TotalAndFracB(theta)
  > 
  > # Calibrate (total,fracB) by CalMaTe
  > dataC <- calmateByTotalAndFracB(data)
  > 
  > # Calculate copy-number ratios
  > theta <- data[,"total",]
  > thetaR <- matrixStats::rowMedians(theta, na.rm=TRUE)
  > data[,"total",] <- 2*theta/thetaR
  > 
  > # Plot two "random" arrays
  > Clim <- c(0,4)
  > Blim <- c(0,1)
  > subplots(4, ncol=2, byrow=FALSE)
  > for (ii in c(1,5)) {
  +   sampleName <- dimnames(data)[[3]][ii]
  +   sampleLabel <- sprintf("Sample #%d ('%s')", ii, sampleName)
  +   plot(data[,,ii], xlim=Clim, ylim=Blim)
  +   title(main=sampleLabel)
  +   plot(dataC[,,ii], xlim=Clim, ylim=Blim)
  +   title(main=sprintf("%s\ncalibrated", sampleLabel))
  + }
  > 
  > 
  > # Assert that it also works with a single unit
  > dummy <- calmateByTotalAndFracB(data[1,,,drop=FALSE])
  > stopifnot(length(dim(dummy)) == 3)
  > 
  > 
  > message("*** calmateByTotalAndFracB() - misc ...")
  *** calmateByTotalAndFracB() - misc ...
  > 
  > dataT <- data[1:2,,]
  > dataU <- truncateFracB(dataT)
  > str(dataU)
   num [1:2, 1:2, 1:40] 1.982 1.548 0.395 0.652 1.702 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > stopifnot(all(dataU[,2,] >= 0))
  > 
  > dataT <- data[1:2,,1]
  > dataV <- truncateFracB(dataT)
  > str(dataV)
   num [1:2, 1:2] 1.982 1.548 0.395 0.652
   - attr(*, "dimnames")=List of 2
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
  > stopifnot(all(dataV[,2] >= 0))
  > stopifnot(all.equal(dataV, dataU[,,1]))
  > 
  > message("*** calmateByTotalAndFracB() - misc ... DONE")
  *** calmateByTotalAndFracB() - misc ... DONE
  > 
  > 
  > message("*** calmateByTotalAndFracB(..., references) ...")
  *** calmateByTotalAndFracB(..., references) ...
  > 
  > references <- rep(TRUE, length=dim(data)[3])
  > fit1 <- calmateByTotalAndFracB(data, references=references)
  > str(fit1)
   num [1:100, 1:2, 1:40] 1.88 1.47 1.39 2.6 1.93 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > 
  > references <- 1:dim(data)[3]
  > fit2 <- calmateByTotalAndFracB(data, references=references)
  > str(fit2)
   num [1:100, 1:2, 1:40] 1.88 1.47 1.39 2.6 1.93 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > stopifnot(all.equal(fit2, fit1))
  > 
  > fit3 <- calmateByTotalAndFracB(data, refAvgFcn=matrixStats::rowMedians)
  > str(fit3)
   num [1:100, 1:2, 1:40] 1.97 1.7 1.42 2.6 1.95 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > 
  > message("*** calmateByTotalAndFracB(..., references) ... DONE")
  *** calmateByTotalAndFracB(..., references) ... DONE
  > 
  > 
  > message("*** calmateByTotalAndFracB() - exceptions ...")
  *** calmateByTotalAndFracB() - exceptions ...
  > 
  > ## Exceptions
  > dataT <- data[1,,,drop=FALSE]
  > dim(dataT) <- c(dim(dataT), 1L)
  > res <- try(fit <- calmateByTotalAndFracB(dataT))
  Error in calmateByTotalAndFracB.array(dataT) : 
    Argument 'data' is not a 3-dimensional array: 1x2x40x1
  > stopifnot(inherits(res, "try-error"))
  > 
  > dataT <- data[1,1,,drop=FALSE]
  > res <- try(fit <- calmateByTotalAndFracB(dataT))
  Error in calmateByTotalAndFracB.array(dataT) : 
    Argument 'data' is not a Jx2xI-dimensional array: 1x1x40
  > stopifnot(inherits(res, "try-error"))
  > 
  > references <- rep(TRUE, length=dim(data)[3]-1L)
  > res <- try(fit <- calmateByTotalAndFracB(data, references=references))
  Error in calmateByTotalAndFracB.array(data, references = references) : 
    Length of argument 'references' does not match the number of samples in argument 'data': 39 != 40
  > stopifnot(inherits(res, "try-error"))
  > 
  > references <- seq_len(dim(data)[3]+1L)
  > res <- try(fit <- calmateByTotalAndFracB(data, references=references))
  Error in calmateByTotalAndFracB.array(data, references = references) : 
    Argument 'references' is out of range [1,40]: 41
  > stopifnot(inherits(res, "try-error"))
  > 
  > message("*** calmateByTotalAndFracB() - exceptions ... DONE")
  *** calmateByTotalAndFracB() - exceptions ... DONE
  > 
  > message("*** calmateByTotalAndFracB() ... DONE")
  *** calmateByTotalAndFracB() ... DONE
  > 
  > proc.time()
     user  system elapsed 
     2.92    0.28    3.20 
Running the tests in 'tests/fitCalMaTe.R' failed.
Complete output:
  > library("calmate")
  Loading required package: R.utils
  Loading required package: R.oo
  Loading required package: R.methodsS3
  R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
  R.oo v1.26.0 (2024-01-24 05:12:50 UTC) successfully loaded. See ?R.oo for help.
  
  Attaching package: 'R.oo'
  
  The following object is masked from 'package:R.methodsS3':
  
      throw
  
  The following objects are masked from 'package:methods':
  
      getClasses, getMethods
  
  The following objects are masked from 'package:base':
  
      attach, detach, load, save
  
  R.utils v2.12.3 (2023-11-18 01:00:02 UTC) successfully loaded. See ?R.utils for help.
  
  Attaching package: 'R.utils'
  
  The following object is masked from 'package:utils':
  
      timestamp
  
  The following objects are masked from 'package:base':
  
      cat, commandArgs, getOption, isOpen, nullfile, parse, use, warnings
  
  Loading required package: aroma.core
  Loading required package: R.filesets
  R.filesets v2.15.1 (2024-01-24 17:22:49 UTC) successfully loaded. See ?R.filesets for help.
  
  Attaching package: 'R.filesets'
  
  The following object is masked from 'package:R.utils':
  
      validate
  
  The following objects are masked from 'package:base':
  
      append, readLines
  
  Loading required package: R.devices
  R.devices v2.17.2 (2024-01-29 13:30:11 UTC) successfully loaded. See ?R.devices for help.
  aroma.core v3.3.1 (2024-02-19 08:40:02 UTC) successfully loaded. See ?aroma.core for help.
  
  Attaching package: 'aroma.core'
  
  The following objects are masked from 'package:base':
  
      .Machine, colMeans, colSums, library, require, write
  
  calmate v0.13.0 (2022-03-08 23:00:03 UTC) successfully loaded. See ?calmate for help.
  > 
  > message("*** fitCalMaTe() ...")
  *** fitCalMaTe() ...
  > 
  > # Load example (thetaA,thetaB) signals
  > path <- system.file("exData", package="calmate")
  > theta <- loadObject("thetaAB,100x2x40.Rbin", path=path)
  > 
  > theta1 <- theta[1,,]
  > references <- 1:10
  > 
  > for (flavor in c("v1", "v2")) {
  +   message(sprintf(" - fitCalMaTe(..., flavor='%s') ...", flavor))
  +   fit <- fitCalMaTe(theta1, references=references, flavor=flavor)
  +   str(fit)
  +   stopifnot(all.equal(dim(fit), dim(theta1)))
  +   message(sprintf(" - fitCalMaTe(..., flavor='%s') ... DONE", flavor))
  + }
   - fitCalMaTe(..., flavor='v1') ...
   num [1:2, 1:40] 1.75 -5.32e-17 1.56 -4.18e-17 1.99 ...
   - attr(*, "dimnames")=List of 2
    ..$ : NULL
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
   - fitCalMaTe(..., flavor='v1') ... DONE
   - fitCalMaTe(..., flavor='v2') ...
   num [1:2, 1:40] 1.255 0.4 1.432 0.111 2.005 ...
   - attr(*, "dimnames")=List of 2
    ..$ : NULL
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
   - fitCalMaTe(..., flavor='v2') ... DONE
  > 
  > message("*** fitCalMaTe() ... DONE")
  *** fitCalMaTe() ... DONE
  > 
  > proc.time()
     user  system elapsed 
     0.85    0.18    1.03 
Running the tests in 'tests/testScriptCalMaTe1.R' failed.
Complete output:
  > #CalMaTe's Test Script
  > # - - - - - - - - - - - - - - - - - - - - - - -
  > # load the test data
  > #  \item{data}{An Jx2xI @numeric array, where J is the number of SNPs,
  > #          2 is the number of alleles, and I is the number of samples.}
  > #
  > # In this case, the variable data has the J=100 SNPs in the I=40 samples
  > # used in the manuscript
  > # - - - - - - - - - - - - - - - - - - - - - - -
  > library("calmate");
  Loading required package: R.utils
  Loading required package: R.oo
  Loading required package: R.methodsS3
  R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
  R.oo v1.26.0 (2024-01-24 05:12:50 UTC) successfully loaded. See ?R.oo for help.
  
  Attaching package: 'R.oo'
  
  The following object is masked from 'package:R.methodsS3':
  
      throw
  
  The following objects are masked from 'package:methods':
  
      getClasses, getMethods
  
  The following objects are masked from 'package:base':
  
      attach, detach, load, save
  
  R.utils v2.12.3 (2023-11-18 01:00:02 UTC) successfully loaded. See ?R.utils for help.
  
  Attaching package: 'R.utils'
  
  The following object is masked from 'package:utils':
  
      timestamp
  
  The following objects are masked from 'package:base':
  
      cat, commandArgs, getOption, isOpen, nullfile, parse, use, warnings
  
  Loading required package: aroma.core
  Loading required package: R.filesets
  R.filesets v2.15.1 (2024-01-24 17:22:49 UTC) successfully loaded. See ?R.filesets for help.
  
  Attaching package: 'R.filesets'
  
  The following object is masked from 'package:R.utils':
  
      validate
  
  The following objects are masked from 'package:base':
  
      append, readLines
  
  Loading required package: R.devices
  R.devices v2.17.2 (2024-01-29 13:30:11 UTC) successfully loaded. See ?R.devices for help.
  aroma.core v3.3.1 (2024-02-19 08:40:02 UTC) successfully loaded. See ?aroma.core for help.
  
  Attaching package: 'aroma.core'
  
  The following objects are masked from 'package:base':
  
      .Machine, colMeans, colSums, library, require, write
  
  calmate v0.13.0 (2022-03-08 23:00:03 UTC) successfully loaded. See ?calmate for help.
  > 
  > # Load example (thetaA,thetaB) signals
  > path <- system.file("exData", package="calmate");
  > theta <- loadObject("thetaAB,100x2x40.Rbin", path=path);
  > 
  > # Scaling the initial data to CN scale
  > thetaR <- matrixStats::rowMedians(theta[,"A",] + theta[,"B",], na.rm=TRUE);
  > C <- 2*theta/thetaR;
  > 
  > # Transform to (total,fracB) signals
  > data <- thetaAB2TotalAndFracB(theta);
  > 
  > # It returns a list where the elements of the list are the SNPs and
  > # their total copy number and fracB
  > dataC <- calmateByTotalAndFracB(data);
  > 
  > # Allele-specific copy numbers after CalMaTe
  > CC <- C;
  > CC[,"A",] <- dataC[,"total",]*(1-dataC[,"fracB",]);
  > CC[,"B",] <- dataC[,"total",] - CC[,"A",];
  > 
  > 
  > if (interactive()) {
  +   devNew(type="x11", aspectRatio=1.9);
  + } else {
  +   devNew(type="png", "test-testScriptCalMaTe.png", aspectRatio=1.9);
  + }
  > 
  > subplots(2, ncol=1, byrow=FALSE);
  > par(mar=c(3,3,1,1)+0.1, mgp=c(1.8,0.7,0));
  > 
  > # Comparing allele-specific copy numbers before and after CalMaTe
  > # calibration for Sample #3
  > ii <- 3;
  > Clim <- c(-0.2,3);
  > plot(C[,,ii], xlim=Clim, ylim=Clim);
  > points(CC[,,ii], col="blue");
  > 
  > # Comparing BAFs before and after CalMaTe calibration for Sample #3.
  > ii <- 3;
  > plot(data[,"fracB",ii], ylab="BAF", ylim=c(0,1));
  > points(dataC[,"fracB",ii], col="blue");
  > 
  > devDone();
  > 
  > proc.time()
     user  system elapsed 
     1.53    0.12    1.65 
Running the tests in 'tests/thetaAB2TotalAndFracB.R' failed.
Complete output:
  > library("calmate")
  Loading required package: R.utils
  Loading required package: R.oo
  Loading required package: R.methodsS3
  R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
  R.oo v1.26.0 (2024-01-24 05:12:50 UTC) successfully loaded. See ?R.oo for help.
  
  Attaching package: 'R.oo'
  
  The following object is masked from 'package:R.methodsS3':
  
      throw
  
  The following objects are masked from 'package:methods':
  
      getClasses, getMethods
  
  The following objects are masked from 'package:base':
  
      attach, detach, load, save
  
  R.utils v2.12.3 (2023-11-18 01:00:02 UTC) successfully loaded. See ?R.utils for help.
  
  Attaching package: 'R.utils'
  
  The following object is masked from 'package:utils':
  
      timestamp
  
  The following objects are masked from 'package:base':
  
      cat, commandArgs, getOption, isOpen, nullfile, parse, use, warnings
  
  Loading required package: aroma.core
  Loading required package: R.filesets
  R.filesets v2.15.1 (2024-01-24 17:22:49 UTC) successfully loaded. See ?R.filesets for help.
  
  Attaching package: 'R.filesets'
  
  The following object is masked from 'package:R.utils':
  
      validate
  
  The following objects are masked from 'package:base':
  
      append, readLines
  
  Loading required package: R.devices
  R.devices v2.17.2 (2024-01-29 13:30:11 UTC) successfully loaded. See ?R.devices for help.
  aroma.core v3.3.1 (2024-02-19 08:40:02 UTC) successfully loaded. See ?aroma.core for help.
  
  Attaching package: 'aroma.core'
  
  The following objects are masked from 'package:base':
  
      .Machine, colMeans, colSums, library, require, write
  
  calmate v0.13.0 (2022-03-08 23:00:03 UTC) successfully loaded. See ?calmate for help.
  > 
  > message("*** thetaAB2TotalAndFracB() ...")
  *** thetaAB2TotalAndFracB() ...
  > 
  > # Load example (thetaA,thetaB) signals
  > path <- system.file("exData", package="calmate")
  > theta <- loadObject("thetaAB,100x2x40.Rbin", path=path)
  > 
  > data <- thetaAB2TotalAndFracB(theta)
  > str(data)
   num [1:100, 1:2, 1:40] 8724 3479 3327 2894 5256 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "total" "fracB"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > 
  > theta2 <- totalAndFracB2ThetaAB(data)
  > str(theta2)
   num [1:100, 1:2, 1:40] 5282 1212 1143 1362 4768 ...
   - attr(*, "dimnames")=List of 3
    ..$ : NULL
    ..$ : chr [1:2] "A" "B"
    ..$ : chr [1:40] "GSM318728" "GSM318729" "GSM318730" "GSM318731" ...
  > 
  > stopifnot(all.equal(theta2, theta))
  > 
  > ## Exceptions
  > thetaT <- theta
  > dim(thetaT) <- c(dim(theta), 1L)
  > res <- try(dataT <- thetaAB2TotalAndFracB(thetaT))
  Error in thetaAB2TotalAndFracB.array(thetaT) : 
    Argument 'data' is not a 3-dimensional array: 100x2x40x1
  > stopifnot(inherits(res, "try-error"))
  > 
  > thetaT <- theta[,1,,drop=FALSE]
  > res <- try(dataT <- thetaAB2TotalAndFracB(thetaT))
  Error in thetaAB2TotalAndFracB.array(thetaT) : 
    Argument 'data' is not a Jx2xI-dimensional array: 100x1x40
  > stopifnot(inherits(res, "try-error"))
  > 
  > dataT <- data
  > dim(dataT) <- c(dim(data), 1L)
  > res <- try(thetaT <- totalAndFracB2ThetaAB(dataT))
  Error in totalAndFracB2ThetaAB.array(dataT) : 
    Argument 'data' is not a 3-dimensional array: 100x2x40x1
  > stopifnot(inherits(res, "try-error"))
  > 
  > dataT <- data[,1,,drop=FALSE]
  > res <- try(thetaT <- totalAndFracB2ThetaAB(dataT))
  Error in totalAndFracB2ThetaAB.array(dataT) : 
    Argument 'data' is not a Jx2xI-dimensional array: 100x1x40
  > stopifnot(inherits(res, "try-error"))
  > 
  > message("*** thetaAB2TotalAndFracB() ... DONE")
  *** thetaAB2TotalAndFracB() ... DONE
  > 
  > proc.time()
     user  system elapsed 
     0.84    0.25    1.06