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

Add optional scree plot to report #192

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 30 additions & 2 deletions assets/differentialabundance_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ params:
report_title: NULL,
report_author: NULL,
report_description: NULL,
report_scree: NULL
observations_type: NULL
observations: NULL # GSE156533.samplesheet.csv
observations_id_col: NULL
Expand Down Expand Up @@ -495,10 +496,12 @@ cat(paste0("\n### ", ucfirst(params$observations_type), " relationships\n"))
Principal components analysis was conducted based on the `r params$exploratory_n_features` most variable `r params$features_type`s. Each component was annotated with its percent contribution to variance.

```{r, echo=FALSE, results='asis'}
# Create nested list to save the percentVars for reusing in the scree plot
percentVar_list <- list()
for (assay_type in rev(names(assay_data))){

pca_data <- pca_datas[[assay_type]]

percentVar_list[[assay_type]] <- list()
for (iv in informative_variables){

cat(paste0("\n##### ", prettifyVariablename(assay_type), " (", iv, ")\n"))
Expand Down Expand Up @@ -543,6 +546,31 @@ for (assay_type in rev(names(assay_data))){

print(htmltools::tagList(do.call("plotly_scatterplot", plot_args)))
}
percentVar_list[[assay_type]][[iv]] <- percentVar
}
}
```

```{r, echo=FALSE, results='asis', eval=params$report_scree}
cat(paste0("\n#### Scree plot {.tabset}"))
cat(paste0("\nThe following scree plot visualizes what percentage of total variation in the data can be explained by each of the principal components computed.\n"))

for (assay_type in names(percentVar_list)) {
for (iv in names(percentVar_list[[assay_type]])) {
WackerO marked this conversation as resolved.
Show resolved Hide resolved
percentVarData <- data.frame(percentVar_list[[assay_type]][[iv]])
colnames(percentVarData) <- c("var_explained")
percentVarData$PCA <- as.numeric(rownames(percentVarData))
write.table(percentVarData, file=paste0("/home-link/iivow01/git/save_differentialabundance/error/", assay_type, "_", iv, "_varex.tsv"), quote=F, sep="\t")
cat(paste0("\n##### ", prettifyVariablename(assay_type), " (", iv, ")\n"))
print(
ggplot(percentVarData, aes(x=factor(PCA),y=var_explained, group=1)) +
theme_bw() +
geom_point(size=4) +
geom_line(linetype="dashed") +
xlab("PC") +
ylab("Percent variance explained")
)
cat("\n")
}
}
```
Expand Down Expand Up @@ -902,4 +930,4 @@ print( htmltools::tagList(datatable(versions_table, caption = "Software versions

```{r, echo=FALSE, results='asis'}
htmltools::includeMarkdown(params$citations)
```
```
1 change: 1 addition & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ params {
report_title = null
report_author = null
report_description = null
report_scree = false
WackerO marked this conversation as resolved.
Show resolved Hide resolved

// Sample sheet options
observations_type = 'sample'
Expand Down
5 changes: 5 additions & 0 deletions nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,11 @@
"default": "None",
"fa_icon": "fas fa-feather",
"description": "A description for reporting outputs"
},
"report_scree": {
"type": "boolean",
"default": "false",
"description": "Whether to generate a scree plot in the report"
}
},
"required": ["report_file", "logo_file", "css_file"]
Expand Down