First attemt on laydi R package.

This commit is contained in:
Einar Ryeng 2011-03-05 13:49:15 +00:00
parent 80e64afd04
commit 260e0ad715
5 changed files with 189 additions and 5 deletions

View File

@ -1,17 +1,17 @@
write.ftsv <- function(data, con, name="unnamed_dataset", rowdim="rows", coldim="cols") {
/* If con is a file name, open it */
# If con is a file name, open it
opened.here = FALSE
if (is.character(con)){
con = file(con, "w")
opened.here = TRUE
}
/* Substitute all whitespace with underscores in identifiers */
# Substitute all whitespace with underscores in identifiers
rows <- paste(gsub("\\s", "_", rownames(data)), collapse=" ")
cols <- paste(gsub("\\s", "_", colnames(data)), collapse=" ")
/* Write header */
# Write header
writeLines(c("# type: dataset",
paste("# dimension:", rowdim, rows, collapse=' '),
paste("# dimension:", coldim, cols, collapse=' '),
@ -19,10 +19,10 @@ write.ftsv <- function(data, con, name="unnamed_dataset", rowdim="rows", coldim=
""),
con=con)
/* Write matrix */
# Write matrix
write.table(data, file=con, col.names=FALSE, row.names=FALSE, sep="\t")
/* If con was a string, close file now */
# If con was a string, close file now
if (opened.here)
close(con)
}

10
R/laydi/DESCRIPTION Normal file
View File

@ -0,0 +1,10 @@
Package: laydi
Type: Package
Title: Interface to Laydi
Version: 1.0
Date: 2011-03-05
Author: Einar Ryeng <einarr@pvv.ntnu.no>
Maintainer: Einar Ryeng <einarr@pvv.ntnu.no>
Description: R interface to Laydi
License: LGPL
LazyLoad: yes

30
R/laydi/R/laydi.R Normal file
View File

@ -0,0 +1,30 @@
write.ftsv <- function(data, con, name="unnamed_dataset", rowdim="rows", coldim="cols") {
# If con is a file name, open it
opened.here = FALSE
if (is.character(con)){
con = file(con, "w")
opened.here = TRUE
}
# Substitute all whitespace with underscores in identifiers
rows <- paste(gsub("\\s", "_", rownames(data)), collapse=" ")
cols <- paste(gsub("\\s", "_", colnames(data)), collapse=" ")
# Write header
writeLines(c("# type: dataset",
paste("# dimension:", rowdim, rows, collapse=' '),
paste("# dimension:", coldim, cols, collapse=' '),
paste("# name:", name, collapse=' '),
""),
con=con)
# Write matrix
write.table(data, file=con, col.names=FALSE, row.names=FALSE, sep="\t")
# If con was a string, close file now
if (opened.here)
close(con)
}

View File

@ -0,0 +1,39 @@
\name{laydi-package}
\alias{laydi-package}
\alias{laydi}
\docType{package}
\title{Interface to Laydi}
\description{
Interface to Laydi files and projects. Allows writing R matrices to laydi data files.
}
\details{
\tabular{ll}{
Package: \tab laydi\cr
Type: \tab Package\cr
Version: \tab 0.1.0\cr
Date: \tab 2011-03-05\cr
License: \tab LGPL\cr
LazyLoad: \tab yes\cr
}
library(laydi)
}
\author{
Einar Ryeng <einarr@pvv.org>
Arnar Flatberg <arnar.flatberg@gmail.com>
Maintainer: Einar Ryeng <einarr@pvv.org>
}
\references{
}
~~ Optionally other standard keywords, one per line, from file KEYWORDS in ~~
~~ the R documentation directory ~~
\keyword{ package }
\seealso{
~~ Optional links to other man pages, e.g. ~~
~~ \code{\link[<pkg>:<pkg>-package]{<pkg>}} ~~
}
\examples{
~~ simple examples of the most important functions ~~
}

105
R/laydi/man/write.ftsv.Rd Normal file
View File

@ -0,0 +1,105 @@
\name{write.ftsv}
\alias{write.ftsv}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
%% ~~function to do ... ~~
}
\description{
Writes a matrix to a ftsv (laydi dataset) file. The matrix must have rownames
and colnames. Rownames and colnames must be unique, and whitespace characters
will be replaced with underscores.
}
\usage{
write.ftsv(data, con, name = "unnamed_dataset", rowdim = "rows", coldim = "cols")
}
\arguments{
\item{data}{
A data matrix. All items in rownames(data) and colnames(data) must be
unique, and all whitespace characters will be replaced wity underscores in
the output. (Laydi requires unique identifiers along a dimension, and does
not allow identifiers to contain spaces.)
}
\item{con}{
Connection (or file name) to write the data to. If con is a character
string, it will be treated as a file name, and a file by that name will be
created, written to and closed. If con is an open connection (file descriptor),
the file will remain open.
}
\item{name}{
Datasets in laydi have a name.
}
\item{rowdim}{
Laydi names all dimensions of matrices. rowdim is the dimension
name for rows in the the file. E.g. "samples", if rows denotes samples.
}
\item{coldim}{
Laydi names all dimensions of matrices. coldim is the dimension
name for columns in the the file. E.g. "gene-ids" if columns represent
genes.
}
}
\details{
%% ~~ If necessary, more details than the description above ~~
}
\value{
%% ~Describe the value returned
%% If it is a LIST, use
%% \item{comp1 }{Description of 'comp1'}
%% \item{comp2 }{Description of 'comp2'}
%% ...
}
\references{
Laydi and this R package are not published in the litterature. Source code can be found at
http://dev.pvv.ntnu.no/projects/laydi
}
\author{
Einar Ryeng
}
\note{
%% ~~further notes~~
}
%% ~Make other sections like Warning with \section{Warning }{....} ~
\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(data, con, name="unnamed_dataset", rowdim="rows", coldim="cols") {
# If con is a file name, open it
opened.here = FALSE
if (is.character(con)){
con = file(con, "w")
opened.here = TRUE
}
# Substitute all whitespace with underscores in identifiers
rows <- paste(gsub("\\s", "_", rownames(data)), collapse=" ")
cols <- paste(gsub("\\s", "_", colnames(data)), collapse=" ")
# Write header
writeLines(c("# type: dataset",
paste("# dimension:", rowdim, rows, collapse=' '),
paste("# dimension:", coldim, cols, collapse=' '),
paste("# name:", name, collapse=' '),
""),
con=con)
# Write matrix
write.table(data, file=con, col.names=FALSE, row.names=FALSE, sep="\t")
# If con was a string, close file now
if (opened.here)
close(con)
}
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line