[BioC] trouble hacking plotPCA

Martin Morgan mtmorgan at fhcrc.org
Thu Dec 14 20:32:16 CET 2006


Jenny et al.,

Just wanted to temper enthusiasm a bit for (1). It means that you lock
yourself into 'your' version of the package, so when Jim updates some
other part you'll either have to stick with your modified package and
not get the benefits of Jim's change, or 'port' your customizations to
Jim's update.

A marginally better approach might be to place your customizations
into a file that you then 'source', but provide access to the 'hidden'
functions, e.g., in the file you're going to source change references
to pca.legend to affycoretools:::pca.legend. Usually there are at most
a couple of such references in a typical function. Now you're only
locked into a particular version of JDplotPCA, at least until Jim
decides he'd rather name pca.legend legend.of.pca (which is his
prerogative, since the function isn't 'public'). This kind of solution
can be problematic when a function inside a package is the one that
calls the one you're trying to modify -- in some circumstance it will
see the package version of the function before it sees yours.

All of this is quite messy.

Martin

Jenny Drnevich <drnevich at uiuc.edu> writes:

> Hi Jim,
>
> I thought it might have something to do with namespaces. All those links 
> you sent in response to Naomi's query are just what I've been needing as 
> well - thanks again. I would like to be able to do alternative #1 below, 
> and I think I know what to do, and my PC is capable of installing packages 
> - just have to take time to try it. I would like to see plotPCA function on 
> matrices, and if you agree then it would also be good to add this 
> functionality for everyone. I'll try to bumble through it on my own, but if 
> I hit a wall, do you mind if I contact you for advice? On- or off-list?
>
> Thanks,
> Jenny
>
> At 07:04 PM 12/13/2006, James W. MacDonald wrote:
>>Hi Jenny,
>>
>>Ha Ha, you can't foil my anti-hack barrier code! ;-D
>>
>>Actually, I use a namespace, so when you hack plotPCA() and dump it into 
>>your .GlobalEnv, it is no longer part of the affycoretools namespace and 
>>thus can't find helper functions that are sealed in the namespace.
>>
>>The alternatives are:
>>1.) Make the hacks to the source package and then install using R CMD INSTALL
>>2.) Wait until tomorrow when I can make the changes and send you the 
>>package. I would normally have you wait until it propagates through the 
>>build process, but annaffy is busted and keeping affycoretools from 
>>building, so no propagation for me ;-(
>>
>>Let me know your preference.
>>
>>Best,
>>
>>Jim
>>
>>Jenny Drnevich wrote:
>>>Hi Jim,
>>>I was trying to modify 'plotPCA' so it could take a matrix instead of an 
>>>exprSet object, but in doing so somehow R can't find the function 
>>>'pca.legend', even though it pulls up the documentation for it when I 
>>>query '?pca.legend". I didn't even touch the code that had to do with 
>>>'pca.legend'! Any ideas why and/or what I can do to get the legend?  Code 
>>>and sessionInfo() below.
>>>Thanks,
>>>Jenny
>>>
>>>  >plotPCA(rma.data)
>>># no problem with this - the legend was fine
>>>  > source("C:/Statistics/JDplotPCA.R")
>>>  > JDplotPCA(exprs(rma.data))
>>>Error in JDplotPCA(exprs(rma.data)) : could not find function "pca.legend"
>>>  > JDplotPCA
>>>function (eset, groups = NULL, groupnames = NULL, addtext = NULL,
>>>      x.coord = NULL, y.coord = NULL, screeplot = FALSE, squarepca = FALSE,
>>>      pch = NULL, col = NULL, ...)
>>>{
>>>      require(affycoretools)
>>>      if (is.null(groupnames))
>>>          groupnames <- colnames(eset)
>>>      if (is.factor(groupnames))
>>>          groupnames <- as.character(groupnames)
>>>      pca <- prcomp(t(eset))
>>>      if (screeplot) {
>>>          plot(pca, main = "Screeplot")
>>>      }
>>>      else {
>>>          if (squarepca) {
>>>              ylim <- max(abs(range(pca$x[, 1])))
>>>              ylim <- c(-ylim, ylim)
>>>          }
>>>          else ylim <- NULL
>>>          if (!is.null(groups)) {
>>>              if (is.null(pch))
>>>                  pch <- groups
>>>              if (is.null(col))
>>>                  col <- groups
>>>              plot(pca$x[, 1:2], pch = pch, col = col, ylab = "PC2",
>>>                  xlab = "PC1", main = "Principal Components Plot",
>>>                  ylim = ylim, ...)
>>>          }
>>>          else {
>>>              if (is.null(pch))
>>>                  pch <- 0:length(colnames(eset))
>>>              if (is.null(col))
>>>                  col <- 1:length(colnames(eset))
>>>              plot(pca$x[, 1:2], pch = pch, col = col, ylab = "PC2",
>>>                  xlab = "PC1", main = "Principal Components Plot",
>>>                  ylim = ylim, ...)
>>>          }
>>>          if (is.null(addtext)) {
>>>              pca.legend(pca, groupnames, pch, col, x.coord = x.coord,
>>>                  y.coord = y.coord, ...)
>>>          }
>>>          else {
>>>              smidge <- pca.legend(pca, groupnames, pch, col, x.coord = 
>>> x.coord,
>>>                  y.coord = y.coord, saveup = TRUE, ...)
>>>              text(pca$x[, 1], pca$x[, 2] + smidge, label = addtext,
>>>                  cex = 0.7)
>>>          }
>>>      }
>>>}
>>>  > sessionInfo()
>>>R version 2.4.0 (2006-10-03)
>>>i386-pc-mingw32
>>>locale:
>>>LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
>>>States.1252;LC_MONETARY=English_United 
>>>States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>>attached base packages:
>>>[1] "splines"   "tools"     "methods"   "stats"     "graphics"  "grDevices"
>>>[7] "utils"     "datasets"  "base"
>>>other attached packages:
>>>   affyQCReport    simpleaffy         made4 scatterplot3d          ade4
>>>       "1.12.0"       "2.8.0"       "1.8.0"      "0.3-24"       "1.4-2"
>>>        affyPLM         gcrma   matchprobes      affydata affycoretools
>>>       "1.10.0"       "2.6.0"       "1.6.0"      "1.10.0"       "1.6.0"
>>>        biomaRt         RCurl           XML       GOstats      Category
>>>        "1.8.0"       "0.7-0"       "1.2-0"       "2.0.3"       "2.0.3"
>>>     genefilter      survival          KEGG          RBGL      annotate
>>>       "1.12.0"        "2.29"      "1.14.1"      "1.10.0"      "1.12.0"
>>>             GO         graph         limma          affy        affyio
>>>       "1.14.1"      "1.12.0"       "2.9.1"      "1.12.1"       "1.2.0"
>>>        Biobase       RWinEdt
>>>       "1.12.2"       "1.7-5"
>>>Jenny Drnevich, Ph.D.
>>>Functional Genomics Bioinformatics Specialist
>>>W.M. Keck Center for Comparative and Functional Genomics
>>>Roy J. Carver Biotechnology Center
>>>University of Illinois, Urbana-Champaign
>>>330 ERML
>>>1201 W. Gregory Dr.
>>>Urbana, IL 61801
>>>USA
>>>ph: 217-244-7355
>>>fax: 217-265-5066
>>>e-mail: drnevich at uiuc.edu
>>>_______________________________________________
>>>Bioconductor mailing list
>>>Bioconductor at stat.math.ethz.ch
>>>https://stat.ethz.ch/mailman/listinfo/bioconductor
>>>Search the archives: 
>>>http://news.gmane.org/gmane.science.biology.informatics.conductor
>>
>>
>>--
>>James W. MacDonald
>>University of Michigan
>>Affymetrix and cDNA Microarray Core
>>1500 E Medical Center Drive
>>Ann Arbor MI 48109
>>734-647-5623
>>
>>
>>
>>**********************************************************
>>Electronic Mail is not secure, may not be read every day, and should not 
>>be used for urgent or sensitive issues.
>
> Jenny Drnevich, Ph.D.
>
> Functional Genomics Bioinformatics Specialist
> W.M. Keck Center for Comparative and Functional Genomics
> Roy J. Carver Biotechnology Center
> University of Illinois, Urbana-Champaign
>
> 330 ERML
> 1201 W. Gregory Dr.
> Urbana, IL 61801
> USA
>
> ph: 217-244-7355
> fax: 217-265-5066
> e-mail: drnevich at uiuc.edu
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Martin T. Morgan
Bioconductor / Computational Biology
http://bioconductor.org



More information about the Bioconductor mailing list