Skip to content

Commit

Permalink
Merge pull request #20 from jhsiao999/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jhsiao999 authored Sep 16, 2019
2 parents 53b0aea + ce01ea9 commit 6e10318
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ peco*tar.gz
vignettes/*.html
vignettes/*.R
NOTES.txt
peco.Rproj
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Encoding: UTF-8
Type: Package
Package: peco
Version: 0.99.0
Version: 0.99.1
Date: 2019-09-11
Title: A Supervised Approach for **P**r**e**dicting **c**ell Cycle
Pr**o**gression using scRNA-seq data
Expand All @@ -21,7 +21,7 @@ Description: Our approach provides a way to assign continuous cell cycle phase
URL: https://github.com/jhsiao999/peco
BugReports: https://github.com/jhsiao999/peco/issues
License: GPL (>= 3)
Depends: R (>= 3.5)
Depends: R (>= 3.6)
Imports:
assertthat,
Biobase,
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changes in version 0.99.1 (2019-09-16)
+ Fixed R CMD Check warnings and errors
+ Fixed R CMD BiocCheck warnings and errors

Changes in version 0.99.0 (2019-09-11)
+ Submitted to Bioconductor

90 changes: 47 additions & 43 deletions R/cycle_npreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
#' trends of gene express levels for each gene.}
#'
#' @examples
#' library(Biobase)
#' \dontrun{
#' # import data
#' library(Biobase)
#' data(eset_sub)
#'
#' # select top 5 cyclic genes
Expand All @@ -58,7 +59,7 @@
#'
#' # quantile-transform each gene to normal distribution
#' expr_quant <- do.call(rbind,
#' lapply(seq_len(nrow(counts_normed)), function(g) {
#' lapply(seq_len(nrow(counts_normed)), function(g) {
#' yy <- counts_normed[g,]
#' is.zero <- which(yy == 0)
#' qq.map <- qqnorm(yy, plot.it = FALSE)
Expand All @@ -74,8 +75,7 @@
#' which_samples_train <- rownames(pdata)[which(pdata$chip_id != "NA18511")]
#' which_samples_predict <- rownames(pdata)[which(pdata$chip_id == "NA18511")]
#'
#' # make an example of using data from 5 individuals to predict
#' # phase in one indivdual
#' # make an example of using data from 5 individuals to predict phase in one indivdual
#' Y_train <- expr_quant[, which(colnames(expr_quant) %in% which_samples_train)]
#' theta_train <- pdata$theta_shifted[which(rownames(pdata) %in% which_samples_train)]
#' names(theta_train) <- rownames(pdata)[which(rownames(pdata) %in% which_samples_train)]
Expand Down Expand Up @@ -117,12 +117,19 @@
#' title(rownames(fit_predict$Y_reordered)[g])
#' }
#' title("Predicting cell cycle phase for NA18511", outer=TRUE)
#' }
#'
#' @author Joyce Hsiao
#'
#' @family peco classifier functions
#' @seealso
#' \code{\link{cycle_npreg_mstep}} for estimating cyclic functions given
#' inferred phases from \code{\link{cycle_npreg_loglik}},
#' \code{\link{cycle_npreg_outsample}} for predicting cell cycle phase
#' using parameters learned from \code{\link{cycle_npreg_insample}}
#'
#' @import Biobase
#' @import methods
#'
#' @export
cycle_npreg_insample <- function(Y, theta,
ncores=4,
Expand Down Expand Up @@ -289,6 +296,15 @@ cycle_npreg_insample <- function(Y, theta,
#'
#' @import Biobase
#' @import methods
#' @family peco classifier functions
#' @seealso \code{\link{cycle_npreg_insample}} for obtaining parameteres for
#' cyclic functions from training data,
#' \code{\link{cycle_npreg_loglik}} for log-likehood at
#' angles between 0 to 2pi,
#' \code{\link{initialize_grids}} for selecting
#' angles in \code{\link{cycle_npreg_loglik}},
#' \code{\link{cycle_npreg_mstep}} for estimating cyclic functions given
#' inferred phases from \code{\link{cycle_npreg_loglik}}
#' @export
cycle_npreg_outsample <- function(Y_test,
sigma_est,
Expand Down Expand Up @@ -357,6 +373,14 @@ cycle_npreg_outsample <- function(Y_test,
#' @return A vector of initialized angles to be used in
#' \code{cycle_npreg_loglik} to infer angles.
#'
#' @family peco classifier functions
#' @seealso
#' \code{\link{cycle_npreg_loglik}} for log-likehood at
#' angles between 0 to 2pi,
#' \code{\link{cycle_npreg_mstep}} for estimating cyclic functions given
#' inferred phases from \code{\link{cycle_npreg_loglik}},
#' \code{\link{cycle_npreg_outsample}} for predicting cell cycle phase
#' using parameters learned from \code{\link{cycle_npreg_insample}}
#' @author Joyce Hsiao
#'
initialize_grids <- function(Y, grids=100,
Expand Down Expand Up @@ -407,14 +431,20 @@ initialize_grids <- function(Y, grids=100,
#'
#' @return A list with the following three elements:
#'
#' \item{cell_times_est}{Inferred angles or cell cycle phases, NOT
#' \item{cell_times_est}{Inferred angles or cell cycle phases, NOT
#' ordered.}
#'
#' \item{loglik_est}{Log-likelihood estimates for each gene.}
#'
#' \item{prob_per_cell_by_celltimes}{Probabilities of each cell belong
#' \item{loglik_est}{Log-likelihood estimates for each gene.}
#' \item{prob_per_cell_by_celltimes}{Probabilities of each cell belong
#' to each bin.}
#'
#' @family peco classifier functions
#' @seealso \code{\link{initialize_grids}} for selecting
#' angles in \code{\link{cycle_npreg_loglik}},
#' \code{\link{cycle_npreg_mstep}} for estimating cyclic functions given
#' inferred phases from \code{\link{cycle_npreg_loglik}},
#' \code{\link{cycle_npreg_outsample}} for predicting cell cycle phase
#' using parameters learned from \code{\link{cycle_npreg_insample}}
#'
#' @author Joyce Hsiao
cycle_npreg_loglik <- function(Y, sigma_est, funs_est,
grids=100,
Expand Down Expand Up @@ -517,6 +547,13 @@ cycle_npreg_loglik <- function(Y, sigma_est, funs_est,
#' @import parallel
#' @import foreach
#'
#' @family peco classifier functions
#' @seealso
#' \code{\link{cycle_npreg_insample}} for estimating cyclic functions
#' given known phasesfrom training data,
#' \code{\link{cycle_npreg_outsample}} for predicting cell cycle phase
#' using parameters learned from \code{\link{cycle_npreg_insample}}
#'
#' @author Joyce Hsiao
cycle_npreg_mstep <- function(Y, theta, method.trend=c("trendfilter",
"loess", "bspline"),
Expand Down Expand Up @@ -547,39 +584,6 @@ cycle_npreg_mstep <- function(Y, theta, method.trend=c("trendfilter",
Y_ordered <- Y[,ord]
}

# for each gene, estimate the cyclical pattern of gene expression
# conditioned on the given cell times
# fit <- mclapply(seq_len(G), function(g) {
# y_g <- Y_ordered[g,]
#
# if (method.trend=="trendfilter") {
# fit_g <- fit_trendfilter_generic(yy=y_g, polyorder = polyorder)
# fun_g <- approxfun(x=as.numeric(theta_ordered),
# y=as.numeric(fit_g$trend.yy), rule=2)
# mu_g <- fit_g$trend.yy
# }
# if (method.trend=="bspline") {
# fit_g <- fit_bspline(yy=y_g, time = theta_ordered)
# fun_g <- approxfun(x=as.numeric(theta_ordered),
# y=as.numeric(fit_g$pred.yy), rule=2)
# mu_g <- fit_g$pred.yy
# }
#
# if (method.trend=="loess") {
# fit_g <- fit_loess(yy=y_g, time = theta_ordered)
# fun_g <- approxfun(x=as.numeric(theta_ordered),
# y=as.numeric(fit_g$pred.yy), rule=2)
# mu_g <- fit_g$pred.yy
# }
#
# sigma_g <- sqrt(sum((y_g-mu_g)^2)/N)
#
# list(y_g =y_g,
# mu_g=mu_g,
# sigma_g=sigma_g,
# fun_g=fun_g)
# }, mc.cores = ncores)

fit <- foreach::foreach(g=seq_len(G)) %dopar% {
y_g <- Y_ordered[g,]

Expand Down
5 changes: 4 additions & 1 deletion R/fit_cyclic_many.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#' @return A vector of proportion of variance explained for each gene.
#'
#' @examples
#' \dontrun{
#' library(Biobase)
#' data(eset_sub)
#' pdata <- pData(eset_sub)
Expand All @@ -55,9 +56,11 @@
#' yy_ordered <- counts_quant[,match(names(theta_ordered), colnames(counts_quant))]
#'
#' fit <- fit_cyclical_many(Y=yy_ordered, theta=theta_ordered)
#' }
#'
#' @author Joyce Hsiao
#'
#' @seealso
#' \code{\link{fit_cyclic_one}} for fitting one gene
#' @import doParallel
#' @import foreach
#' @import parallel
Expand Down
21 changes: 17 additions & 4 deletions man/cycle_npreg_insample.Rd

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

22 changes: 17 additions & 5 deletions man/cycle_npreg_loglik.Rd

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

12 changes: 12 additions & 0 deletions man/cycle_npreg_mstep.Rd

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

16 changes: 16 additions & 0 deletions man/cycle_npreg_outsample.Rd

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

5 changes: 5 additions & 0 deletions man/fit_cyclical_many.Rd

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

14 changes: 14 additions & 0 deletions man/initialize_grids.Rd

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

0 comments on commit 6e10318

Please sign in to comment.