Commit f2468757 authored by Rauschenberger's avatar Rauschenberger
Browse files

automation

parent ea777429
......@@ -63,26 +63,32 @@ prepare.data.matrices <- function(Y,X){
#' @description
#' This function adjusts exon expression data for different library sizes.
#'
#' @param Y
#' matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)
#' @param x
#' matrix with \eqn{n} rows (samples) and \eqn{p} columns (variables)
#'
#' @examples
#' NA
#'
adjust.library.sizes <- function(Y){
if(!is.matrix(Y)){
stop("Argument Y is no matrix.",call.=FALSE)
adjust.library.sizes <- function(x){
if(!is.matrix(x)){
stop("no matrix argument",call.=FALSE)
}
if(!is.numeric(x)){
stop("no numeric argument",call.=FALSE)
}
if(!is.integer(x)){
warning("non-integer values",call.=FALSE)
}
if(!is.numeric(Y)){
stop("Argument Y is not numeric.",call.=FALSE)
if(any(x)<0){
warning("negative values",call.=FALSE)
}
n <- nrow(Y); p <- ncol(Y)
lib.size <- rowSums(Y)
norm.factors <- edgeR::calcNormFactors(object=t(Y),lib.size=lib.size)
n <- nrow(x); p <- ncol(x)
lib.size <- rowSums(x)
norm.factors <- edgeR::calcNormFactors(object=t(x),lib.size=lib.size)
gamma <- norm.factors*lib.size/mean(lib.size)
gamma <- matrix(gamma,nrow=n,ncol=p,byrow=FALSE)
Y <- Y/gamma
return(Y)
x <- x/gamma
return(x)
}
#' @export
......@@ -92,16 +98,14 @@ adjust.library.sizes <- function(Y){
#' @description
#' This function adjusts exon expression data for different exon lengths.
#'
#' @param Y
#' @param x
#' matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)
#'
#' @param gene
#' @param group
#' gene (not exon) names\strong{:} vector of length \eqn{p}
#'
#' @param start
#' @param offset
#' exon start positions\strong{:} vector of length \eqn{p}
#'
#' @param end
#' exon end positions\strong{:} vector of length \eqn{p}
#'
#' @details
......@@ -110,23 +114,28 @@ adjust.library.sizes <- function(Y){
#' @examples
#' NA
#'
adjust.exon.length <- function(Y,gene,start,end){
if(!is.matrix(Y)){
stop("Argument Y is no matrix.",call.=FALSE)
adjust.exon.length <- function(x,group,offset){
if(!is.numeric(x)|!is.matrix(x)){
stop("Argument \"x\" is no numeric matrix.",call.=FALSE)
}
if(!is.character(group)|!is.vector(group)){
stop("Argument \"group\" is no character vector.",call.=FALSE)
}
if(!is.numeric(offset)|!is.vector(offset)){
stop("Argument \"offset\" is no numeric vector.",call.=FALSE)
}
if(any(ncol(Y)!=c(length(gene),length(start),length(end)))){
if(ncol(x)!=length(group)|ncol(x)!=length(offset)){
stop("Contradictory dimensions.",call.=FALSE)
}
n <- nrow(Y); p <- ncol(Y); names <- dimnames(Y)
Y <- as.numeric(Y) # wrong?
x <- rep(end-start,each=n)
gene <- strsplit(gene,split=",")
gene <- sapply(gene,function(x) x[[1]][1])
gene <- rep(gene,each=n)
lmer <- lme4::lmer(Y ~ x + (1|gene))
Y <- matrix(stats::residuals(lmer),nrow=n,ncol=p,dimnames=names)
Y <- Y-min(Y)
return(Y)
n <- nrow(x); p <- ncol(x); names <- dimnames(x)
x <- as.numeric(x)
group <- strsplit(group,split=",")
group <- sapply(group,function(x) x[[1]][1])
group <- rep(group,each=n)
lmer <- lme4::lmer(x ~ offset + (1|group))
x <- matrix(stats::residuals(lmer),nrow=n,ncol=p,dimnames=names)
x <- x-min(x)
return(x)
}
#' @export
......
......@@ -120,26 +120,23 @@
</div>
<pre class="usage"><span class='fu'>adjust.exon.length</span>(<span class='no'>Y</span>, <span class='no'>gene</span>, <span class='no'>start</span>, <span class='no'>end</span>)</pre>
<pre class="usage"><span class='fu'>adjust.exon.length</span>(<span class='no'>x</span>, <span class='no'>group</span>, <span class='no'>offset</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>Y</th>
<th>x</th>
<td><p>matrix with \(n\) rows (samples) and \(p\) columns (exons)</p></td>
</tr>
<tr>
<th>gene</th>
<th>group</th>
<td><p>gene (not exon) names<strong>:</strong> vector of length \(p\)</p></td>
</tr>
<tr>
<th>start</th>
<td><p>exon start positions<strong>:</strong> vector of length \(p\)</p></td>
</tr>
<tr>
<th>end</th>
<td><p>exon end positions<strong>:</strong> vector of length \(p\)</p></td>
<th>offset</th>
<td><p>exon start positions<strong>:</strong> vector of length \(p\)
exon end positions<strong>:</strong> vector of length \(p\)</p></td>
</tr>
</table>
......
......@@ -120,14 +120,14 @@
</div>
<pre class="usage"><span class='fu'>adjust.library.sizes</span>(<span class='no'>Y</span>)</pre>
<pre class="usage"><span class='fu'>adjust.library.sizes</span>(<span class='no'>x</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>Y</th>
<td><p>matrix with \(n\) rows (samples) and \(p\) columns (exons)</p></td>
<th>x</th>
<td><p>matrix with \(n\) rows (samples) and \(p\) columns (variables)</p></td>
</tr>
</table>
......
......@@ -4,16 +4,15 @@
\alias{adjust.exon.length}
\title{Adjust exon length}
\usage{
adjust.exon.length(Y, gene, start, end)
adjust.exon.length(x, group, offset)
}
\arguments{
\item{Y}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)}
\item{x}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)}
\item{gene}{gene (not exon) names\strong{:} vector of length \eqn{p}}
\item{group}{gene (not exon) names\strong{:} vector of length \eqn{p}}
\item{start}{exon start positions\strong{:} vector of length \eqn{p}}
\item{end}{exon end positions\strong{:} vector of length \eqn{p}}
\item{offset}{exon start positions\strong{:} vector of length \eqn{p}
exon end positions\strong{:} vector of length \eqn{p}}
}
\description{
This function adjusts exon expression data for different exon lengths.
......
......@@ -4,10 +4,10 @@
\alias{adjust.library.sizes}
\title{Adjust library sizes}
\usage{
adjust.library.sizes(Y)
adjust.library.sizes(x)
}
\arguments{
\item{Y}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)}
\item{x}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (variables)}
}
\description{
This function adjusts exon expression data for different library sizes.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment