Skip to content

Commit

Permalink
Add parameter loess-span
Browse files Browse the repository at this point in the history
  • Loading branch information
spriyansh committed Jul 30, 2024
1 parent ebd710d commit 635b497
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 107 deletions.
31 changes: 16 additions & 15 deletions R/plotTrend.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ plotTrend <- function(scmpObj,

# Check
assertthat::assert_that(all(feature_id %in% rownames(bulk.counts)),
msg = "Feature Id doesn't exist please select another one"
msg = paste0("'", feature_id, "' doesn't exist please select another one.")
)

if (significant) {
Expand Down Expand Up @@ -181,21 +181,22 @@ plotTrend <- function(scmpObj,

# if log is requestion
suppressWarnings(
expr = {
if (logs) {
if (logType == "log2") {
points.df$pb.counts <- log2(points.df$pb.counts + pseudoCount)
ylab <- paste0("log2(", ylab, ")")
} else if (logType == "log") {
points.df$pb.counts <- log(points.df$pb.counts + pseudoCount)
ylab <- paste0("log(", ylab, ")")
} else if (logType == "log10") {
points.df$pb.counts <- log10(points.df$pb.counts + pseudoCount)
ylab <- paste0("log10(", ylab, ")")
} else {
stop("'logType' should be one of 'log2', 'log10', 'log'")
expr = {
if (logs) {
if (logType == "log2") {
points.df$pb.counts <- log2(points.df$pb.counts + pseudoCount)
ylab <- paste0("log2(", ylab, ")")
} else if (logType == "log") {
points.df$pb.counts <- log(points.df$pb.counts + pseudoCount)
ylab <- paste0("log(", ylab, ")")
} else if (logType == "log10") {
points.df$pb.counts <- log10(points.df$pb.counts + pseudoCount)
ylab <- paste0("log10(", ylab, ")")
} else {
stop("'logType' should be one of 'log2', 'log10', 'log'")
}
}
}
}}
)

# Generate line.df
Expand Down
87 changes: 45 additions & 42 deletions R/plotTrendCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#' @param curves Whether to plot the fitted curves. (Default is TRUE)
#' @param lines Whether to plot the lines. (Default is FALSE)
#' @param points Whether to plot the points. (Default is TRUE)
#' @param loess_span The fraction of the data used when estimating each y-value,
#' when plotting curves. (Default is 0.75)
#'
#' @return ggplot2 plot object.
#' @author Priyansh Srivastava \email{spriyansh29@@gmail.com}
Expand All @@ -48,7 +50,8 @@ plotTrendCluster <- function(scmpObj,
curves = TRUE,
lines = FALSE,
points = TRUE,
parallel = FALSE) {
parallel = FALSE,
loess_span = 0.8) {
# # # Debugg
# scmpObj <- multi_scmp_ob_A
# xlab <- "Pooled Pseudotime"
Expand Down Expand Up @@ -359,48 +362,48 @@ plotTrendCluster <- function(scmpObj,
# Initiate plotting
p <- ggplot()

suppressWarnings(expr = {
if (points) {
p <- p + geom_point(
data = points_combined, aes(x = .data$x_axis, y = .data$y_axis, color = .data$group),
fill = "#102C57", alpha = 0.5, size = 0.5, stroke = 0.5, shape = 21
)
}
if (lines) {
p <- p + geom_path(
data = lines_combined,
aes(
x = .data$x_axis, y = .data$y_axis, color = .data$group, group = .data$group,
), linetype = "dashed", linewidth = 0.5
)
}
if (points) {
p <- p + geom_point(
data = points_combined, aes(x = .data$x_axis, y = .data$y_axis, color = .data$group),
fill = "#102C57", alpha = 0.5, size = 0.5, stroke = 0.5, shape = 21
)
}
if (lines) {
p <- p + geom_path(
data = lines_combined,
aes(
x = .data$x_axis, y = .data$y_axis, color = .data$group, group = .data$group,
), linetype = "dashed", linewidth = 0.5
)
}

if (curves) {
p <- p + geom_smooth(
data = curves_combined,
se = FALSE,
formula = y ~ x, span = 0.7,
method = "loess",
aes(
x = .data$x_axis, y = .data$y_axis, color = .data$group, group = .data$group,
), linetype = "solid", linewidth = 0.5
)
}
if (curves) {
p <- p + geom_smooth(
data = curves_combined,
se = FALSE,
# formula = y ~ s(x , k = scmpObj@Parameters@poly_degree, bs = "cs"),
# method = "gam",
formula = y ~ x,
method = "loess", span = loess_span,
aes(
x = .data$x_axis, y = .data$y_axis, color = .data$group, group = .data$group,
), linetype = "solid", linewidth = 0.5
)
}

p <- p + facet_wrap(~ .data$cluster, scales = "free_y") + # Create a panel for each cluster_id
scale_color_manual(values = scmp_colors(length(unique(cDense(scmpObj)[[scmpObj@Parameters@path_col]])))) + # Custom colors for paths
theme_classic(base_size = 10) +
theme(
strip.background = element_blank(),
strip.text.x = element_text(size = 10, angle = 0),
legend.position = "bottom", legend.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "grey90", linewidth = 0.3, linetype = "dashed"),
panel.grid.minor = element_blank(),
axis.text.x = element_text(angle = 45, hjust = 1) # Rotate x-axis text if necessary
) +
labs(title = "Gene Expression over Pseudotime", color = "Branching Path") +
xlab(xlab) +
ylab(ylab)
})
p <- p + facet_wrap(~ .data$cluster, scales = "free_y") + # Create a panel for each cluster_id
scale_color_manual(values = scmp_colors(length(unique(cDense(scmpObj)[[scmpObj@Parameters@path_col]])))) + # Custom colors for paths
theme_classic(base_size = 10) +
theme(
strip.background = element_blank(),
strip.text.x = element_text(size = 10, angle = 0),
legend.position = "bottom", legend.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "grey90", linewidth = 0.3, linetype = "dashed"),
panel.grid.minor = element_blank(),
axis.text.x = element_text(angle = 45, hjust = 1) # Rotate x-axis text if necessary
) +
labs(title = "Gene Expression over Pseudotime", color = "Branching Path") +
xlab(xlab) +
ylab(ylab)
return(p)
}
6 changes: 5 additions & 1 deletion man/plotTrendCluster.Rd

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

22 changes: 12 additions & 10 deletions vignettes/Basic-Workflow.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,31 @@ Currently, `scMaSigPro` is available on GitHub and can be installed as follows:
### Bioconductor and Dependencies
```{r, eval=FALSE, echo=TRUE}
# Install Dependencies
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install(version = "3.14")
BiocManager::install(c('SingleCellExperiment', 'maSigPro', 'MatrixGenerics', 'S4Vectors'))
BiocManager::install(c("SingleCellExperiment", "maSigPro", "MatrixGenerics", "S4Vectors"))
```

### scMaSigPro latest version
To install `scMaSigPro` from GitHub, use the following R code:
```{r, eval=FALSE, echo=TRUE}
# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
install.packages("devtools")
}
# Install scMaSigPro
devtools::install_github("BioBam/scMaSigPro",
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE)
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE
)
```

## Basic Workflow
Expand Down
34 changes: 15 additions & 19 deletions vignettes/Common-Root-Cells.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,31 @@ Currently, `scMaSigPro` is available on GitHub and can be installed as follows:
### Bioconductor and Dependencies
```{r, eval=FALSE, echo=TRUE}
# Install Dependencies
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install(version = "3.14")
BiocManager::install(c('SingleCellExperiment', 'maSigPro', 'MatrixGenerics', 'S4Vectors'))
BiocManager::install(c("SingleCellExperiment", "maSigPro", "MatrixGenerics", "S4Vectors"))
```

### scMaSigPro latest version
To install `scMaSigPro` from GitHub, use the following R code:
```{r, eval=FALSE, echo=TRUE}
# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
install.packages("devtools")
}
# Install scMaSigPro
devtools::install_github("BioBam/scMaSigPro",
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE)
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE
)
```

## Setup
Expand Down Expand Up @@ -298,8 +300,8 @@ gene_br_Y_15 <- rownames(shared_genes[shared_genes$Y_52vsroot == 1 &
shared_genes$Y_18vsroot == 1 &
shared_genes$Y_15vsroot == 0 &
shared_genes$root == 1 &
shared_genes$Y_18_links_Y_15vsroot == 0, ])
# plotTrend(multi_scmp_ob_A, gene_br_Y_15[1], points = F, lines = T)
shared_genes$Y_18_links_Y_15vsroot == 0, ]) # "G42"
plotTrend(multi_scmp_ob_A, feature_id = "G42", points = F, lines = T)
```

In the above plot, we can see that the gene G42 has a similar expression in the
Expand All @@ -317,7 +319,7 @@ in groups.
multi_scmp_ob_A <- scMaSigPro::sc.cluster.trend(multi_scmp_ob_A)
# Plot Clusters
plotTrendCluster(multi_scmp_ob_A, verbose = FALSE)
plotTrendCluster(multi_scmp_ob_A, verbose = FALSE, loess_span = 0.8)
```

# Ordering Common Cells (Approach-2)
Expand Down Expand Up @@ -478,12 +480,6 @@ multi_scmp_ob_B <- sc.filter(
plotIntersect(multi_scmp_ob_B)
```

```{r}
## Extract shared genes
shared_genes <- plotIntersect(multi_scmp_ob_B, return = TRUE)
head(shared_genes)
```

Now, in the above scenario, Y_15 is treated as the reference, and we will look
at the genes that are expressed differently compared to this branch. This approach
will help us understand how genes are changing across the branches while considering
Expand Down
22 changes: 12 additions & 10 deletions vignettes/scMaSigPro-Class.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,31 @@ Currently, `scMaSigPro` is available on GitHub and can be installed as follows:
### Bioconductor and Dependencies
```{r, eval=FALSE, echo=TRUE}
# Install Dependencies
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install(version = "3.14")
BiocManager::install(c('SingleCellExperiment', 'maSigPro', 'MatrixGenerics', 'S4Vectors'))
BiocManager::install(c("SingleCellExperiment", "maSigPro", "MatrixGenerics", "S4Vectors"))
```

### scMaSigPro latest version
To install `scMaSigPro` from GitHub, use the following R code:
```{r, eval=FALSE, echo=TRUE}
# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
install.packages("devtools")
}
# Install scMaSigPro
devtools::install_github("BioBam/scMaSigPro",
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE)
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE
)
```

## Dataset
Expand Down
22 changes: 12 additions & 10 deletions vignettes/scMaSigPro-maSigPro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,31 @@ Currently, `scMaSigPro` is available on GitHub and can be installed as follows:
### Bioconductor and Dependencies
```{r, eval=FALSE, echo=TRUE}
# Install Dependencies
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install(version = "3.14")
BiocManager::install(c('SingleCellExperiment', 'maSigPro', 'MatrixGenerics', 'S4Vectors'))
BiocManager::install(c("SingleCellExperiment", "maSigPro", "MatrixGenerics", "S4Vectors"))
```

### scMaSigPro latest version
To install `scMaSigPro` from GitHub, use the following R code:
```{r, eval=FALSE, echo=TRUE}
# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
install.packages("devtools")
}
# Install scMaSigPro
devtools::install_github("BioBam/scMaSigPro",
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE)
ref = "main",
build_vignettes = FALSE,
build_manual = TRUE,
upgrade = "never",
force = TRUE,
quiet = TRUE
)
```

### Installing `maSigPro`
Expand Down

0 comments on commit 635b497

Please sign in to comment.