Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
akdess committed Feb 25, 2020
1 parent 489ba22 commit 2b850fb
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 608 deletions.
994 changes: 497 additions & 497 deletions .Rhistory

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
.Rhistory
.RData
.Ruserdata
inst/doc
1 change: 0 additions & 1 deletion CaSpER.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: Identification, visualization and integrative analysis of CNV event
Encoding: UTF-8
LazyData: true
LinkingTo: Rcpp
Depends: Rcpp, signal, pheatmap, GenomicRanges, RColorBrewer, HMMcopy, IRanges, grid, ggplot2, reshape, mclust, ggpubr, scales, gridExtra, igraph, intergraph, ggnetwork, ape, biomaRt, limma, GO.db, org.Hs.eg.db, GOstats
Depends: Rcpp, signal, pheatmap, GenomicRanges, RColorBrewer, IRanges, grid, ggplot2, reshape, mclust, ggpubr, scales, gridExtra, igraph, intergraph, ggnetwork, ape, biomaRt, limma, GO.db, org.Hs.eg.db, GOstats
RoxygenNote: 6.1.1
Suggests: knitr,
rmarkdown
Expand Down
11 changes: 10 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
useDynLib(CaSpER, .registration = TRUE)
export(CreateCasperObject)
export(lohCallMedianFilterByChr)
export(lohCallMedianFilter)
export(ProcessData)
export(PerformMedianFilter)
export(PerformMedianFilterByChr)
export(PerformMeanFilterByChr)
export(CenterSmooth)
export(ControlNormalize)
export(AverageReference)
Expand All @@ -19,6 +21,7 @@ export(extractEvents)
export(draw_matrix2)
export(draw_colnames_45)
export(plotHeatmap)
export(plotHeatmap10x)
export(plotGEAndGT)
export(plotLargeScaleEvent)
export(plotBAFInSeperatePages)
Expand All @@ -41,13 +44,19 @@ export(splitByOverlap)
export(extractLargeScaleEvents)
export(mergeScalesAndGenerateFinalEventSummary)
export(goEnrichmentBP)
export(estimateTNoiseParamsMap)
export(tdistPDF)
export(dirichletpdf)
export(normalize)
export(manualSegment)
export(processSegments)
export(HMMsegment)
export(gene.matrix)
import(igraph)
import(signal)
import(pheatmap)
import(RColorBrewer)
import(grid)
import(HMMcopy)
import(IRanges)
import(ggplot2)
import(reshape)
Expand Down
16 changes: 7 additions & 9 deletions R/casper.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#'
#' @slot loh original baf signal
#'
#' @slot median.filtered.data median filtered expression signal
#' @slot filtered.data median filtered expression signal
#'
#' @slot loh.median.filtered.data median filtered baf signal
#'
Expand All @@ -30,9 +30,7 @@
#'
#' @slot control.normalized control normalization is performed by subtracting reference expression values from the tumor expression values.
#'
#' @slot control.normalized.visbound control normalized data is thresholded in order to perform better visualization.
#'
#' @slot control.normalized.visbound.noiseRemoved noise is removed from control normalized and thresholded data.
#' @slot control.normalized.noiseRemoved noise is removed from control normalized and thresholded data.
#'
#' @slot large.scale.cnv.events large scale CNV events identified by CaSpER
#'
Expand Down Expand Up @@ -78,12 +76,12 @@
#' @aliases casper-class
#' @exportClass casper

casper <- methods::setClass("casper", slots = c(raw.data = "ANY", data = "ANY", median.filtered.data = "ANY", loh.median.filtered.data = "ANY",
centered.data = "ANY", center.smoothed.data = "ANY", control.normalized = "ANY", control.normalized.visbound = "ANY", control.normalized.visbound.noiseRemoved = "ANY",
casper <- methods::setClass("casper", slots = c(raw.data = "ANY", data = "ANY", filtered.data = "ANY", loh.median.filtered.data = "ANY",
centered.data = "ANY", matrix.type="ANY", center.smoothed.data = "ANY", control.normalized = "ANY", control.normalized.noiseRemoved = "ANY",
large.scale.cnv.events = "ANY", segments = "ANY", cytoband = "ANY", annotation = "ANY", annotation.filt = "ANY", control.sample.ids = "character",
project.name = "character", genomeVersion = "ANY", hmmparam = "ANY", plotorder = "ANY", vis.bound = "ANY",
noise.thr = "ANY", loh.name.mapping = "ANY", sequencing.type = "ANY", cnv.scale = "ANY", loh.scale = "ANY", method = "ANY",
loh.shift.thr = "ANY", window.length = "ANY", length.iterations = "ANY", loh = "ANY"))
project.name = "character", genomeVersion = "ANY", hmmparam = "ANY", plotorder = "ANY",
loh.name.mapping = "ANY", sequencing.type = "ANY", cnv.scale = "ANY", loh.scale = "ANY", method = "ANY",
loh.shift.thr = "ANY", window.length = "ANY", length.iterations = "ANY", loh = "ANY", filter= "ANY"))

