Accessors           package:adegenet           R Documentation(utf8)

_A_c_c_e_s_s_o_r_s _f_o_r _a_d_e_g_e_n_e_t _o_b_j_e_c_t_s

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

     An accessor is a function that allows to interact with slots of an
     object in a convenient way. Several accessors are available for
     genind or genpop objects. The operator "$" and "$<-" are used to
     access the slots, being equivalent to "@" and "@<-".

     The operator "[" can be used to access components of the matrix
     slot "@tab", returning a genind or genpop object. This syntax is
     the same as for a matrix; for instance:
      - "obj[,]" returns "obj" 
      - "obj[1:10,]" returns an object with only the first 10 genotypes
     (if "obj" is a genind) or the first 10 populations (if "obj" is a
     genpop) of "obj" 
      - "obj[1:10, 5:10]" returns an object keeping the first 10
     entities and the alleles 5 to 10.
      - "obj[nloc=c("L1","L3")]" returns an object keeping only the
     loci specified in the 'loc' argument (using generic names, not
     true names; in this example, only the first and the third locus
     would be retained)
      - "obj[1:3, drop=TRUE]" returns the first 3 genotypes/populations
     of "obj", but retaining only alleles that are present in this
     subset (as opposed to keeping all alleles of "obj", which is the
     default behavior).

     The argument 'treatOther' handles the treatment of objects in the
     '@other' slot (see details). The argument 'drop' can be set to
     TRUE to drop alleles that are no longer represented in the subset.

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

     nLoc(x, ...)
     pop(x)
     locNames(x, ...)
     ## S4 method for signature 'genind':
     locNames(x, withAlleles=FALSE, ...)
     ## S4 method for signature 'genpop':
     locNames(x, withAlleles=FALSE, ...)

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

       x: a genind or a genpop object.

withAlleles: a logical indicating whether the result should be of the
          form [locus name].[allele name], instead of [locus name].

     ...: further arguments to be passed to other methods (currently
          not used).

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

     The "[" operator can treat elements in the '@other' slot as well.
     For instance, if 'obj@other$xy' contains spatial coordinates, the
     'obj[1:3,]@other$xy' will contain the spatial coordinates of the
     genotypes (or population) 1,2 and 3. This is handled through the
     argument 'treatOther', a logical defaulting to TRUE. If set to
     FALSE, the '@other' component is not returned.

     Note that only matrix-like, vector-like and lists can be proceeded
     in '@other'. Other kind of objects will issue a warning an be
     returned as they are.

     The 'drop' argument can be set to TRUE to retain only alleles that
     are present in the subset. To achieve better control of
     polymorphism of the data, see 'isPoly'.

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

     A genind or genpop object.

_M_e_t_h_o_d_s:


     _n_L_o_c returns the number of loci of the object

     _p_o_p returns the population factor of the object, using true (as
          opposed to generic) levels.

     _p_o_p<- replacement method for the '@pop' slot of an object. The
          content of '@pop' and '@pop.names' is updated automatically.

     _l_o_c_N_a_m_e_s returns the true names of markers and/or alleles.

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

     Thibaut Jombart t.jombart@imperial.ac.uk

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

     data(nancycats)
     nancycats
     nancycats$pop

     # let's isolate populations 4 and 8
     temp <- nancycats@pop=="P04" | nancycats@pop=="P08"
     obj <- nancycats[temp,]
     obj

     truenames(obj)$pop

     # let's isolate two markers, fca23 and fca90
     nancycats$loc.names

     # they correspond to L2 and L7
     temp <- nancycats$loc.fac=="L2" | nancycats$loc.fac=="L7"
     obj <- nancycats[,temp]
     obj

     obj$loc.fac 
     obj$loc.names

     # or more simply
     nancycats[loc=c("L2","L7")]
     obj$loc.fac 
     obj$loc.names

     # using 'drop':
     truenames(nancycats[1:2])$tab
     truenames(nancycats[1:2, drop=TRUE])$tab

     # illustrate how 'other' slot is handled
     colonies <- genind2genpop(nancycats)
     colonies@other$aChar <- "This will not be proceeded"
     colonies123 <- colonies[1:3]
     colonies
     colonies@other$xy

     # illustrate pop
     obj <- nancycats[sample(1:100,10)]
     obj$pop
     obj$pop.names
     pop(obj)
     pop(obj) <- rep(c('b','a'), each=5)
     obj$pop
     obj$pop.names
     pop(obj)

     # illustrate locNames
     locNames(obj)
     locNames(obj, withAlleles=TRUE)

