3 argv <- commandArgs(TRUE)
4 if (length(argv) != 2) {
5 cat("Usage: rsem-plot-model modelF outF\n")
9 con <- file(argv[1], open = "r")
12 # model type and forward probability
13 model_type <- as.numeric(readLines(con, n = 4)[1])
15 # fragment length distribution
16 strvec <- readLines(con, n = 3)
17 vec <- as.numeric(strsplit(strvec[1], split = " ")[[1]])
18 maxL <- vec[2] # maxL used for Profile
19 x <- (vec[1] + 1) : vec[2]
20 y <- as.numeric(strsplit(strvec[2], split = " ")[[1]])
21 mean <- weighted.mean(x, y)
22 std <- sqrt(weighted.mean((x - mean)^2, y))
23 plot(x, y, type = "h", main = "Fragment Length Distribution", sub = paste("Mean = ", mean, ", Std = ", std), xlab = "Fragment Length", ylab = "Probability")
25 # mate length distribution
26 bval <- as.numeric(readLines(con, n = 1)[1])
28 list <- strsplit(readLines(con, n = 2), split = " ")
29 vec <- as.numeric(list[[1]])
31 x <- (vec[1] + 1) : vec[2]
32 y <- as.numeric(list[[2]])
33 mean <- weighted.mean(x, y)
34 std <- sqrt(weighted.mean((x - mean)^2, y))
35 plot(x, y, type = "h", main = "Mate Length Distribution", sub = paste("Mean = ", mean, ", Std = ", std), xlab = "Mate Length", ylab = "Probability")
37 strvec <- readLines(con, n = 1)
40 bval <- as.numeric(readLines(con, n = 1)[1])
42 bin_size <- as.numeric(readLines(con, n = 1)[1])
43 y <- as.numeric(strsplit(readLines(con, n = 1), split = " ")[[1]])
44 barplot(y, space = 0, main = "Read Start Position Distribution", xlab = "Bin #", ylab = "Probability")
46 strvec <- readLines(con, n = 1)
48 # plot sequencing errors
49 if (model_type == 1 || model_type == 3) {
51 N <- as.numeric(readLines(con, n = 1)[1])
52 readLines(con, n = N + 1)
53 readLines(con, n = 1) # for the blank line
58 peA <- c() # probability of sequencing error given reference base is A
64 strvec <- readLines(con, n = 6)
65 list <- strsplit(strvec[1:4], split = " ")
66 vecA <- as.numeric(list[[1]])
67 vecC <- as.numeric(list[[2]])
68 vecG <- as.numeric(list[[3]])
69 vecT <- as.numeric(list[[4]])
70 if (sum(c(vecA, vecC, vecG, vecT)) < 1e-8) break
71 peA <- c(peA, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecA[1]))
72 peC <- c(peC, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecC[2]))
73 peG <- c(peG, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecG[3]))
74 peT <- c(peT, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecT[4]))
77 x <- 0 : (length(peA) - 1)
78 matplot(x, cbind(peA, peC, peG, peT), type = "b", lty = 1:4, pch = 0:3, main = "Quality Score v.s. Percentage Sequence Error", xlab = "Quality Score", ylab = "Percentage of Sequencing Error")
79 legend("topright", c("A", "C", "G", "T"), lty = 1:4, pch = 0:3)
84 peA <- c() # probability of sequencing error given reference base is A
90 strvec <- readLines(con, n = 6)
91 list <- strsplit(strvec[1:4], split = " ")
92 vecA <- as.numeric(list[[1]])
93 vecC <- as.numeric(list[[2]])
94 vecG <- as.numeric(list[[3]])
95 vecT <- as.numeric(list[[4]])
96 if (sum(c(vecA, vecC, vecG, vecT)) < 1e-8) break
97 peA <- c(peA, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecA[1]))
98 peC <- c(peC, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecC[2]))
99 peG <- c(peG, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecG[3]))
100 peT <- c(peT, ifelse(sum(vec) < 1e-8, NA, 1.0 - vecT[4]))
104 matplot(x, cbind(peA, peC, peG, peT), type = "b", lty = 1:4, pch = 0:3, main = "Position v.s. Percentage Sequence Error", xlab = "Position", ylab = "Percentage of Sequencing Error")
105 legend("topleft", c("A", "C", "G", "T"), lty = 1:4, pch = 0:3)