\name{as.geneSet}
\alias{as.geneSet}
\alias{as.geneSet.matrix}
\alias{as.geneSet.data.frame}
\title{Convert an existing object to a geneSet}
\description{
  Convert an existing object to a geneSet.  Methods currenrly exist only
  for matrix and data.frame objects.
}
\usage{
\method{as.geneSet}{matrix}(x, ... )
\method{as.geneSet}{data.frame}(x,
  gene.columns,
  format=c("single", "adjacent"),
  ploidy=2,
  alleles=NULL,
  sep="/",
  remove.spaces=TRUE,
  reorder=c("freq", "yes", "no", "default", "ascii"),
  allow.partial.missing=FALSE,
  markerNames,
  phase=list(F),
  ...)

}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{x}{The matrix or data.frame object to be converted}
  \item{gene.columns}{Names or indexes of columns containing genotypes}
  \item{format}{One of "single", indiciating that each specified column
    contains a complete genotype (e.g. "A/C"), or "adjacent" indicating
    that sets of \code{ploidy} adjacent columns each contain as single
    allele (e.g. "A", "C")}
  \item{ploidy}{Number of allele copies per genotype.  Defaults to 2}
  \item{alleles}{Not currently supported.  In the future, this variable
    will allow specification of the allele strings for each genotype.} 
  \item{sep}{A character value or a numeric index vector indicating how
    allels are spearated within genotypes, defaults to "/". If a
    character, it indicates that  alleles within a genotype are
    separated by this character (e.g. for "A/C", \code{sep="/"}).  If a
    numeric vector (of length \code{ploidy}-1), the value(s) indicate
    which positions separate allele names (e.g. for "AA", \code{sep=1}).
  }
  \item{remove.spaces}{Should whitespace be removed before processing.}
  \item{reorder}{One of "freq", "yes", "no", "default", or "ascii",
    indicating whether and how alleles should be reorderd within
    genotypes.

    If \code{reorder="no"}, the observed order is preserved
    (important when phase is known).

    If \code{reorder="freq"}, sort
    alleles within each individual by observed frequency.

    If \code{reorder="yes"}, sort alleles in the order provided by the
    \code{alleles} argument.
    
    If \code{reorder="ascii"}, reorder alleles in  ASCII order
    (alphabetical, with all upper case before lower case).

    The default value is \code{"freq"}.
  }
  
  \item{allow.partial.missing}{Logical value indicating whether a
    genotype is permitted to be partially missing.  When
    \code{allow.partial.missing=FALSE}, if any individual allele
    is missing within a genotype, the entire genotype will be converted
    to a missing value.  When \code{allow.partial.missing=TRUE},
    the missingness of individual alleles will be preserved.}
  \item{markerNames}{Character vector of names to use for the genotype
    columns.  This must have the same lenght as the number of genotype
    columns. }
  \item{phase}{List indicating whether phase is known for each genotype
    column.  If the list has a single logical entry, this will apply to
    all genotype columns.}
  \item{\dots}{Optional arguments.}
}
\details{

}
\value{
  An S4 object of class geneSet
}
%\references{ ~put references to the literature/web site here ~ }
\author{Gregory R. Warnes \email{greg@random-technologies-llc.com}}
%\note{ ~~further notes~~ 
%
% ~Make other sections like Warning with \section{Warning }{....} ~
%}
\seealso{ \code{\link{geneSet}} }
\examples{


## Create a test data set where there are several genotypes in columns
## of the form "A/T".
test1 <- data.frame(Tmt=sample(c("Control","Trt1","Trt2"),20, replace=TRUE),
                G1=sample(c("A/T","T/T","T/A",NA),20, replace=TRUE),
                N1=rnorm(20),
                I1=sample(1:100,20,replace=TRUE),
                G2=paste(sample(c("134","138","140","142","146"),20,
                                replace=TRUE),
                         sample(c("134","138","140","142","146"),20,
                                replace=TRUE),
                         sep=" / "),
                G3=sample(c("A /T","T /T","T /A"),20, replace=TRUE),
                comment=sample(c("Possible Bad Data/Lab Error",""),20,
                               rep=TRUE)
                )
test1

## now automatically convert genotype columns
geno1 <- as.geneSet(test1)
geno1


}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ manip }