Skip to content

Commit

Permalink
Merge pull request #17 from KrishnaswamyLab/dev
Browse files Browse the repository at this point in the history
phateR v0.2.8
  • Loading branch information
scottgigante authored Jul 9, 2018
2 parents 71700ea + 76cbf54 commit 7b41a16
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ r:
- release
- devel

cache: packages

env:
global:
- PATH="$HOME/miniconda/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: phateR
Title: PHATE - Potential of Heat-Diffusion for Affinity-Based Transition Embedding
Version: 0.2.7
Version: 0.2.8
Authors@R: c(person("Krishnan", "Srinivasan", email = "[email protected]", role = c("aut")),
person(given = 'Scott', family = 'Gigante', email = '[email protected]', role = 'cre', comment = c(ORCID = '0000-0002-4544-2764')))
Description: PHATE is a tool for visualizing high dimensional single-cell data
Expand Down
51 changes: 36 additions & 15 deletions R/phate.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
#' If NULL, alpha decaying kernel is not used
#' @param n.landmark int, optional, default: 2000
#' number of landmarks to use in fast PHATE
#' @param potential.method string, optional, default: 'log'
#' choose from 'log' and 'sqrt'
#' which transformation of the diffusional operator is used
#' to compute the diffusion potential
#' @param gamma float, optional, default: 1
#' Informational distance constant between -1 and 1.
#' `gamma=1` gives the PHATE log potential, `gamma=0` gives
#' a square root potential.
#' @param t int, optional, default: 'auto'
#' power to which the diffusion operator is powered
#' sets the level of diffusion
#' @param knn.dist.method string, optional, default: 'euclidean'.
#' The desired distance function for calculating pairwise distances on the data.
#' If 'precomputed', `data` is treated as a
#' (n_samples, n_samples) distance or affinity matrix
#' recommended values: 'euclidean', 'cosine', 'precomputed'
#' Any metric from `scipy.spatial.distance` can be used
#' distance metric for building kNN graph. If 'precomputed',
#' `data` should be an n_samples x n_samples distance or
#' affinity matrix. Distance matrices are assumed to have zeros
#' down the diagonal, while affinity matrices are assumed to have
#' non-zero values down the diagonal. This is detected automatically using
#' `data[0,0]`. You can override this detection with
#' `knn.dist.method='precomputed_distance'` or
#' `knn.dist.method='precomputed_affinity'`.
#' @param init phate object, optional
#' object to use for initialization. Avoids recomputing
#' intermediate steps if parameters are the same.
Expand Down Expand Up @@ -55,8 +62,9 @@
#' For n_jobs below -1, (n.cpus + 1 + n.jobs) are used. Thus for
#' n_jobs = -2, all CPUs but one are used
#' @param seed int or `NULL`, random state (default: `NULL`)
#' @param use.alpha boolean, default: NULL
#' Deprecated. To disable alpha decay, use `alpha=NULL`
#' @param potential.method Deprecated.
#' @param use.alpha Deprecated
#' To disable alpha decay, use `alpha=NULL`
#' @param n.svd Deprecated.
#' @param pca.method Deprecated.
#' @param g.kernel Deprecated.
Expand Down Expand Up @@ -105,12 +113,13 @@
#' @export
phate <- function(data, ndim = 2, k = 5,
alpha = 15,
n.landmark=2000, potential.method = "log",
n.landmark=2000, gamma=1,
t = "auto", knn.dist.method = "euclidean",
init=NULL,
mds.method = "metric", mds.dist.method = "euclidean",
t.max=100, npca = 100, plot.optimal.t=FALSE,
verbose=1, n.jobs=1, seed=NULL,
potential.method = NULL,
# deprecated args, remove in v3
use.alpha=NULL,
n.svd = NULL,
Expand All @@ -127,6 +136,18 @@ phate <- function(data, ndim = 2, k = 5,
message("Argument dist.method is deprecated. Using knn.dist.method instead.")
knn.dist.method <- dist.method
}
if (!is.null(potential.method)) {
if (potential.method == 'log') {
gamma <- 1
} else if (potential.method == 'sqrt') {
gamma <- 0
} else {
stop(paste0("potential.method ", potential.method, " not recognized. ",
"Please use -1 <= gamma <= 1 instead."))
}
message(paste0("Argument potential_method is deprecated. Setting gamma to ",
gamma, " to achieve ", potential.method, " transformation."))
}
if (!is.null(n.svd)) {
message("Setting n.svd is currently not supported. Using n.svd=100")
}
Expand Down Expand Up @@ -208,8 +229,8 @@ phate <- function(data, ndim = 2, k = 5,

# store parameters
params <- list("data" = data, "k" = k, "alpha" = alpha, "t" = t,
"n.landmark" = n.landmark, "ndim" = ndim,
"potential.method" = potential.method,
"n.landmark" = n.landmark, "gamma" = gamma,
"ndim" = ndim,
"npca" = npca, "mds.method" = mds.method,
"knn.dist.method" = knn.dist.method,
"mds.dist.method" = mds.dist.method)
Expand All @@ -226,7 +247,7 @@ phate <- function(data, ndim = 2, k = 5,
t = t,
alpha_decay = use.alpha,
n_landmark = n.landmark,
potential_method = potential.method,
gamma = gamma,
n_pca = npca,
mds = mds.method,
mds_dist = mds.dist.method,
Expand All @@ -243,7 +264,7 @@ phate <- function(data, ndim = 2, k = 5,
t = t,
alpha_decay = use.alpha,
n_landmark = n.landmark,
potential_method = potential.method,
gamma = gamma,
n_pca = npca,
mds = mds.method,
mds_dist = mds.dist.method,
Expand Down Expand Up @@ -314,7 +335,7 @@ plot.phate <- function(x, ...) {
#' ## $embedding : (3000, 2)
#' ## $operator : Python PHATE operator
#' ## $params : list with elements (data, k, alpha, t, n.landmark, ndim,
#' ## potential.method, npca, mds.method,
#' ## gamma, npca, mds.method,
#' ## knn.dist.method, mds.dist.method)
#'
#' }
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ load_pyphate <- function() {
#' is not available on Windows.
#' @param conda Path to conda executable (or "auto" to find conda using the PATH
#' and other conventional install locations).
#' @param pip Install from pip, if possible.
#' @param ... Additional arguments passed to conda_install() or
#' virtualenv_install().
#'
Expand Down
15 changes: 8 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title : phateR v0.2.7
title : phateR v0.2.8
output: github_document
---

Expand Down Expand Up @@ -42,6 +42,8 @@ For our Python and Matlab implementations, please see [KrishnaswamyLab/PHATE](ht

In order to use PHATE in R, you must also install the Python package.

If `python` or `pip` are not installed, you will need to install them. We recommend [Miniconda3](https://conda.io/miniconda.html) to install Python and `pip` together, or otherwise you can install `pip` from https://pip.pypa.io/en/stable/installing/.

#### Installation from CRAN and PyPi

Install `phateR` from CRAN by running the following code in R:
Expand All @@ -56,8 +58,6 @@ Install `phate` in Python by running the following code from a terminal:
pip install --user phate
```

If `python` or `pip` are not installed, you will need to install them. We recommend [Miniconda3](https://conda.io/miniconda.html) to install Python and `pip` together, or otherwise you can install `pip` from https://pip.pypa.io/en/stable/installing/.

#### Installation with `devtools` and `reticulate`

The development version of PHATE can be installed directly from R with `devtools`:
Expand All @@ -80,7 +80,7 @@ reticulate::py_install("phate", pip=TRUE)
The latest source version of PHATE can be accessed by running the following in a terminal:

```{bash install-source, eval=FALSE}
git clone --recursive git://github.com/SmitaKrishnaswamy/PHATE.git
git clone --recursive git://github.com/KrishnaswamyLab/PHATE.git
cd PHATE/phateR
R CMD INSTALL
cd ../Python
Expand Down Expand Up @@ -126,11 +126,11 @@ palette(rainbow(10))
plot(tree.phate, col = tree.data$branches)
```

Good news! Our branches separate nicely. However, most of the interesting activity seems to be concentrated into one region of the plot - in this case we should try the square root potential instead. We can also try increasing `t` to make the structure a little clearer - in this case, because synthetic data in unusually structured, we can use a very large value, like 120, but in biological data the automatic `t` selection is generally very close to ideal. Note here that if we pass our previous result in with the argument `init`, we won't have to recompute the diffusion operator.
Good news! Our branches separate nicely. However, most of the interesting activity seems to be concentrated into one region of the plot - in this case we should try the square root potential instead by using `gamma=0`. We can also try increasing `t` to make the structure a little clearer - in this case, because synthetic data in unusually structured, we can use a very large value, like 120, but in biological data the automatic `t` selection is generally very close to ideal. Note here that if we pass our previous result in with the argument `init`, we won't have to recompute the diffusion operator.

```{r adjust-parameters}
# runs phate with different parameters
tree.phate <- phate(tree.data$data, potential.method='sqrt', t=120, init=tree.phate)
tree.phate <- phate(tree.data$data, gamma=0, t=120, init=tree.phate)
# plot embedding
palette(rainbow(10))
plot(tree.phate, col = tree.data$branches)
Expand All @@ -147,4 +147,5 @@ ggplot(tree.phate, aes(x=PHATE1, y=PHATE2, color=tree.data$branches)) +

## Issues

Please let us know of any issues at the [GitHub repo](https://github.com/KrishnaswamyLab/phateR/issues)
Please let us know of any issues at the [GitHub repo](https://github.com/KrishnaswamyLab/phateR/issues). If you have any questions or require assistance using MAGIC, please contact us at <https://krishnaswamylab.org/get-help>.

33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
phateR v0.2.7
phateR v0.2.8
================

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down Expand Up @@ -43,6 +43,11 @@ For our Python and Matlab implementations, please see

In order to use PHATE in R, you must also install the Python package.

If `python` or `pip` are not installed, you will need to install them.
We recommend [Miniconda3](https://conda.io/miniconda.html) to install
Python and `pip` together, or otherwise you can install `pip` from
<https://pip.pypa.io/en/stable/installing/>.

#### Installation from CRAN and PyPi

Install `phateR` from CRAN by running the following code in R:
Expand All @@ -57,8 +62,6 @@ Install `phate` in Python by running the following code from a terminal:
pip install --user phate
```

If `python` or `pip` are not installed, you will need to install them. We recommend [Miniconda3](https://conda.io/miniconda.html) to install Python and `pip` together, or otherwise you can install `pip` from https://pip.pypa.io/en/stable/installing/.

#### Installation with `devtools` and `reticulate`

The development version of PHATE can be installed directly from R with
Expand All @@ -83,7 +86,7 @@ The latest source version of PHATE can be accessed by running the
following in a terminal:

``` bash
git clone --recursive git://github.com/SmitaKrishnaswamy/PHATE.git
git clone --recursive git://github.com/KrishnaswamyLab/PHATE.git
cd PHATE/phateR
R CMD INSTALL
cd ../Python
Expand Down Expand Up @@ -113,7 +116,6 @@ PCA.
``` r
library(phateR)
#> Loading required package: Matrix
#> Warning: package 'Matrix' was built under R version 3.4.4
data(tree.data)
plot(prcomp(tree.data$data)$x, col=tree.data$branches)
```
Expand Down Expand Up @@ -145,17 +147,17 @@ plot(tree.phate, col = tree.data$branches)

Good news\! Our branches separate nicely. However, most of the
interesting activity seems to be concentrated into one region of the
plot - in this case we should try the square root potential instead. We
can also try increasing `t` to make the structure a little clearer - in
this case, because synthetic data in unusually structured, we can use a
very large value, like 120, but in biological data the automatic `t`
selection is generally very close to ideal. Note here that if we pass
our previous result in with the argument `init`, we won’t have to
recompute the diffusion operator.
plot - in this case we should try the square root potential instead by
using `gamma=0`. We can also try increasing `t` to make the structure a
little clearer - in this case, because synthetic data in unusually
structured, we can use a very large value, like 120, but in biological
data the automatic `t` selection is generally very close to ideal. Note
here that if we pass our previous result in with the argument `init`, we
won’t have to recompute the diffusion operator.

``` r
# runs phate with different parameters
tree.phate <- phate(tree.data$data, potential.method='sqrt', t=120, init=tree.phate)
tree.phate <- phate(tree.data$data, gamma=0, t=120, init=tree.phate)
# plot embedding
palette(rainbow(10))
plot(tree.phate, col = tree.data$branches)
Expand All @@ -177,4 +179,7 @@ ggplot(tree.phate, aes(x=PHATE1, y=PHATE2, color=tree.data$branches)) +
## Issues

Please let us know of any issues at the [GitHub
repo](https://github.com/KrishnaswamyLab/phateR/issues)
repo](https://github.com/KrishnaswamyLab/phateR/issues).
If you have any questions or require assistance using PHATE,
please contact us at <https://krishnaswamylab.org/get-help>.

Binary file modified man/figures/README-adjust-parameters-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-ggplot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-plot-results-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion man/install.phate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 23 additions & 14 deletions man/phate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/print.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b41a16

Please sign in to comment.