From 260e0ad715944cffce7b3fa32da05ea05eca9efb Mon Sep 17 00:00:00 2001 From: einarr Date: Sat, 5 Mar 2011 13:49:15 +0000 Subject: [PATCH] First attemt on laydi R package. --- R/laydi.R | 10 ++-- R/laydi/DESCRIPTION | 10 ++++ R/laydi/R/laydi.R | 30 ++++++++++ R/laydi/man/laydi-package.Rd | 39 +++++++++++++ R/laydi/man/write.ftsv.Rd | 105 +++++++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 R/laydi/DESCRIPTION create mode 100644 R/laydi/R/laydi.R create mode 100644 R/laydi/man/laydi-package.Rd create mode 100644 R/laydi/man/write.ftsv.Rd diff --git a/R/laydi.R b/R/laydi.R index 54f878a..22d1fa3 100644 --- a/R/laydi.R +++ b/R/laydi.R @@ -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) } diff --git a/R/laydi/DESCRIPTION b/R/laydi/DESCRIPTION new file mode 100644 index 0000000..3f8af87 --- /dev/null +++ b/R/laydi/DESCRIPTION @@ -0,0 +1,10 @@ +Package: laydi +Type: Package +Title: Interface to Laydi +Version: 1.0 +Date: 2011-03-05 +Author: Einar Ryeng +Maintainer: Einar Ryeng +Description: R interface to Laydi +License: LGPL +LazyLoad: yes diff --git a/R/laydi/R/laydi.R b/R/laydi/R/laydi.R new file mode 100644 index 0000000..22d1fa3 --- /dev/null +++ b/R/laydi/R/laydi.R @@ -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) +} + + diff --git a/R/laydi/man/laydi-package.Rd b/R/laydi/man/laydi-package.Rd new file mode 100644 index 0000000..50938bd --- /dev/null +++ b/R/laydi/man/laydi-package.Rd @@ -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 +Arnar Flatberg + +Maintainer: Einar Ryeng +} +\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[:-package]{}} ~~ +} +\examples{ +~~ simple examples of the most important functions ~~ +} diff --git a/R/laydi/man/write.ftsv.Rd b/R/laydi/man/write.ftsv.Rd new file mode 100644 index 0000000..256e0f3 --- /dev/null +++ b/R/laydi/man/write.ftsv.Rd @@ -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