Commit 10c41a50 authored by Rauschenberger's avatar Rauschenberger
Browse files

automation

parent f2468757
# Generated by roxygen2: do not edit by hand
export(adjust.exon.length)
export(adjust.library.sizes)
export(adjust.covariates)
export(adjust.samples)
export(drop.trivial.genes)
export(map.exons)
export(map.genes)
export(map.snps)
export(prepare.data.matrices)
export(match.samples)
export(spliceQTL)
......@@ -4,64 +4,116 @@
#' Prepare data matrices
#'
#' @description
#' This function removes duplicate samples, retains overlapping samples, and
#' orders samples.
#' This function removes duplicate samples from each matrix,
#' only retains samples appearing in all matrices,
#' and brings them into the same order.
#'
#' @param Y
#' matrix with \eqn{n_y} rows (samples) and \eqn{p_y} columns (exons)
#' @param ...
#' matrices with samples in the rows and variables in the columns
#' (separated by commas)
#'
#' @param X
#' matrix with \eqn{n_x} rows (samples) and \eqn{p_x} columns (SNPs)
#' @param message
#' display messages\strong{:} logical
#'
#' @examples
#' NA
#'
prepare.data.matrices <- function(Y,X){
match.samples <- function(...,message=TRUE){
list <- list(...)
if(length(list)==1 & is.list(list[[1]])){list <- list[[1]]}
names <- names(list)
# check input
if(!is.matrix(Y)|!is.matrix(X)){
stop("Provide X and Y as matrices!",call.=FALSE)
cond <- sapply(list,function(x) !is.matrix(x))
if(any(cond)){
stop("Provide matrices!",call.=FALSE)
}
if(is.null(rownames(Y))|is.null(rownames(X))){
stop("Missing sample names!",call.=FALSE)
cond <- sapply(list,function(x) is.null(rownames(x)))
if(any(cond)){
stop("Provide row names!",call.=FALSE)
}
# remove duplicate samples
dup_y <- duplicated(rownames(Y))
dup_x <- duplicated(rownames(X))
message("Duplicates: removing ",round(100*mean(dup_y)),"% of Y.")
message("Duplicates: removing ",round(100*mean(dup_x)),"% of X.")
Y <- Y[!dup_y,]
X <- X[!dup_x,]
# remove duplicated samples
duplic <- lapply(list,function(x) duplicated(x))
for(i in seq_along(list)){
percent <- round(100*mean(duplic[[i]]))
if(message){message(percent,"% duplicates in ",names[i])}
list[[i]] <- list[[i]][!duplic[[i]],]
}
# retain overlapping samples
both <- intersect(x=rownames(Y),y=rownames(X))
message("Overlap: retaining ",round(100*mean(rownames(Y) %in% both)),"% of Y.")
message("Overlap: retaining ",round(100*mean(rownames(X) %in% both)),"% of X.")
Y <- Y[both,]
X <- X[both,]
all <- Reduce(f=intersect,x=lapply(list,rownames))
for(i in seq_along(list)){
percent <- round(100*mean(rownames(list[[i]]) %in% all))
if(message){message(percent,"% overlap in",names[i])}
list[[i]] <- list[[i]][all,]
}
# check output
if(any(duplicated(rownames(Y))) | any(duplicated(rownames(X)))){
cond <- sapply(list,function(x) any(duplicated(rownames(x))))
if(any(cond)){
stop("Duplicate samples!",call.=FALSE)
}
if(nrow(Y)!=nrow(X)){
cond <- sapply(list,function(x) nrow(x)!=nrow(list[[1]]))
if(any(cond)){
stop("Different sample sizes!",call.=FALSE)
}
if(any(rownames(Y)!=rownames(X))){
cond <- sapply(list,function(x) any(rownames(x)!=rownames(list[[1]])))
if(any(cond)){
stop("Different sample names!",call.=FALSE)
}
return(list(Y=Y,X=X))
return(list)
}
# prepare.data.matrices <- function(Y,X){
#
# # check input
# if(!is.matrix(Y)|!is.matrix(X)){
# stop("Provide X and Y as matrices!",call.=FALSE)
# }
# if(is.null(rownames(Y))|is.null(rownames(X))){
# stop("Missing sample names!",call.=FALSE)
# }
#
# # remove duplicate samples
# dup_y <- duplicated(rownames(Y))
# dup_x <- duplicated(rownames(X))
# message("Duplicates: removing ",round(100*mean(dup_y)),"% of Y.")
# message("Duplicates: removing ",round(100*mean(dup_x)),"% of X.")
# Y <- Y[!dup_y,]
# X <- X[!dup_x,]
#
# # retain overlapping samples
# both <- intersect(x=rownames(Y),y=rownames(X))
# message("Overlap: retaining ",round(100*mean(rownames(Y) %in% both)),"% of Y.")
# message("Overlap: retaining ",round(100*mean(rownames(X) %in% both)),"% of X.")
# Y <- Y[both,]
# X <- X[both,]
#
# # check output
# if(any(duplicated(rownames(Y))) | any(duplicated(rownames(X)))){
# stop("Duplicate samples!",call.=FALSE)
# }
# if(nrow(Y)!=nrow(X)){
# stop("Different sample sizes!",call.=FALSE)
# }
# if(any(rownames(Y)!=rownames(X))){
# stop("Different sample names!",call.=FALSE)
# }
#
# return(list(Y=Y,X=X))
# }
#' @export
#' @title
#' Adjust library sizes
#'
#' @description
#' This function adjusts exon expression data for different library sizes.
#' This function adjusts RNA-seq expression data for different library sizes.
#'
#' @param x
#' matrix with \eqn{n} rows (samples) and \eqn{p} columns (variables)
......@@ -69,7 +121,7 @@ prepare.data.matrices <- function(Y,X){
#' @examples
#' NA
#'
adjust.library.sizes <- function(x){
adjust.samples <- function(x){
if(!is.matrix(x)){
stop("no matrix argument",call.=FALSE)
}
......@@ -114,21 +166,22 @@ adjust.library.sizes <- function(x){
#' @examples
#' NA
#'
adjust.exon.length <- function(x,group,offset){
adjust.covariates <- function(x,offset,group){
if(!is.numeric(x)|!is.matrix(x)){
stop("Argument \"x\" is no numeric matrix.",call.=FALSE)
}
if(!is.numeric(offset)|!is.vector(offset)|any(offset<0)){
stop("Argument \"offset\" is no (positive) numeric vector.",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(ncol(x)!=length(group)|ncol(x)!=length(offset)){
stop("Contradictory dimensions.",call.=FALSE)
}
n <- nrow(x); p <- ncol(x); names <- dimnames(x)
x <- as.numeric(x)
offset <- rep(offset,each=n)
group <- strsplit(group,split=",")
group <- sapply(group,function(x) x[[1]][1])
group <- rep(group,each=n)
......
......@@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adjust exon length — adjust.exon.length • spliceQTL</title>
<title>Adjust exon length — adjust.covariates • spliceQTL</title>
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script>
......@@ -28,7 +28,7 @@
<meta property="og:title" content="Adjust exon length — adjust.exon.length" />
<meta property="og:title" content="Adjust exon length — adjust.covariates" />
<meta property="og:description" content="This function adjusts exon expression data for different exon lengths." />
<meta name="twitter:card" content="summary" />
......@@ -111,7 +111,7 @@
<div class="page-header">
<h1>Adjust exon length</h1>
<small class="dont-index">Source: <a href='https://github.com/rauschenberger/spliceQTL/blob/master/R/function.R'><code>R/function.R</code></a></small>
<div class="hidden name"><code>adjust.exon.length.Rd</code></div>
<div class="hidden name"><code>adjust.covariates.Rd</code></div>
</div>
<div class="ref-description">
......@@ -120,7 +120,7 @@
</div>
<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>
<pre class="usage"><span class='fu'>adjust.covariates</span>(<span class='no'>x</span>, <span class='no'>offset</span>, <span class='no'>group</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......@@ -129,15 +129,15 @@
<th>x</th>
<td><p>matrix with \(n\) rows (samples) and \(p\) columns (exons)</p></td>
</tr>
<tr>
<th>group</th>
<td><p>gene (not exon) names<strong>:</strong> vector of length \(p\)</p></td>
</tr>
<tr>
<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>
<tr>
<th>group</th>
<td><p>gene (not exon) names<strong>:</strong> vector of length \(p\)</p></td>
</tr>
</table>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
......
......@@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adjust library sizes — adjust.library.sizes • spliceQTL</title>
<title>Adjust library sizes — adjust.samples • spliceQTL</title>
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script>
......@@ -28,9 +28,9 @@
<meta property="og:title" content="Adjust library sizes — adjust.library.sizes" />
<meta property="og:title" content="Adjust library sizes — adjust.samples" />
<meta property="og:description" content="This function adjusts exon expression data for different library sizes." />
<meta property="og:description" content="This function adjusts RNA-seq expression data for different library sizes." />
<meta name="twitter:card" content="summary" />
......@@ -111,16 +111,16 @@
<div class="page-header">
<h1>Adjust library sizes</h1>
<small class="dont-index">Source: <a href='https://github.com/rauschenberger/spliceQTL/blob/master/R/function.R'><code>R/function.R</code></a></small>
<div class="hidden name"><code>adjust.library.sizes.Rd</code></div>
<div class="hidden name"><code>adjust.samples.Rd</code></div>
</div>
<div class="ref-description">
<p>This function adjusts exon expression data for different library sizes.</p>
<p>This function adjusts RNA-seq expression data for different library sizes.</p>
</div>
<pre class="usage"><span class='fu'>adjust.library.sizes</span>(<span class='no'>x</span>)</pre>
<pre class="usage"><span class='fu'>adjust.samples</span>(<span class='no'>x</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......
......@@ -124,18 +124,6 @@
</th>
</tr>
<tr>
<!-- -->
<td>
<p><code><a href="adjust.library.sizes.html">adjust.library.sizes()</a></code> </p>
</td>
<td><p>Adjust library sizes</p></td>
</tr><tr>
<!-- -->
<td>
<p><code><a href="adjust.exon.length.html">adjust.exon.length()</a></code> </p>
</td>
<td><p>Adjust exon length</p></td>
</tr><tr>
<!-- -->
<td>
<p><code><a href="map.genes.html">map.genes()</a></code> </p>
......@@ -168,9 +156,21 @@
</tr><tr>
<!-- -->
<td>
<p><code><a href="prepare.data.matrices.html">prepare.data.matrices()</a></code> </p>
<p><code><a href="match.samples.html">match.samples()</a></code> </p>
</td>
<td><p>Prepare data matrices</p></td>
</tr><tr>
<!-- -->
<td>
<p><code><a href="adjust.samples.html">adjust.samples()</a></code> </p>
</td>
<td><p>Adjust library sizes</p></td>
</tr><tr>
<!-- -->
<td>
<p><code><a href="adjust.covariates.html">adjust.covariates()</a></code> </p>
</td>
<td><p>Adjust exon length</p></td>
</tr>
</tbody>
</table>
......
......@@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prepare data matrices — prepare.data.matrices • spliceQTL</title>
<title>Prepare data matrices — match.samples • spliceQTL</title>
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script>
......@@ -28,10 +28,11 @@
<meta property="og:title" content="Prepare data matrices — prepare.data.matrices" />
<meta property="og:title" content="Prepare data matrices — match.samples" />
<meta property="og:description" content="This function removes duplicate samples, retains overlapping samples, and
orders samples." />
<meta property="og:description" content="This function removes duplicate samples from each matrix,
only retains samples appearing in all matrices,
and brings them into the same order." />
<meta name="twitter:card" content="summary" />
......@@ -112,28 +113,30 @@ orders samples." />
<div class="page-header">
<h1>Prepare data matrices</h1>
<small class="dont-index">Source: <a href='https://github.com/rauschenberger/spliceQTL/blob/master/R/function.R'><code>R/function.R</code></a></small>
<div class="hidden name"><code>prepare.data.matrices.Rd</code></div>
<div class="hidden name"><code>match.samples.Rd</code></div>
</div>
<div class="ref-description">
<p>This function removes duplicate samples, retains overlapping samples, and
orders samples.</p>
<p>This function removes duplicate samples from each matrix,
only retains samples appearing in all matrices,
and brings them into the same order.</p>
</div>
<pre class="usage"><span class='fu'>prepare.data.matrices</span>(<span class='no'>Y</span>, <span class='no'>X</span>)</pre>
<pre class="usage"><span class='fu'>match.samples</span>(<span class='no'>...</span>, <span class='kw'>message</span> <span class='kw'>=</span> <span class='fl'>TRUE</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_y\) rows (samples) and \(p_y\) columns (exons)</p></td>
<th>...</th>
<td><p>matrices with samples in the rows and variables in the columns
(separated by commas)</p></td>
</tr>
<tr>
<th>X</th>
<td><p>matrix with \(n_x\) rows (samples) and \(p_x\) columns (SNPs)</p></td>
<th>message</th>
<td><p>display messages<strong>:</strong> logical</p></td>
</tr>
</table>
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function.R
\name{adjust.exon.length}
\alias{adjust.exon.length}
\name{adjust.covariates}
\alias{adjust.covariates}
\title{Adjust exon length}
\usage{
adjust.exon.length(x, group, offset)
adjust.covariates(x, offset, group)
}
\arguments{
\item{x}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (exons)}
\item{group}{gene (not exon) names\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}}
\item{group}{gene (not exon) names\strong{:} vector of length \eqn{p}}
}
\description{
This function adjusts exon expression data for different exon lengths.
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function.R
\name{adjust.library.sizes}
\alias{adjust.library.sizes}
\name{adjust.samples}
\alias{adjust.samples}
\title{Adjust library sizes}
\usage{
adjust.library.sizes(x)
adjust.samples(x)
}
\arguments{
\item{x}{matrix with \eqn{n} rows (samples) and \eqn{p} columns (variables)}
}
\description{
This function adjusts exon expression data for different library sizes.
This function adjusts RNA-seq expression data for different library sizes.
}
\examples{
NA
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function.R
\name{prepare.data.matrices}
\alias{prepare.data.matrices}
\name{match.samples}
\alias{match.samples}
\title{Prepare data matrices}
\usage{
prepare.data.matrices(Y, X)
match.samples(..., message = TRUE)
}
\arguments{
\item{Y}{matrix with \eqn{n_y} rows (samples) and \eqn{p_y} columns (exons)}
\item{...}{matrices with samples in the rows and variables in the columns
(separated by commas)}
\item{X}{matrix with \eqn{n_x} rows (samples) and \eqn{p_x} columns (SNPs)}
\item{message}{display messages\strong{:} logical}
}
\description{
This function removes duplicate samples, retains overlapping samples, and
orders samples.
This function removes duplicate samples from each matrix,
only retains samples appearing in all matrices,
and brings them into the same order.
}
\examples{
NA
......
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