Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Plots #36

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ extdata/
inst/doc
/doc/
/Meta/
.Rbuildignore
.Rbuildignore
test_dev
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: scMaSigPro
Type: Package
Title: Application of MaSigPro Bioconductor Package for scRNA Trajectory data
Version: 0.0.1
Version: 0.0.2
Authors@R: c(
person("Ana", "Conesa", role = c("aut"), email = "ana.conesa@csic.es"),
person("Maria Jose", "Nueda", role = c("aut"), email = "mj.nueda@ua.es"),
Expand Down
14 changes: 13 additions & 1 deletion R/plotTrend.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ plotTrend <- function(scmpObj,
pooled.time <- "pooled.time"
path <- "path"

# Offset
offset_vector <- scmpObj@Design@offset

# Check summary_mode
assert_that(any(summary_mode %in% c("median", "mean")),
msg = paste(
Expand Down Expand Up @@ -144,6 +147,11 @@ plotTrend <- function(scmpObj,
data.sol <- showSol(scmpObj, view = FALSE, return = TRUE)
data.sol <- data.sol[feature_id, , drop = FALSE]

# Correct by offset
if (sum(offset_vector) != 0) {
points.df["pb.counts"] <- points.df["pb.counts"] / exp(offset_vector)
}

# if log is requestion
if (logs) {
if (logType == "log2") {
Expand Down Expand Up @@ -174,10 +182,14 @@ plotTrend <- function(scmpObj,
summarize(pb.counts = median(pb.counts), .groups = "drop")
}

if (sum(offset_vector) != 0) {
line.df <- points.df
}

# Plot
p <- ggplot() +
geom_point(data = points.df, aes(x = pooled.time, y = pb.counts, color = path), fill = "#102C57", alpha = 0.5, size = 2, stroke = 1, shape = 21) +
geom_line(data = line.df, aes(x = pooled.time, y = .data$pb.counts, color = path), linetype = "solid", linewidth = 1, alpha = 0.7) +
geom_line(data = line.df, aes(x = pooled.time, y = pb.counts, color = path), linetype = "solid", linewidth = 1, alpha = 0.7) +
geom_line(data = curve.df, aes(x = x, y = y, color = path), linetype = "dashed", linewidth = 1, alpha = 0.7) +
ggtitle(
paste("Feature Id:", feature_id),
Expand Down
13 changes: 12 additions & 1 deletion R/plotTrendCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ plotTrendCluster <- function(scmpObj,
# Global vars
scmp_clusters <- "scmp_clusters"
feature_id <- "feature_id"
# Offset
offset_vector <- scmpObj@Design@offset

# Check
assert_that(!isEmpty(scmpObj@Significant@clusters),
Expand Down Expand Up @@ -103,7 +105,7 @@ plotTrendCluster <- function(scmpObj,
logs = log, logType = log_type,
pseudoCount = pCount,
significant = sig,
summary_mode = summary
summary_mode = summary,
)
return(plt)
},
Expand Down Expand Up @@ -264,6 +266,15 @@ plotTrendCluster <- function(scmpObj,
" (", curves_combined[["num"]], " Features)"
)

if (sum(offset_vector) != 0) {
lines_combined <- points_combined
}


# View(points_combined)
# View(curves_combined)
# View(lines_combined)

# Initiate plotting
p <- ggplot() +
geom_point(
Expand Down
23 changes: 9 additions & 14 deletions R/sc.squeeze.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ sc.squeeze <- function(scmpObj,
aggregate = "sum",
fill_gaps = FALSE,
additional_params = list(use_unique_time_points = FALSE)) {
# suppressPackageStartupMessages(library(entropy))
# suppressPackageStartupMessages(library(assertthat))
# suppressPackageStartupMessages(library(SingleCellExperiment))
# Initiate Variable
scmp_bin_lower_bound <- "scmp_l_bound"
scmp_bin_upper_bound <- "scmp_u_bound"
Expand Down Expand Up @@ -286,20 +289,12 @@ sc.squeeze <- function(scmpObj,
# Increment the iteration counter
it <- it + 1
}
}

if (verbose) {
message(paste(
"Optimizing bin sizes, with maximum allowed bin size as",
max.allowed
))
}

if (verbose) {
message(paste(
"Finally, for", path, ",", length_n, "time points has been compressed to",
nrow(bin_table), "bins and the sum is ", sum(bin_table[[bin.size]])
))
if (verbose) {
message(paste(
"Finally, for", path, ",", length_n, "time points has been compressed to",
nrow(bin_table), "bins and the sum is ", sum(bin_table[[bin.size]])
))
}
}

rownames(bin_table) <- NULL
Expand Down
16 changes: 14 additions & 2 deletions vignettes/Basic-Workflow.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ different expression between the two paths. Additionally, there are 10 genes
uniquely associated with Path2vsPath1. This implies that Path2 has 10 genes that
are significantly differentially expressed over time, using Path1 genes as a
reference. Let's explore a few of these genes:
```{r, "trend",eval=TRUE, echo=TRUE}
```{r, "trend",eval=TRUE, echo=TRUE, fig.width=7, fig.height=7}
FigureA <- plotTrend(scmp_ob, "Gene9", logs = TRUE, logType = "log")
FigureB <- plotTrend(scmp_ob, "Gene95", logs = TRUE, logType = "log")
FigureC <- plotTrend(scmp_ob, "Gene10", logs = TRUE, logType = "log")
Expand All @@ -339,7 +339,7 @@ These plots illustrate the gene expression trends for selected genes, providing
insights into their behavior in different paths. Fortunately, since we are using
simulated data, we can validate these trends by extracting gene-level metadata
from our simulated object:
```{r, "ground truth",eval=TRUE, echo=TRUE}
```{r, "ground truth",eval=TRUE, echo=TRUE, fig.width=7, fig.height=7}
groundTruth <- as.data.frame(splat.sim@rowRanges@elementMetadata)
print(groundTruth[groundTruth$Gene %in% c("Gene9", "Gene95", "Gene10", "Gene92"), c(1, 2, 6, 8)])
```
Expand Down Expand Up @@ -382,6 +382,18 @@ further biological interpretation.
This concludes the basic usage quick start guide of `scMaSigPro`. Please refer
to other vignettes for more in-depth analysis.

```{r, "Save and Reload", eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE}
# Save the object
save(splat.sim, file = "../data/splat.sim.RData")

# Save processed data for next tutorial
scmp.ob <- scmp_ob
save(scmp.ob, file = "../data/scmp.ob.RData")

# Compress
tools::resaveRdaFiles(paths = "../data/")
```

---

### Session Info
Expand Down
2 changes: 1 addition & 1 deletion vignettes/scMaSigPro-maSigPro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ plotTrendCluster(
scmpObj = scmp_ob,
plot = "coeff",
verbose = FALSE
)
)
```

---
Expand Down
Loading