-generate_a_page <- function(tids, gene_id = NULL) {
- n <- length(tids)
- ncol <- ifelse(is_gene, floor(sqrt(n)), ncol_per_page)
- nrow <- ifelse(is_gene, ceiling(n / ncol), nrow_per_page)
-
- par(mfrow = c(nrow, ncol), mar = c(1, 1, 2, 1))
- if (is_gene) par(oma = c(0, 0, 3, 0))
-
- for (i in 1:n) {
- vec <- readdepth[[tids[i]]]
- if (is.null(vec)) exit_with_error(paste("Cannot find transcript", tids[i], sep = ""))
- wiggle <- ifelse(vec[2] == "NA", rep(0, vec[1]), as.numeric(unlist(strsplit(vec[2], split = " "))))
- len <- length(wiggle)
- if (!show_uniq) {
- plot(wiggle, type = 'h')
- }
- else {
- vec <- readdepth_uniq[[tids[i]]]
- stopifnot(!is.null(vec))
- wiggle_uniq <- ifelse(vec[2] == "NA", rep(0, vec[1]), as.numeric(unlist(strsplit(vec[2], split = " "))))
- stopifnot(len == length(wiggle_uniq), len == sum(wiggle >= wiggle_uniq))
- heights <- rbind(wiggle_uniq, wiggle - wiggle_uniq)
- barplot(heights, space = 0, border = NA, names.arg = 1:len)
+make_a_plot <- function(id) {
+ vec <- readdepth[[id]]
+ if (is.null(vec)) exit_with_error(sprintf("Unknown %s detected, %s is not included in RSEM's indices.", ifelse(alleleS, "allele-specific transcript", "transcript"), id))
+ if (is.na(vec[[2]])) wiggle <- rep(0, vec[[1]]) else wiggle <- as.numeric(unlist(strsplit(vec[[2]], split = " ")))
+ len <- length(wiggle)
+ if (!show_uniq) {
+ plot(wiggle, type = "h")
+ } else {
+ vec <- readdepth_uniq[[id]]
+ stopifnot(!is.null(vec))
+ if (is.na(vec[[2]])) wiggle_uniq <- rep(0, vec[[1]]) else wiggle_uniq <- as.numeric(unlist(strsplit(vec[[2]], split = " ")))
+ stopifnot(len == length(wiggle_uniq))
+ if (len != sum(wiggle >= wiggle_uniq)) {
+ cat("Warning: ", ifelse(alleleS, "allele-specific transcript", "transcript"), " ", id, " has position(s) that read covarege with multireads is smaller than read covarge without multireads.\n", " The 1-based position(s) is(are) : ", which(wiggle < wiggle_uniq), ".\n", " This may be due to floating point arithmetics.\n", sep = "")