HenrikBengtsson / PSCBS

🔬 R package: Analysis of Parent-Specific DNA Copy Numbers
https://cran.r-project.org/package=PSCBS
7 stars 4 forks source link

plotTracks() for multi-chromosome CBS objects gives error on "Argument 'Clim' is not a vector: NULL" #43

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

For multi-chromosome CBS data, not single as in the vignette, plotTracks() will produce an error on "Argument 'Clim' is not a vector: NULL".

Example

library("PSCBS")

## Create a Chr1 & Chr2 data set
data <- PSCBS::exampleData("paired.chr01")
data <- data[, c("chromosome", "x", "CT")]
colnames(data)[3] <- "y"
tmp <- data
tmp$chromosome <- 2L
data <- rbind(data, tmp)

data <- dropSegmentationOutliers(data)
gaps <- findLargeGaps(data, minLength = 1e+06)
knownSegments <- gapsToSegments(gaps)
fit <- segmentByCBS(data, knownSegments = knownSegments, seed = 48879)

plotTracks(fit)

[2018-02-28 11:04:45] Exception: Argument 'Clim' is not a vector: NULL

  at #09. getVector.Arguments(static, x, ..., .name = .name)
          - getVector.Arguments() is in environment 'R.utils'

  at #08. getVector(static, x, ..., .name = .name)
          - getVector() is in environment 'R.utils'

  at #07. getNumerics.Arguments(static, ...)
          - getNumerics.Arguments() is in environment 'R.utils'

  at #06. getNumerics(static, ...)
          - getNumerics() is in environment 'R.utils'
          - originating from '<text>'

  at #05. Arguments$getNumerics(Clim, length = c(2L, 2L), disallow = c("Inf", 
              "NA", "NaN"))
          - Arguments$getNumerics() is local of the calling function

  at #04. plotTracksManyChromosomes.CBS(fit, scatter = scatter, pch = pch, 
              col = col, cex = cex, meanCol = meanCol, Clim = Clim, xScale = xScale, 
              Clab = Clab, ..., byIndex = byIndex, mar = mar, add = add)
          - plotTracksManyChromosomes.CBS() is in environment 'PSCBS'

  at #03. plotTracksManyChromosomes(fit, scatter = scatter, pch = pch, 
              col = col, cex = cex, meanCol = meanCol, Clim = Clim, xScale = xScale, 
              Clab = Clab, ..., byIndex = byIndex, mar = mar, add = add)
          - plotTracksManyChromosomes() is in environment 'PSCBS'

  at #02. plotTracks.CBS(fit)
          - plotTracks.CBS() is in environment 'PSCBS'

  at #01. plotTracks(fit)
          - plotTracks() is in environment 'PSCBS'

Error: Argument 'Clim' is not a vector: NULL

Workaround

Until fixed in the PSCBS package, set the Clim manually, e.g.

plotTracks(fit, Clim = c(0,5))
HenrikBengtsson commented 6 years ago

The default is Clim = "auto" which sets the Clim as:

  if (identical(Clim, "auto")) {
    signalType <- getSignalType(fit);
    ploidy <- ploidy(fit);
    Clim <- switch(signalType,
      "log2ratio" = c(-2,2) + c(-1,1)*ploidy/2,
      "ratio"     = c(0,3*ploidy),
      NULL
    );
  }

In other words, it'll decided what the default Clim is based on the signal type. In the example here, it is:

> getSignalType(fit)
[1] NA

which is why it becomes Clim = NULL.

HenrikBengtsson commented 6 years ago

Updated develop branch to:

> plotTracks(fit)
Warning in plotTracks.CBS(fit) :
  Setting default 'Clim' assuming the signal type is 'ratio' because signalType(fit) is unknown ('NA'). Use signalType(fit) <- 'ratio' to avoid this warning.