Last data update: 2014.03.03

R: Functions to convert indices to x/y (and reverse)
xy2indicesR Documentation

Functions to convert indices to x/y (and reverse)

Description

Functions to convert indices to x/y (and reverse)

Usage

xy2indices(x, y, nc = NULL, cel = NULL, abatch = NULL, cdf = NULL, xy.offset = NULL)
indices2xy(i, nc = NULL, cel = NULL, abatch = NULL, cdf = NULL, xy.offset = NULL)

Arguments

x

A numeric vector of X (column) position(s) for the probes.

y

A numeric vector of Y (row) position(s) for the probes.

i

A numeric vector of indices in the AffyBatch for the probes.

nc

total number of columns on the chip. It is usually better to specify either the cdf or abatch arguments rather than the number of columns.

cel

a corresponding object of class Cel. This has been deprecated. Use abatch or cdf instead.

abatch

a corresponding object of class AffyBatch.

cdf

character - the name of the corresponding cdf package.

xy.offset

an eventual offset for the XY coordinates. See Details.

Details

The Affymetrix scanner reads data from a GeneChip by row, and exports those data to a CEL file. When we read in the CEL file data to an AffyBatch object, we store data for each GeneChip as a single column in a matrix of probe-wise intensity values.

The CDF files that Affymetrix make available for various GeneChips map individual probes to probesets based on their (x,y) coordinates on the GeneChip. Note that these coordinates are zero-based, and (x,y) is the same as (column, row). In other words, the x coordinate indicates the horizontal location of the probe, and the y coordinate indicates the vertical location of the probe. By convention, (0,0) is the coordinate location for the top left position, and (ncol-1, nrow-1) is the coordinate location of the lower right position.

For most users, the mapping of probes to probeset is handled internally by various functions (rma, espresso, etc), and in general usage it is never necessary for a user to convert probe index position in an AffyBatch to the corresponding (x,y) coordinates on the GeneChip. These functions are only useful for those who wish to know more about the internal workings of the Affymetrix GeneChip.

The parameter xy.offset is there for compatibility. For historical reasons, the xy-coordinates for the features on Affymetrix GeneChips were decided to start at 1 (one) rather than 0 (zero). One can set the offset to 1 or to 0. Unless the you _really_ know what you are doing, it is advisable to let it at the default value NULL. This way the package-wide option xy.offset is always used.

Value

A vector of indices or a two-columns matrix of Xs and Ys.

Warning

Even if one really knows what is going on, playing with the parameter xy.offset could be risky. Changing the package-wide option xy.offset appears much more sane.

Author(s)

L.

See Also

indexProbes

Examples

if (require(affydata)) {
  data(Dilution)
  pm.i <- indexProbes(Dilution, which="pm", genenames="AFFX-BioC-5_at")[[1]]
  mm.i <- indexProbes(Dilution, which="mm", genenames="AFFX-BioC-5_at")[[1]]

  pm.i.xy <- indices2xy(pm.i, abatch = Dilution)
  mm.i.xy <- indices2xy(mm.i, abatch = Dilution)

  ## and back to indices
  i.pm <- xy2indices(pm.i.xy[,1], pm.i.xy[,2], cdf = "hgu95av2cdf")
  i.mm <- xy2indices(mm.i.xy[,1], mm.i.xy[,2], cdf = "hgu95av2cdf")

  identical(pm.i, as.integer(i.pm))
  identical(mm.i, as.integer(i.mm))

  image(Dilution[1], transfo=log2)
  ## plot the pm in red
  plotLocation(pm.i.xy, col="red")
  plotLocation(mm.i.xy, col="blue")
}

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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(affy)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/affy/xy2indices.Rd_%03d_medium.png", width=480, height=480)
> ### Name: xy2indices
> ### Title: Functions to convert indices to x/y (and reverse)
> ### Aliases: xy2indices indices2xy
> ### Keywords: manip
> 
> ### ** Examples
> 
> if (require(affydata)) {
+   data(Dilution)
+   pm.i <- indexProbes(Dilution, which="pm", genenames="AFFX-BioC-5_at")[[1]]
+   mm.i <- indexProbes(Dilution, which="mm", genenames="AFFX-BioC-5_at")[[1]]
+ 
+   pm.i.xy <- indices2xy(pm.i, abatch = Dilution)
+   mm.i.xy <- indices2xy(mm.i, abatch = Dilution)
+ 
+   ## and back to indices
+   i.pm <- xy2indices(pm.i.xy[,1], pm.i.xy[,2], cdf = "hgu95av2cdf")
+   i.mm <- xy2indices(mm.i.xy[,1], mm.i.xy[,2], cdf = "hgu95av2cdf")
+ 
+   identical(pm.i, as.integer(i.pm))
+   identical(mm.i, as.integer(i.mm))
+ 
+   image(Dilution[1], transfo=log2)
+   ## plot the pm in red
+   plotLocation(pm.i.xy, col="red")
+   plotLocation(mm.i.xy, col="blue")
+ }
Loading required package: affydata
     Package    LibPath                            Item      
[1,] "affydata" "/home/ddbj/local/lib64/R/library" "Dilution"
     Title                        
[1,] "AffyBatch instance Dilution"

Warning messages:
1: replacing previous import 'AnnotationDbi::tail' by 'utils::tail' when loading 'hgu95av2cdf' 
2: replacing previous import 'AnnotationDbi::head' by 'utils::head' when loading 'hgu95av2cdf' 
3: In Dilution[1] :
  The use of abatch[i,] and abatch[i] is deprecated. Please use abatch[,i] instead.

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>