- data <- read.table(file = filename, sep = "\t", stringsAsFactors = FALSE)
- t2gmap <- list()
-
- nrow <- dim(data)[1]
- ncol <- dim(data)[2]
-
- gene_id <- ""
- tids <- c()
- for (i in 1:nrow) {
- if (gene_id != data[i, ncol]) {
- if (gene_id != "") {
- t2gmap[[gene_id]] <- tids
- }
- gene_id <- data[i, ncol]
- tids <- c()
+ tpos <- 1 # the position of transcript_id
+ gpos <- 2 # the position of gene_id
+
+ data <- read.delim(file = filename, sep = "\t", stringsAsFactors = FALSE)
+ tmp <- aggregate(data[tpos], data[gpos], function(x) x)
+ t2gmap <- tmp[,2]
+ names(t2gmap) <- tmp[,1]
+
+ t2gmap
+}
+
+make_a_plot <- function(tid) {
+ vec <- readdepth[[tid]]
+ if (is.null(vec)) exit_with_error(paste("Unknown transcript detected,", tid, "is not included in RSEM's indices."))
+ 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[[tid]]
+ 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: transcript ", tid, " 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 = "")