Skip to content

Commit

Permalink
add -h flag to Rscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-mRNA committed Jul 1, 2024
1 parent f9c5740 commit 4acf604
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions scripts/R2_plotMetaCodon.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ help_message <- function() {
args <- commandArgs(trailingOnly = TRUE)
options <- list(ci_method = "loess", output_path = NULL, add_labels = FALSE, plot_from = NULL)

# help message
if ("-h" %in% args || length(args) == 0) {
help_message()
quit(status = 0)
Expand Down Expand Up @@ -53,6 +54,7 @@ if (!plot_from_specified) {
stop("Error: Either -s or -e flag must be specified.")
}

# check remaining positional arguments
if (length(remaining_args) != 5) {
help_message()
stop("Error: Incorrect number of positional arguments.")
Expand Down
9 changes: 7 additions & 2 deletions scripts/R2_plotMetaJunction.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env Rscript

## read positional arguments while ensuring that the correct number of inputs are provided
# read positional arguments while ensuring that the correct number of inputs are provided
args <- commandArgs(trailingOnly = TRUE)

# help message
if ("-h" %in% args || length(args) == 0) {
stop("\nUsage: Rscript R2_plotMetaJunction.R '/path/to/annotated.bed' '/path/to/output.png' '<probability field>' '<cutoff>' '<upper/lower>' [-c 'loess'/'binom'] [-o '/path/to/output_table.tsv']", call. = FALSE)
}

# check for positional argument for the confidence interval method
# options are "loess" (default) or binomial confidence interval (-c binom)
ci_method <- "loess"
Expand All @@ -20,7 +25,7 @@ if ("-o" %in% args) {
args <- args[-c(index, index + 1)] # Remove the flag and its value from the args
}

# check number of positional arguments
# check remaining positional arguments
if (length(args) != 5) {
stop("\nUsage: Rscript R2_plotMetaJunction.R '/path/to/annotated.bed' '/path/to/output.png' '<probability field>' '<cutoff>' '<upper/lower>' [-c 'loess'/'binom'] [-o '/path/to/output_table.tsv']", call. = FALSE)
}
Expand Down
13 changes: 9 additions & 4 deletions scripts/R2_plotMetaTranscript.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env Rscript

## read positional arguments while ensuring that the correct number of inputs are provided
# read positional arguments
args <- commandArgs(trailingOnly = TRUE)

## check for positional arguments
# help message
if ("-h" %in% args || length(args) == 0) {
stop("\nUsage: Rscript R2_plotMetaTranscript.R '/path/to/annotated.bed' '/path/to/output.png' '<probability field>' '<cutoff>' '<upper/lower>' [-c 'loess'/'binom'] [-o '/path/to/output.tsv']", call. = FALSE)
}

# -c flag for selecting confidence interval method, options are loess (default), or binom confint (-c binom)
ci_method <- "loess"
Expand All @@ -29,6 +32,7 @@ if ("-l" %in% args) {
args <- args[-index]
}

# check remaining positional arguments
if (length(args) != 5) {
stop("\nUsage: Rscript R2_plotMetaTranscript.R '/path/to/annotated.bed' '/path/to/output.png' '<probability field>' '<cutoff>' '<upper/lower>' [-c 'loess'/'binom'] [-o '/path/to/output.tsv']", call. = FALSE)
}
Expand Down Expand Up @@ -76,7 +80,7 @@ filter_calls <- function(input_file, col_name, cutoff, direction) {
return(calls)
}

# define function to calculate the proportion of significant sites in metatranscript bins based on the "transcript_metacoordinate" column from R2D_annotate
# calculate the proportion of significant sites in metatranscript bins based on the "transcript_metacoordinate" column from R2D_annotate
compute_ratio <- function(calls, ci_method) {
breaks <- seq(0, 3, 0.025) # bin interval can be changed here, default, 120 bins of width 0.025
out_ratio <- calls %>%
Expand All @@ -96,6 +100,7 @@ compute_ratio <- function(calls, ci_method) {
return(out_ratio)
}

# make metatranscript plot
plot_ratio <- function(out_ratio, ci_method, add_labels) {
if (nrow(out_ratio) == 0 || is.infinite(max(out_ratio$interval))) {
stop("out_ratio is empty or contains invalid interval data.")
Expand All @@ -120,7 +125,7 @@ plot_ratio <- function(out_ratio, ci_method, add_labels) {
xlab("Relative metatranscriptomic location") + ylab("Proportion of significant sites") +
geom_vline(xintercept = c(80,40), col = "black") +
scale_x_continuous(breaks = seq(0, 3, by = 0.5), limits = c(0, 3)) + # show x-axis in original metatranscript coordinates
expand_limits(y = y_limit) # Use expand_limits instead of coord_cartesian
expand_limits(y = y_limit)

if (add_labels) {
p <- p +
Expand Down

0 comments on commit 4acf604

Please sign in to comment.