Skip to content

Commit

Permalink
added back format options
Browse files Browse the repository at this point in the history
  • Loading branch information
ssnn-airr committed Apr 17, 2024
1 parent 3ca98f3 commit 86274c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: repcred
Type: Package
Version: 0.0.1
Date: 2023-05-18
Date: 2024-04-17
Authors@R: c(person("Susanna", "Marquez", role=c("aut", "cre"),
email="[email protected]"),
person("AIRR Community", role=c("cph")))
Expand Down Expand Up @@ -38,7 +38,7 @@ Imports:
xfun,
Suggests:
testthat
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Collate:
'repcred.R'
'cdr3_check.R'
Expand Down
35 changes: 29 additions & 6 deletions R/repcred-core.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ repcredWeb <- function(appDir=system.file("shiny-app",
#' @param downsample Whether report will downsample repertoire
#' @param genome_file A reference set of the V(D)J alleles.
#' @param outdir Directory where the report will be generated
#' @param format Output format: html, pdf, all
#' @return Path to the credibility report.
#'
#' @examples
#'
#' rep_file <- system.file(package="repcred", "extdata", "ExampleDb.tsv")
#' repcred_report(rep_file, tempdir())
#' @export
repcred_report <- function(rep, outdir=NULL,genome_file=NULL, downsample=TRUE) {

repcred_report <- function(rep, outdir=NULL,genome_file=NULL, downsample=TRUE, format=c("html", "pdf", "all")) {
format <- match.arg(format)
if (file.exists(rep)) {
if (is.null(outdir)) {
outdir <- dirname(rep)
Expand All @@ -42,7 +43,7 @@ repcred_report <- function(rep, outdir=NULL,genome_file=NULL, downsample=TRUE) {

tryCatch(
{
report_path <- render_report(rep, outdir,genome_file,downsample)
report_path <- render_report(rep, outdir, genome_file, downsample, format)
},
error = function(e) {
stop(safeError(e))
Expand Down Expand Up @@ -98,9 +99,11 @@ getCoreStats <- function(data){
#' @param outdir Directory where the report will be generated
#' @param downsample Whether report will downsample repertoire
#' @param genome A reference set of the V(D)J alleles.
#' @param format Output format: html, pdf, all
#' @export
render_report <- function(rep,outdir,genome=NULL,downsample) {
path = "../rstudio/templates/project/project_files/"
render_report <- function(rep,outdir,genome=NULL,downsample=TRUE,format=c("html","pdf","all")) {
# path = "../rstudio/templates/project/project_files/"
format <- match.arg(format)
if (!dir.exists(outdir)) {
dir.create(outdir, recursive = T)
}
Expand All @@ -112,18 +115,38 @@ render_report <- function(rep,outdir,genome=NULL,downsample) {

#setwd("../rstudio/templates/project/project_files/")

if (format == "html") {
output_format <- 'bookdown::gitbook'
} else if (format == "pdf") {
output_format <- 'bookdown::pdf_book'
} else {
output_format <- format
}

# render
xfun::in_dir(
outdir,
book <- bookdown::render_book(
input = ".",
output_format='bookdown::gitbook',
output_format=output_format,
config_file ="_bookdown.yml",
clean=FALSE,
new_session=FALSE,
params=list("rep"=rep, outdir=outdir,"genome_file"=genome,
"downsample"=downsample))
)
if (format %in% c("pdf", "all")) {
is_pdf <- grepl("_main.pdf$",book)
for (i in which(is_pdf)) {
book_i <- gsub("_main.pdf$","repcred-report.pdf",book[i])
try(
if (file.rename(book[i],book_i)) {
book[i] <- book_i
}
)
}
}

book
}

Expand Down

0 comments on commit 86274c9

Please sign in to comment.