Skip to content

Commit

Permalink
Merge pull request #14 from LUMC/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
tomkuipers1402 authored Nov 3, 2020
2 parents f93da00 + b682ec8 commit 0a5c8d9
Show file tree
Hide file tree
Showing 50 changed files with 2,936 additions and 1,678 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dgeAnalysis
Type: Package
Title: dgeAnalysis
Version: 1.3.1
Version: 1.3.2
Author@R:
person("Tom", "Kuipers", email = "[email protected]", role = c("aut", "cre"))
Description:
Expand Down
Binary file modified MANUAL.pdf
Binary file not shown.
68 changes: 36 additions & 32 deletions R/de.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#' @param data_samples Dataframe, Containing all sample data
#'
#' @return se, (SummerizedExperiment) With counts
#'
#'
#' @export

readCountsFromTable <- function(data_counts, data_samples) {
out <- as.matrix(data_counts[, colnames(data_counts) %in% rownames(data_samples)])
se <- SummarizedExperiment(assays=list(counts=out))
se <- SummarizedExperiment(assays = list(counts = out))
se
}

Expand All @@ -24,14 +24,14 @@ readCountsFromTable <- function(data_counts, data_samples) {
#' @param data_samples Dataframe, Containing all sample data
#'
#' @return se, (SummerizedExperiment) With samples and counts
#'
#'
#' @export

addSamplesFromTableToSE <- function(se, data_samples){
addSamplesFromTableToSE <- function(se, data_samples) {
data_samples <- droplevels(data_samples)
samples <- intersect(colnames(se), rownames(data_samples))
se <- se[,samples]
colData(se) <- DataFrame(data_samples[samples,, drop = FALSE])
se <- se[, samples]
colData(se) <- DataFrame(data_samples[samples, , drop = FALSE])
se
}

Expand All @@ -42,13 +42,13 @@ addSamplesFromTableToSE <- function(se, data_samples){
#' @param data_annotation Dataframe, Containing all annotation data
#'
#' @return se, (SummerizedExperiment) With samples, counts and annotation
#'
#'
#' @export

addAnnotationsFromTableToSE <- function(se, data_annotation){
addAnnotationsFromTableToSE <- function(se, data_annotation) {
features <- intersect(rownames(se), rownames(data_annotation))
se <- se[features,]
rowData(se) <- DataFrame(data_annotation[features,])
se <- se[features, ]
rowData(se) <- DataFrame(data_annotation[features, ])
se
}

Expand All @@ -63,14 +63,14 @@ addAnnotationsFromTableToSE <- function(se, data_annotation){
#' @param raw Dataframe, Containing count data
#'
#' @return Integer, With total counted reads
#'
#'
#' @export

getCount <- function(x, raw){
getCount <- function(x, raw) {
if (x["feature"] %in% rownames(raw)) {
return(raw[x["feature"], x["sample"]])
} else {
features <- rownames(raw)[! grepl("^__", rownames(raw))]
features <- rownames(raw)[!grepl("^__", rownames(raw))]
return(sum(raw[features, x["sample"]]))
}
}
Expand All @@ -81,12 +81,13 @@ getCount <- function(x, raw){
#' @param se SummerizedExperiment, With samples, counts (and annotation)
#'
#' @return out, (Dataframe) With total counts per available mapping feature
#'
#'
#' @export

alignmentSummary <- function(se){
specialFeatures <- rownames(se)[ grepl( "^__", rownames(se) ) ]
out <- expand.grid(feature=c("aligned", specialFeatures), sample=colnames(se))
alignmentSummary <- function(se) {
specialFeatures <- rownames(se)[grepl("^__", rownames(se))]
out <- expand.grid(feature = c("aligned", specialFeatures),
sample = colnames(se))
out$count <- apply(out, 1, getCount, assays(se)$counts)
out
}
Expand All @@ -98,19 +99,20 @@ alignmentSummary <- function(se){
#' @param max Integer, The maximum rank that is used
#'
#' @return out, (Dataframe) With total read counts per gene
#'
#'
#' @export

complexityData <- function(se, max){
features <- rownames(se)[ ! grepl( "^__", rownames(se) ) ]
complexityData <- function(se, max) {
features <- rownames(se)[!grepl("^__", rownames(se))]
ranks <- c(1:max)
out <- expand.grid(rank=ranks, sample=colnames(se))
for (x in colnames(se)){
values <- as.vector(assay(se)[features,x])
out <- expand.grid(rank = ranks, sample = colnames(se))
for (x in colnames(se)) {
values <- as.vector(assay(se)[features, x])
sorted <- sort(values, T)
total <- sum(sorted)
out[out$sample == x, "value"] <- cumsum(sorted)[1:max]
out[out$sample == x, "fraction"] <- out[out$sample == x, "value"] /total
out[out$sample == x, "fraction"] <-
out[out$sample == x, "value"] / total
}
out
}
Expand All @@ -122,10 +124,10 @@ complexityData <- function(se, max){
#' @param max Integer, The maximum rank that is used
#'
#' @return count, (Dataframe) With mapping feature, sample and LogCPM
#'
#'
#' @export

stackDge <- function(dge){
stackDge <- function(dge) {
count <- stack(dge$counts)
names(count) <- c("feature", "sample", "logCPM")
count
Expand All @@ -139,27 +141,29 @@ stackDge <- function(dge){
#' @param biasColumn String, Value on which to calculate confidence
#'
#' @return prediction, (Vector) With coordinates of prediction locations (line plot)
#'
#'
#' @export

gamConfidenceFit <- function(deTab, biasColumn) {
method.args = list()
method.args$method <- "REML"

formula <- avgLog2FC ~ s(columnHere, bs = "cs")
formula <- paste(gsub("columnHere", parse(text=biasColumn), formula))
formula <- eval(parse(text = gsub("\\", "", paste(formula[2], formula[3], sep=" ~ "), fixed=TRUE)))
formula <- paste(gsub("columnHere", parse(text = biasColumn), formula))
formula <- eval(parse(text = gsub(
"\\", "", paste(formula[2], formula[3], sep = " ~ "), fixed = TRUE
)))

base.args <- list(quote(formula), data = quote(deTab))
gamModel <- do.call(mgcv::gam, c(base.args, method.args))

prediction <- deTab[, c(biasColumn, "avgLog2FC")]
prediction <- cbind(prediction, predict(gamModel, se.fit=TRUE))
prediction <- prediction[order(prediction[[biasColumn]]), ]
prediction <- cbind(prediction, predict(gamModel, se.fit = TRUE))
prediction <- prediction[order(prediction[[biasColumn]]),]

setRange <- range(1, nrow(prediction))
result <- round(seq(setRange[1], setRange[2], length.out = 500))
prediction <- prediction[c(result),]
prediction <- prediction[c(result), ]
}

## --------------------------------------------------------------------------
Loading

0 comments on commit 0a5c8d9

Please sign in to comment.