diff --git a/NAMESPACE b/NAMESPACE index ceab112..62b6d86 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,17 +3,15 @@ export(calculate_variance) export(calculate_zscore) export(plot_position) -export(ppr_accuracy_test) -export(ppr_cell_plot) -export(ppr_precision) -export(ppr_timeline_plot) +export(accuracy_test) +export(cell_plot) +export(precision) +export(timeline_plot) export(predict_position) export(print.PPR_OBJECT) export(subset_switching_genes) export(which_mid_max) exportClasses(PPR_OBJECT) -import(ggplot2) -import(ggrepel) importFrom(GeneSwitches,filter_switchgenes) importFrom(ggplot2,aes) importFrom(ggplot2,aes_string) diff --git a/R/ppr_accuracy_test.R b/R/accuracy_test.R similarity index 97% rename from R/ppr_accuracy_test.R rename to R/accuracy_test.R index 4882e3c..ba51cea 100644 --- a/R/ppr_accuracy_test.R +++ b/R/accuracy_test.R @@ -15,7 +15,7 @@ #' If plot = TRUE, returns a the accuracy data frame. #' @importFrom graphics abline hist text #' @export -ppr_accuracy_test <- function(sample_ppr, reference_sce, plot = TRUE) { +accuracy_test <- function(sample_ppr, reference_sce, plot = TRUE) { # Create a data frame to store the accuracy results accuracy <- data.frame( # Cell names from reference_sce diff --git a/R/ppr_cell_plot.R b/R/cell_plot.R similarity index 99% rename from R/ppr_cell_plot.R rename to R/cell_plot.R index 75c7c6a..cfdb78e 100644 --- a/R/ppr_cell_plot.R +++ b/R/cell_plot.R @@ -16,7 +16,7 @@ #' @importFrom graphics segments text lines #' @export #' -ppr_cell_plot <- function(sample_ppr, +cell_plot <- function(sample_ppr, cell_idx = 1, col = "red", overlay = FALSE, diff --git a/R/ppr_racinglines_plot.R b/R/ppr_racinglines_plot.R deleted file mode 100644 index 7d05332..0000000 --- a/R/ppr_racinglines_plot.R +++ /dev/null @@ -1,113 +0,0 @@ -#' @title Identify and Visualise each cells position. -#' -#' @description -#' Produces a plot for each cell which helps visualize how PathPinPointR is predicting the cells position. -#' -#' @param reference.sg A selection of switching genes which are evenly distributed through pseudo-time. -#' @param lines logical, do you want to include lines to indicate the predicted position of a cell -#' @param reference_reduced a matrix of your sample's binary gene expression. -#' @param cell_id The index or name of the cell of interest -#' -#' @return Timeline plot of selected cell -#' @import ggplot2 -#' @import ggrepel -#' -#' -#' @export -#' - -ppr_timeline_plot <- function(reference.sg, lines = TRUE, reference_reduced = NULL, cell_id = 1) { - - # Convert reference.sg to a data frame - reference.sg <- as.data.frame(reference.sg) - - # Add a new column direction_num and set it to -1 - reference.sg$direction_num <- -1 - - # If "up" is present in the direction column, set direction_num to 1 - if ("up" %in% reference.sg$direction) { - reference.sg[reference.sg$direction == "up", ]$direction_num <- 1 - } - - # Generate pseudotime data based on the specified parameters - timeidx_df <- data.frame(timeidx_range = c(0, 25, 50, 75, 100), timeidx_labs = c(0, 25, 50, 75, 100)) - - - # Create the initial ggplot object with x and y aesthetics, color, and labels - timeline_plot <- ggplot(reference.sg, aes(x = switch_at_timeidx, y = pseudoR2s * direction_num, label = rownames(reference.sg))) + - geom_point(size = 1) + xlab("Time-Index") + ylab("Quality of fitting (R^2)") - - # Add the classic theme to the plot - timeline_plot <- timeline_plot + theme_classic() - - # Add a horizontal black line for the timeline - timeline_plot <- timeline_plot + geom_hline(yintercept = 0, color = "black", linewidth = 0.6) - - # Add labels for pseudotime on the plot - timeline_plot <- timeline_plot + geom_label(data = timeidx_df, aes(x = timeidx_range, y = 0, label = timeidx_labs), - size = (3), color = "black") - - # Add text labels with repulsion to avoid overlap - timeline_plot <- timeline_plot + geom_text_repel(aes(x = switch_at_timeidx, y = pseudoR2s * direction_num, label = rownames(reference.sg)), - size = 3, show.legend = FALSE) - - # Customize the theme and legend appearance - timeline_plot <- timeline_plot + theme(legend.position = "bottom", legend.title = element_blank(), legend.key.size = unit(10, "pt"), - text = element_text(size = 12)) - - -if (lines) { - - if (is.character(cell_id)) { - cell_idx <- which(colnames(reference_reduced) == cell_id) - } else if (is.numeric(cell_id)) { - # Convert numeric to integer if needed - cell_idx <- as.integer(cell_id) - } else { - stop("cell_id must be character or numeric.") - } - - ## Reorder reference.sg - # as the code relies on the rownames and idicies of the genes in reference_reduced and reference.sg matching. - reference_reduced <- reference_reduced[rownames(reference.sg),] - - # Check if row names in reference.sg match those in reference_reduced - if (!setequal(rownames(reference.sg), rownames(reference_reduced))) { - stop("Row names in reference.sg do not match those in reference_reduced") - } - - #loop through all of the genes in reference.sg. - for (g in 1:dim(reference.sg)[1]) { - # if G is NOT expressed in C, and the switch is UP , then draw the line to the right. - if ((reference_reduced[rownames(reference.sg)[g], cell_idx] == 0) && (reference.sg$direction[g] == "up")) { - timeline_plot <- timeline_plot + geom_segment(aes_string(x = 0, xend = reference.sg$switch_at_timeidx[g], y = reference.sg$pseudoR2s[g], yend = reference.sg$pseudoR2s[g]), - color = "blue", linewidth = 0.6) - } - # if G is expressed in c, and the switch is UP , then draw the line to the right. - if ((reference_reduced[rownames(reference.sg)[g], cell_idx] == 1) && (reference.sg$direction[g] == "up")) { - timeline_plot <- timeline_plot + geom_segment(aes_string(x = reference.sg$switch_at_timeidx[g], xend = 100, y = reference.sg$pseudoR2s[g], yend = reference.sg$pseudoR2s[g]), - color = "blue", linewidth = 0.6) - } - # if G is NOT expressed in C, and the switch is Down, then draw the line to the Left. - if ((reference_reduced[rownames(reference.sg)[g], cell_idx] == 0) && (reference.sg$direction[g] == "down")) { - timeline_plot <- timeline_plot + geom_segment(aes_string(x = reference.sg$switch_at_timeidx[g], xend = 100, y = -reference.sg$pseudoR2s[g], yend = -reference.sg$pseudoR2s[g]), - color = "blue", linewidth = 0.6) - } - # if G is expressed in C, and the switch is Down, then draw the line to the Left. - if ((reference_reduced[rownames(reference.sg)[g], cell_idx] == 1) && (reference.sg$direction[g] == "down")) { - timeline_plot <- timeline_plot + geom_segment(aes_string(x = 0, xend = reference.sg$switch_at_timeidx[g], y = -reference.sg$pseudoR2s[g], yend = -reference.sg$pseudoR2s[g]), - color = "blue", linewidth = 0.6) - } - } - -# Title the plot with the name of the cell -timeline_plot <- timeline_plot + ggtitle(colnames(reference_reduced)[cell_idx]) - - -} - -# Return the final plot -return(timeline_plot) - -} - diff --git a/R/ppr_precision.R b/R/precision.R similarity index 96% rename from R/ppr_precision.R rename to R/precision.R index 8cbe61b..9f7c7d5 100644 --- a/R/ppr_precision.R +++ b/R/precision.R @@ -1,4 +1,4 @@ -#' ppr_precision +#' precision #' #' @description #' Used to find the optimum r2cutoff to use, @@ -15,7 +15,7 @@ #' #' #' @export -ppr_precision <- function(sce, +precision <- function(sce, r2_cutoff_range = seq(0.0, 0.5, 0.1), plot = TRUE) { @@ -58,7 +58,7 @@ ppr_precision <- function(sce, sample_ppr <- predict_position(sample_reduced, switching_genes) # - accuracy <- ppr_accuracy_test(sample_ppr = sample_ppr, + accuracy <- accuracy_test(sample_ppr = sample_ppr, reference_sce = sce, plot = FALSE) # diff --git a/R/ppr_timeline_plot.R b/R/timeline_plot.R similarity index 99% rename from R/ppr_timeline_plot.R rename to R/timeline_plot.R index 1614d99..5bc50a0 100644 --- a/R/ppr_timeline_plot.R +++ b/R/timeline_plot.R @@ -17,7 +17,7 @@ #' #' #' @export -ppr_timeline_plot <- function(switching_genes, +timeline_plot <- function(switching_genes, genomic_expression_traces = FALSE, reduced_sce = NULL, cell_id = 1) { diff --git a/R/ppr_utils.R b/R/utils.R similarity index 100% rename from R/ppr_utils.R rename to R/utils.R diff --git a/R/ppr_welcome.R b/R/welcome_to_PathPinpointR.R similarity index 100% rename from R/ppr_welcome.R rename to R/welcome_to_PathPinpointR.R diff --git a/man/PPR_OBJECT-class.Rd b/man/PPR_OBJECT-class.Rd index 9590c34..26168b3 100644 --- a/man/PPR_OBJECT-class.Rd +++ b/man/PPR_OBJECT-class.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_utils.R +% Please edit documentation in R/utils.R \docType{class} \name{PPR_OBJECT-class} \alias{PPR_OBJECT-class} diff --git a/man/ppr_accuracy_test.Rd b/man/ppr_accuracy_test.Rd index 2d1760f..31ddc33 100644 --- a/man/ppr_accuracy_test.Rd +++ b/man/ppr_accuracy_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_accuracy_test.R -\name{ppr_accuracy_test} -\alias{ppr_accuracy_test} +% Please edit documentation in R/accuracy_test.R +\name{accuracy_test} +\alias{accuracy_test} \title{accuracy_test} \usage{ -ppr_accuracy_test(sample_ppr, reference_sce, plot = TRUE) +accuracy_test(sample_ppr, reference_sce, plot = TRUE) } \arguments{ \item{sample_ppr}{A "PPR_OBJECT" which originates from the reference, diff --git a/man/ppr_cell_plot.Rd b/man/ppr_cell_plot.Rd index bdc2261..fd5f9c9 100644 --- a/man/ppr_cell_plot.Rd +++ b/man/ppr_cell_plot.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_cell_plot.R -\name{ppr_cell_plot} -\alias{ppr_cell_plot} +% Please edit documentation in R/cell_plot.R +\name{cell_plot} +\alias{cell_plot} \title{PPR INDIVIDUAL CELL PLOT} \usage{ -ppr_cell_plot( +cell_plot( sample_ppr, cell_idx = 1, col = "red", diff --git a/man/ppr_precision.Rd b/man/ppr_precision.Rd index 445509e..c303479 100644 --- a/man/ppr_precision.Rd +++ b/man/ppr_precision.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_precision.R -\name{ppr_precision} -\alias{ppr_precision} -\title{ppr_precision} +% Please edit documentation in R/precision.R +\name{precision} +\alias{precision} +\title{precision} \usage{ -ppr_precision(sce, r2_cutoff_range = seq(0, 0.5, 0.1), plot = TRUE) +precision(sce, r2_cutoff_range = seq(0, 0.5, 0.1), plot = TRUE) } \arguments{ \item{sce}{SingleCellExperiement object, diff --git a/man/ppr_timeline_plot.Rd b/man/ppr_timeline_plot.Rd index 77e3e74..b71373a 100644 --- a/man/ppr_timeline_plot.Rd +++ b/man/ppr_timeline_plot.Rd @@ -1,17 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_racinglines_plot.R, R/ppr_timeline_plot.R -\name{ppr_timeline_plot} -\alias{ppr_timeline_plot} +% Please edit documentation in R/timeline_plot.R +\name{timeline_plot} +\alias{timeline_plot} \title{Identify and Visualise each cells position.} \usage{ -ppr_timeline_plot( - switching_genes, - genomic_expression_traces = FALSE, - reduced_sce = NULL, - cell_id = 1 -) - -ppr_timeline_plot( +timeline_plot( switching_genes, genomic_expression_traces = FALSE, reduced_sce = NULL, @@ -28,21 +21,11 @@ Do you want lines which indicate the predicted position of the selected cell.} that you have already run PathPinPointR::subset_switching_genes() on.} \item{cell_id}{The index or name of the cell of interest} - -\item{reference.sg}{A selection of switching genes which are evenly distributed through pseudo-time.} - -\item{lines}{logical, do you want to include lines to indicate the predicted position of a cell} - -\item{reference_reduced}{a matrix of your sample's binary gene expression.} } \value{ -Timeline plot of selected cell - Timeline plot of selected cell } \description{ -Produces a plot for each cell which helps visualize how PathPinPointR is predicting the cells position. - Produces a plot for a given cell, this helps visualize predicted position of the selected cell. } diff --git a/man/print-PPR_OBJECT-method.Rd b/man/print-PPR_OBJECT-method.Rd index c97a7f7..3dbff84 100644 --- a/man/print-PPR_OBJECT-method.Rd +++ b/man/print-PPR_OBJECT-method.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_utils.R +% Please edit documentation in R/utils.R \name{print,PPR_OBJECT-method} \alias{print,PPR_OBJECT-method} \title{Set Default Print Method for PPR_OBJECT} diff --git a/man/print.PPR_OBJECT.Rd b/man/print.PPR_OBJECT.Rd index 0c47ae7..7e1410b 100644 --- a/man/print.PPR_OBJECT.Rd +++ b/man/print.PPR_OBJECT.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_utils.R +% Please edit documentation in R/utils.R \name{print.PPR_OBJECT} \alias{print.PPR_OBJECT} \title{Print method for PPR Object.} diff --git a/man/which_mid_max.Rd b/man/which_mid_max.Rd index 12c556f..33645e6 100644 --- a/man/which_mid_max.Rd +++ b/man/which_mid_max.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ppr_utils.R +% Please edit documentation in R/utils.R \name{which_mid_max} \alias{which_mid_max} \title{Select the middle index among multiple occurrences of the maximum value}