3 argv <- commandArgs(TRUE)
4 if (length(argv) != 2) {
5 cat("Usage: rsem-plot-model sample_name outF\n")
9 strvec <- strsplit(argv[1], split = "/")[[1]]
10 token <- strvec[length(strvec)]
12 modelF <- paste(argv[1], ".stat/", token, ".model")
13 cntF <- paste(argv[1], ".stat/", token, ".cnt")
17 con <- file(modelF, open = "r")
19 # model type and forward probability
20 model_type <- as.numeric(readLines(con, n = 4)[1])
22 # fragment length distribution
23 strvec <- readLines(con, n = 3)
24 vec <- as.numeric(strsplit(strvec[1], split = " ")[[1]])
25 maxL <- vec[2] # maxL used for Profile
26 x <- (vec[1] + 1) : vec[2]
27 y <- as.numeric(strsplit(strvec[2], split = " ")[[1]])
28 mean <- weighted.mean(x, y)
29 std <- sqrt(weighted.mean((x - mean)^2, y))
30 plot(x, y, type = "h", main = "Fragment Length Distribution", sub = paste("Mean = ", mean, ", Std = ", std), xlab = "Fragment Length", ylab = "Probability")
32 # mate length distribution
33 if (model_type == 0 || model_type == 1) bval <- as.numeric(readLines(con, n = 1)[1]) else bval <- 1
36 list <- strsplit(readLines(con, n = 2), split = " ")
37 vec <- as.numeric(list[[1]])
39 x <- (vec[1] + 1) : vec[2]
40 y <- as.numeric(list[[2]])
41 mean <- weighted.mean(x, y)
42 std <- sqrt(weighted.mean((x - mean)^2, y))
43 plot(x, y, type = "h", main = "Mate Length Distribution", sub = paste("Mean = ", mean, ", Std = ", std), xlab = "Mate Length", ylab = "Probability")
45 strvec <- readLines(con, n = 1)
48 bval <- as.numeric(readLines(con, n = 1)[1])
50 bin_size <- as.numeric(readLines(con, n = 1)[1])
51 y <- as.numeric(strsplit(readLines(con, n = 1), split = " ")[[1]])
53 barplot(y, space = 0, names.arg = 1:bin_size, main = "Read Start Position Distribution", xlab = "Bin #", ylab = "Probability")
56 strvec <- readLines(con, n = 1)
58 # plot sequencing errors
59 if (model_type == 1 || model_type == 3) {
61 N <- as.numeric(readLines(con, n = 1)[1])
62 readLines(con, n = N + 1)
63 readLines(con, n = 1) # for the blank line
68 peA <- c() # probability of sequencing error given reference base is A
74 strvec <- readLines(con, n = 6)
75 list <- strsplit(strvec[1:4], split = " ")
76 vecA <- as.numeric(list[[1]])
77 vecC <- as.numeric(list[[2]])
78 vecG <- as.numeric(list[[3]])
79 vecT <- as.numeric(list[[4]])
80 if (sum(c(vecA, vecC, vecG, vecT)) < 1e-8) break
81 peA <- c(peA, ifelse(sum(vec) < 1e-8, NA, -10 * log(1.0 - vecA[1])))
82 peC <- c(peC, ifelse(sum(vec) < 1e-8, NA, -10 * log(1.0 - vecC[2])))
83 peG <- c(peG, ifelse(sum(vec) < 1e-8, NA, -10 * log(1.0 - vecG[3])))
84 peT <- c(peT, ifelse(sum(vec) < 1e-8, NA, -10 * log(1.0 - vecT[4])))
87 x <- 0 : (length(peA) - 1)
88 matplot(x, cbind(peA, peC, peG, peT), type = "b", lty = 1:4, pch = 0:3, col = 1:4, main = "Quality Score vs. Observed Quality", xlab = "Quality Score", ylab = "Observed Quality")
89 legend("topleft", c("A", "C", "G", "T"), lty = 1:4, pch = 0:3, col = 1:4)
94 peA <- c() # probability of sequencing error given reference base is A
100 strvec <- readLines(con, n = 6)
101 list <- strsplit(strvec[1:4], split = " ")
102 vecA <- as.numeric(list[[1]])
103 vecC <- as.numeric(list[[2]])
104 vecG <- as.numeric(list[[3]])
105 vecT <- as.numeric(list[[4]])
106 if (sum(c(vecA, vecC, vecG, vecT)) < 1e-8) break
107 peA <- c(peA, ifelse(sum(vec) < 1e-8, NA, (1.0 - vecA[1]) * 100))
108 peC <- c(peC, ifelse(sum(vec) < 1e-8, NA, (1.0 - vecC[2]) * 100))
109 peG <- c(peG, ifelse(sum(vec) < 1e-8, NA, (1.0 - vecG[3]) * 100))
110 peT <- c(peT, ifelse(sum(vec) < 1e-8, NA, (1.0 - vecT[4]) * 100))
114 matplot(x, cbind(peA, peC, peG, peT), type = "b", lty = 1:4, pch = 0:3, col = 1:4, main = "Position vs. Percentage Sequence Error", xlab = "Position", ylab = "Percentage of Sequencing Error")
115 legend("topleft", c("A", "C", "G", "T"), lty = 1:4, pch = 0:3, col = 1:4)
120 pair <- read.table(file = cntF, skip = 3, sep = "\t")
121 plot(pair[,1], pair[,2], xlab = "Number of Alignments", ylab = "Number of Reads", main = "Among alignable reads, distribution of # of alignments")