\HeaderA{as.geneSet}{Convert an existing object to a geneSet}{as.geneSet}
\methaliasA{as.geneSet.data.frame}{as.geneSet}{as.geneSet.data.frame}
\methaliasA{as.geneSet.matrix}{as.geneSet}{as.geneSet.matrix}
\keyword{manip}{as.geneSet}
\begin{Description}\relax
Convert an existing object to a geneSet.  Methods currenrly exist only
for matrix and data.frame objects.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'matrix':
as.geneSet(x, ... )
## S3 method for class 'data.frame':
as.geneSet(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),
  ...)

\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] The matrix or data.frame object to be converted
\item[\code{gene.columns}] Names or indexes of columns containing genotypes
\item[\code{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[\code{ploidy}] Number of allele copies per genotype.  Defaults to 2
\item[\code{alleles}] Not currently supported.  In the future, this variable
will allow specification of the allele strings for each genotype.
\item[\code{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[\code{remove.spaces}] Should whitespace be removed before processing.
\item[\code{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[\code{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[\code{markerNames}] Character vector of names to use for the genotype
columns.  This must have the same lenght as the number of genotype
columns. 
\item[\code{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[\code{...}] Optional arguments.
\end{ldescription}
\end{Arguments}
\begin{Value}
An S4 object of class geneSet
\end{Value}
\begin{Author}\relax
Gregory R. Warnes \email{greg@random-technologies-llc.com}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{geneSet}{geneSet}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

## 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

\end{ExampleCode}
\end{Examples}