setMethod(f = "show", signature = "casper", definition = function(object) {
cat("An object of class", class(object), "in project", object@project.name, "\n", nrow(x = object@raw.data), "genes across",
Expand Down
45 changes: 40 additions & 5 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,43 @@ draw_matrix2 <- function(matrix, border_color, gaps_rows, gaps_cols, fmat, fonts
#' @export
#'
#'
plotHeatmap10x <- function(object, fileName, cnv.scale = 3, cluster_cols = F, cluster_rows = T, show_rownames = T, only_soi = T) {

assignInNamespace(x = "draw_matrix", value = draw_matrix2, ns = asNamespace("pheatmap"))
assignInNamespace(x = "draw_colnames", value = "draw_colnames_45", ns = asNamespace("pheatmap"))


data <- object@control.normalized.noiseRemoved[[cnv.scale]]

x.center <- mean(data)
quantiles = quantile(data[data != x.center], c(0.01, 0.99))

delta = max( abs( c(x.center - quantiles[1], quantiles[2] - x.center) ) )
low_threshold = x.center - delta
high_threshold = x.center + delta
x.range = c(low_threshold, high_threshold)

data[data < low_threshold] <- low_threshold
data[data > high_threshold] <- high_threshold

breaks <- seq(x.range[1], x.range[2], length=16)
# breaks <- seq(0, 2, length=16)
color <- colorRampPalette(rev(brewer.pal(11, "RdYlBu")))(length(breaks))

idx <- cumsum(table(object@annotation.filt$Chr)[as.character(1:22)])
xlabel <- rep("", length(rownames(object@data)))
half <- round(table(object@annotation.filt$Chr)[as.character(1:22)]/2)[-1]
xpos <- c(half[1], (idx[-22] + half))
xlabel[xpos] <- 1:22

if (only_soi)
data <- data[, !(colnames(data) %in% object@control.sample.ids)]

pheatmap(t(data), cluster_cols = F, cluster_rows = T, gaps_col = idx, color = color, breaks = breaks,
labels_col = xlabel, show_rownames = T, filename = "heatmap.png")

}

plotHeatmap <- function(object, fileName, cnv.scale = 3, cluster_cols = F, cluster_rows = T, show_rownames = T, only_soi = T) {

assignInNamespace(x = "draw_matrix", value = draw_matrix2, ns = asNamespace("pheatmap"))
Expand All @@ -76,13 +113,13 @@ plotHeatmap <- function(object, fileName, cnv.scale = 3, cluster_cols = F, clust
xpos <- c(half[1], (idx[-22] + half))
xlabel[xpos] <- 1:22

data <- object@control.normalized[[cnv.scale]]
data <- log2(object@control.normalized.noiseRemoved[[cnv.scale]])

if (only_soi)
data <- data[, !(colnames(data) %in% object@control.sample.ids)]

pheatmap(t(data), cluster_cols = F, cluster_rows = T, gaps_col = idx, color = color, breaks = breaks,
labels_col = xlabel, show_rownames = T, filename = "test.png")
labels_col = xlabel, show_rownames = T, filename = "heatmap.png")

}

Expand Down Expand Up @@ -622,9 +659,7 @@ plotSCellCNVTree <- function(finalChrMat, sampleName, path = "C:\\Users\\aharman
colnames(m) <- rownames(finalChrMat)
rownames(m) <- rownames(finalChrMat)
tree <- Rfitch(na.omit(m), global = T, path = path, outgroup = T)




pdf(fileName)
X <- as.matrix(finalChrMat)[, which(apply(finalChrMat, 2, sum) != 0)]
plot(tree, x.lim = 40, align.tip = TRUE, adj = 1, cex = 0.2)
Expand Down
Loading

0 comments on commit 2b850fb

Please sign in to comment.