Skip to content

Commit

Permalink
Switch to Rmd :( (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Jan 29, 2022
1 parent 5f214f8 commit df055bb
Show file tree
Hide file tree
Showing 29 changed files with 841 additions and 2,899 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

## Setup Python and nbconvert
- name: Setup Python for nbconvertR
uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: pip install nbconvert
## Necessary to do plotting with the default quartz device on macOS
- name: Install XQuartz
if: runner.os == 'macOS'
run: brew install --cask xquartz

## R is already included in the Bioconductor docker images
- name: Setup R from r-lib
Expand Down
22 changes: 1 addition & 21 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*.dll
*.pdf
*.tar.gz
.ipynb_checkpoints
.Rproj.user
*.Rcheck
__pycache__/
Expand All @@ -15,25 +14,6 @@ __pycache__/
/update_remotes.sh
/build/
/playground/
/inst/doc/.build.timestamp
/vignettes/.build.timestamp
/inst/doc/*.aux
/vignettes/*.aux
/inst/doc/*.bbl
/vignettes/*.bbl
/inst/doc/*.blg
/vignettes/*.blg
/inst/doc/*.log
/vignettes/*.log
/inst/doc/*.out
/vignettes/*.out
/inst/doc/*.tex
/vignettes/*.tex
/inst/doc/*.toc
/vignettes/*.toc
/inst/doc/*.fls
/vignettes/*.fls
/inst/doc/*.html
/vignettes/*.html
/inst/doc/*_files/
/vignettes/*.R
/vignettes/*_files/
18 changes: 14 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,26 @@ Imports:
scales,
scatterplot3d
LinkingTo: Rcpp, RcppEigen, grDevices
SystemRequirements: C++11, jupyter nbconvert (see nbconvertR’s INSTALL file)
SystemRequirements: C++11
NeedsCompilation: yes
Enhances: rgl, SingleCellExperiment
Suggests:
nbconvertR (>= 1.3.2),
knitr,
rmarkdown,
igraph,
testthat,
FNN,
tidyr
VignetteBuilder: nbconvertR
tidyverse,
gridExtra,
cowplot,
conflicted,
viridis,
rgl,
scRNAseq,
org.Mm.eg.db,
scran,
repr
VignetteBuilder: knitr
biocViews: CellBiology,
CellBasedAssays,
Clustering,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(fortify,DPT)
S3method(fortify,DiffusionMap)
export("dataset<-")
export("distance<-")
export("eigenvalues<-")
Expand Down Expand Up @@ -144,6 +146,7 @@ importFrom(ggplot2,element_line)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_text)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,fortify)
importFrom(ggplot2,geom_path)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_spoke)
Expand Down
2 changes: 1 addition & 1 deletion R/dpt-plotting.r
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ plot.DPT <- function(
dpt@dm, dcs,
plot_more = plot_paths,
legend_main = legend_main,
col = col, legend_name = col_by,
col = col,
...)

if (!identical(Sys.getenv('LOG_LEVEL'), '')) message('Args:\n', paste(capture.output(print(args)), collapse = '\n'))
Expand Down
4 changes: 4 additions & 0 deletions R/methods-coercion.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ setMethod('as.data.frame', 'DiffusionMap', function(x, row.names = NULL, optiona
#'
#' @importFrom BiocGenerics as.data.frame
#' @importFrom Biobase as.data.frame.ExpressionSet
#' @importFrom ggplot2 fortify
#' @rdname coercions
#' @exportS3Method fortify
#' @export fortify.DiffusionMap
fortify.DiffusionMap <- function(model, data, ...) as.data.frame(model, ...)
setAs('DiffusionMap', 'data.frame', function(from) as.data.frame(from))
Expand All @@ -79,7 +81,9 @@ setMethod('as.data.frame', 'DPT', function(x, row.names = NULL, optional = FALSE
#'
#' @importFrom BiocGenerics as.data.frame
#' @importFrom Biobase as.data.frame.ExpressionSet
#' @importFrom ggplot2 fortify
#' @rdname coercions
#' @exportS3Method fortify
#' @export fortify.DPT
fortify.DPT <- function(model, data, ...) as.data.frame(model, ...)
setAs('DPT', 'data.frame', function(from) as.data.frame(from))
Expand Down
15 changes: 13 additions & 2 deletions tests/testthat/test_dataset_types.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ test_nfeat <- 3L
test_obss <- paste0('c', seq_len(test_nobss))
test_feat <- paste0('g', seq_len(test_nfeat))

test_matrix <- matrix(runif(test_nobss * test_nfeat), test_nobss, test_nfeat, dimnames = list(test_obss, test_feat))
test_matrix[test_matrix < mean(test_matrix)] <- 0
mk_test_matrix <- function() {
m <- matrix(runif(test_nobss * test_nfeat), test_nobss, test_nfeat, dimnames = list(test_obss, test_feat))
m[m < mean(m)] <- 0
m
}

test_matrix <- mk_test_matrix()
for (attempt in seq_len(100L)) {
if (!any(duplicated(test_matrix))) break
test_matrix <- mk_test_matrix()
}
if (any(duplicated(test_matrix))) stop('Could not create sensible test matrix after 100 attempts')

test_df <- data.frame(test_matrix, cm1 = LETTERS[seq_len(test_nobss)], stringsAsFactors = FALSE)
test_es <- ExpressionSet(
t(test_matrix),
Expand Down
90 changes: 90 additions & 0 deletions vignettes/DPT.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: destiny 2.0 brought the Diffusion Pseudo Time (DPT) class
output: rmarkdown::html_vignette
bibliography: bibliography.bib
vignette: >
%\VignetteIndexEntry{destiny 2.0 brought the Diffusion Pseudo Time (DPT) class}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r}
set.seed(1)
```

Diffusion Pseudo Time (DPT) is a pseudo time metric based on the transition probability of a diffusion process [@haghverdi_diffusion_2016].

*destiny* supports `DPT` in addition to its primary function of creating `DiffusionMap`s from data.

```{r}
library(destiny) # load destiny…
data(guo) # …and sample data
library(gridExtra) # Also we need grid.arrange
```

`DPT` is in practice independent of Diffusion Maps:

```{r}
par(mar = rep(0, 4))
graph <- igraph::graph_from_literal(
data -+ 'transition probabilities' -+ DiffusionMap,
'transition probabilities' -+ DPT)
plot(
graph, layout = igraph::layout_as_tree,
vertex.size = 50,
vertex.color = 'transparent',
vertex.frame.color = 'transparent',
vertex.label.color = 'black')
```

However in order not to overcomplicate things, in *destiny*, you have to create `DPT` objects from `DiffusionMap` objects.
<small>(If you really only need the DPT, skip Diffusion Component creation by specifying `n_eigs = 0`)</small>

```{r}
dm <- DiffusionMap(guo)
dpt <- DPT(dm)
```

The resulting object of a call like this will have three automatically chosen tip cells. You can also specify tip cells:

```{r}
set.seed(4)
dpt_random <- DPT(dm, tips = sample(ncol(guo), 3L))
```

Plotting without parameters results in the DPT of the first root cell:

TODO: wide plot

```{r}
grid.arrange(plot(dpt), plot(dpt_random), ncol = 2)
```

Other possibilities include the DPT from the other tips or everything supported by `plot.DiffusionMap`:

TODO: wide plot

```{r}
grid.arrange(
plot(dpt, col_by = 'DPT3'),
plot(dpt, col_by = 'Gata4', pal = viridis::magma),
ncol = 2
)
```

The `DPT` object also contains a clustering based on the tip cells and DPT, and you can specify where to draw paths from and to:

```{r}
plot(dpt, root = 2, paths_to = c(1,3), col_by = 'branch')
```

You can further divide branches. First simply plot branch colors like we did above, then identify the number of the branch you intend to plot, and then specify it in a subsequent `plot` call. In order to see the new branches best, we specify a `dcs` argument that visually spreads out out all four branches.

```{r}
plot(dpt, col_by = 'branch', divide = 3, dcs = c(-1,-3,2), pch = 20)
```

References
==========

<div id="refs"></div>
319 changes: 0 additions & 319 deletions vignettes/DPT.ipynb

This file was deleted.

4 changes: 0 additions & 4 deletions vignettes/DPT.ipynbmeta

This file was deleted.

43 changes: 43 additions & 0 deletions vignettes/Diffusion-Map-recap.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Reproduce the Diffusion Map vignette with the supplied data()
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Reproduce the Diffusion Map vignette with the supplied data()}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

Quickstart
==========

A short version to achive the above is by using the preprocessed version of the dataset provided with this package. `data(guo)` is already preprocessed (using the method first mentioned), has its threshold set to a constant 15 and is ready to use. Since the platform’s maximum amplification cycles are 40, that number can be used as upper border of the uncertainty range.

```{r}
library(destiny)
data(guo)
```

It can be used directly for diffusion map creation:

```{r}
dm_guo <- DiffusionMap(guo, verbose = FALSE,
censor_val = 15, censor_range = c(15, 40))
dm_guo
```

```{r}
plot(dm_guo)
```

using the annotation shows that the approximation worked

```{r}
palette(cube_helix(6))
plot(dm_guo, col_by = 'num_cells',
legend_main = 'Cell stage')
```

References
==========

<div id="refs"></div>
131 changes: 0 additions & 131 deletions vignettes/Diffusion-Map-recap.ipynb

This file was deleted.

4 changes: 0 additions & 4 deletions vignettes/Diffusion-Map-recap.ipynbmeta

This file was deleted.

Loading

0 comments on commit df055bb

Please sign in to comment.