Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
feat: add python package stub installer
Browse files Browse the repository at this point in the history
  • Loading branch information
milescsmith committed Aug 11, 2021
1 parent 2b4f4b0 commit c257f92
Show file tree
Hide file tree
Showing 23 changed files with 1,479 additions and 590 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.1] - 2020-12-23
## [2.5.0] - 2020-08-11
### Added
- Added a python stub package to pin package versions
### Changed
- Removed opt-SNE because it hasn't been updated in several years and it is
not trivial to install


## [2.4.1] - 2020-12-23
### Fixed
- Added missing `@importFrom magrittr %>%` in `PAGA()` header

### Changed
- Reformatted `PAGA()` code


## [2.4.0] - 2020-12-23

### Added
- Added [PaCMAP](https://github.com/YingfanWang/PaCMAP)
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ReductionWrappers
Title: Wrapper exposing several Python dimensional reduction tools
Version: 2.4.0.0000
Version: 2.5.0
Authors@R:
person(given = "Miles",
family = "Smith",
Expand All @@ -13,14 +13,13 @@ Url: https://github.com/milescsmith/ReductionWrappers
BugReports: https://github.com/milescsmith/ReductionWrappers/issues
Depends: R (>= 3.5.0)
Imports:
cowplot,
rlang,
reticulate,
parallel,
ggplot2,
ggpubr,
glue,
magrittr,
RANN,
Matrix,
Seurat,
SingleCellExperiment,
Expand Down
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ export(DooptSNE)
export(PAGA)
export(PAGAplot)
export(openTSNE)
export(optSNE)
export(pacmap)
export(phate)
export(phenograph)
export(umap)
importFrom(Matrix,Matrix)
importFrom(Matrix,sparseMatrix)
importFrom(RANN,nn2)
importFrom(Seurat,"Idents<-")
importFrom(Seurat,AddMetaData)
importFrom(Seurat,CreateDimReducObject)
Expand All @@ -32,14 +29,14 @@ importFrom(SingleCellExperiment,reducedDim)
importFrom(SingleCellExperiment,reducedDimNames)
importFrom(SummarizedExperiment,"colData<-")
importFrom(SummarizedExperiment,colData)
importFrom(cowplot,theme_cowplot)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_color_manual)
importFrom(ggpubr,theme_pubr)
importFrom(glue,glue)
importFrom(magrittr,"%>%")
importFrom(magrittr,set_colnames)
Expand All @@ -49,4 +46,3 @@ importFrom(reticulate,import)
importFrom(reticulate,py_module_available)
importFrom(rlang,"%||%")
importFrom(s2a,convert_to_anndata)
importFrom(stringr,str_glue)
58 changes: 34 additions & 24 deletions R/forceatlas2.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' ForceAtlas2
#' @title ForceAtlas2
#'
#' An R wrapper around the Python implementation of ForceAtlas2 found at
#' https://github.com/bhargavchippada/forceatlas2
Expand All @@ -10,6 +10,9 @@
#' @param iterations Number of times to iterate the main loop
#' @param ... Additional arguments to pass to the forceatlas2 object instantiation
#'
#' @importFrom reticulate import
#' @importFrom glue glue
#'
#' @rdname fa2
#'
fa2 <- function(init_pos,
Expand All @@ -20,37 +23,44 @@ fa2 <- function(init_pos,
required_modules <- c("fa2","numpy")
for (i in required_modules) {
if (!py_module_available(i)) {
stop(glue("The {i} module is unavailable.
stop(glue::glue("The {i} module is unavailable.
Please activate the appropriate environment or
install the module."))
}
}

fa2 <- import(module = "fa2", delay_load = TRUE)
np <- import(module = "numpy", delay_load = TRUE)
fa2 <- reticulate::import(module = "fa2", delay_load = TRUE)
np <- reticulate::import(module = "numpy", delay_load = TRUE)

# shamelessly based from the fantastic Scanpy package
forceatlas2 <- fa2$ForceAtlas2(outboundAttractionDistribution=FALSE, # Dissuade hubs
linLogMode=FALSE, # NOT IMPLEMENTED
adjustSizes=FALSE, # Prevent overlap (NOT IMPLEMENTED)
edgeWeightInfluence=1.0,
# Performance
jitterTolerance=1.0, # Tolerance
barnesHutOptimize=TRUE,
barnesHutTheta=1.2,
multiThreaded=FALSE, # NOT IMPLEMENTED
# Tuning
scalingRatio=2.0,
strongGravityMode=FALSE,
gravity=1.0,
# Log
verbose=TRUE)
forceatlas2 <-
fa2$ForceAtlas2(
outboundAttractionDistribution=FALSE, # Dissuade hubs
linLogMode=FALSE, # NOT IMPLEMENTED
adjustSizes=FALSE, # Prevent overlap (NOT IMPLEMENTED)
edgeWeightInfluence=1.0,
# Performance
jitterTolerance=1.0, # Tolerance
barnesHutOptimize=TRUE,
barnesHutTheta=1.2,
multiThreaded=FALSE, # NOT IMPLEMENTED
# Tuning
scalingRatio=2.0,
strongGravityMode=FALSE,
gravity=1.0,
# Log
verbose=TRUE
)

fa_results <- forceatlas2$forceatlas2(G = adjacencies,
pos = init_pos,
iterations = as.integer(iterations))
fa_results <-
forceatlas2$forceatlas2(
G = adjacencies,
pos = init_pos,
iterations = as.integer(iterations)
)
fa_embeddings <- np$array(fa_results)
rownames(fa_embeddings) <- rownames(init_pos)
colnames(fa_embeddings) <- as.character(glue("fa_{1:ncol(fa_embeddings)}"))
return(fa_embeddings)
colnames(fa_embeddings) <- as.character(glue::glue("fa_{1:ncol(fa_embeddings)}"))

fa_embeddings
}
Loading

0 comments on commit c257f92

Please sign in to comment.