esApply               package:Biobase               R Documentation

_A_p_p_l_y _f_o_r _t_h_e _e_x_p_r_e_s_s_i_o_n _d_a_t_a _i_n _a_n _e_x_p_r_S_e_t

_D_e_s_c_r_i_p_t_i_o_n:

     esApply is a wrapper to apply for use with exprSets. Because the
     application of a function to the rows of the expression array
     usually involves variables in the 'phenoData' slot we have used a
     special evaluation paradigm here. The function 'FUN' may reference
     any data in phenoData by name.

_U_s_a_g_e:

     esApply(X, MARGIN, FUN, ...)

_A_r_g_u_m_e_n_t_s:

       X: an instance of the exprSet class of the Biobase package. It
          is assumed that 'X' has information on gene expression for G
          genes in N tissue samples. 

  MARGIN: The margin to apply to, either 1 for rows or 2 for columns.

     FUN: any function 

     ...: additional parameters for FUN.

_D_e_t_a_i_l_s:

     The 'phenoData' from 'X' is installed in an environment. This
     environment is installed as the environment of 'FUN'. This will
     then provide bindings for any symbols in 'FUN' that are the same
     as the names of the 'phenoData' of 'X'. If 'FUN' has an
     environment already it is retained but placed after the newly
     created environment. Some variable shadowing could occur under
     these circumstances.

_V_a_l_u_e:

     The result of 'apply(exprs(X),MARGIN, FUN, ...)'.

_A_u_t_h_o_r(_s):

     VJ Carey <stvjc@channing.harvard.edu>, R. Gentleman

_S_e_e _A_l_s_o:

     'apply'

_E_x_a_m_p_l_e_s:

     require(Biobase)
     data(eset)

     # we know that eset has covariates in
     # the pData called "cov1" and "cov2"
     #
     # here are two functions conforming to the esApply
     # protocol

     ##here cov1 is an unbound value, it will be resolved
     ##by using the pData

     mytt.demo <- function(y) {
      ys <- split( y, cov1 )
      t.test( ys[[1]], ys[[2]] )$p.value
      }

     myreg.demo <- function( y ) {
     # obtain the p value of the slope
     # associated with cov2, adjusting for cov1
     # (if we were concerned with sign we could
     # save the z statistic instead at coef[3,3]
     #
      summary(lm(y~cov1+cov2))$coef[3,4]
      }

     # let's try it out

     newt <- esApply( eset, 1, mytt.demo )

     # here's a resampling method 

     resamp <- function( ESET ) {
      ntiss <- ncol(exprs(ESET))
      newind <- sample(1:ntiss, size=ntiss, replace=TRUE)
      ESET[newind,]
      }

     # here's a filter

     q3g100filt <- function( eset ) {
      apply( exprs(eset), 1, function(x)quantile(x,.75)>100 )
      }

     # want to filter after resampling and then apply

     set.seed(123)
     rest <- esApply( { bool <- q3g100filt(resamp(eset)); eset[bool,] }, 1,
     mytt.demo ) 
      

