1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
##
# This function draws two graphics, one of the CA of a DNA sequence, and one of
# start/stop codons positions in the three reading frames. This for the direct or
# the reverse strand.
##
#v.18.08.2011
draw.recstat <- function(rec, fac = 1, direct = TRUE, xlim = c(1, seqsize), col = c("red", "blue", "purple"))
{
if (fac < 0 | 4 < fac)
{ # test if factor is between 1 and 4
print("Factor number is not in 1:4.")
return()
}
seq <- rec[[1]] # recovery of elements of list rec
sizewin <- rec[[2]]
shift <- rec[[3]]
seqsize <- rec[[4]]
seqname <- rec[[5]]
vstopd <- rec[[8]]
vstopr <- rec[[9]]
vinitd <- rec[[10]]
vinitr <- rec[[11]]
recd <- rec[[14]]
recr <- rec[[15]]
if (xlim[1] < 1 | xlim[1] > seqsize)
{
xlim <- c(1, xlim[2])
}
if (seqsize < xlim[2] | 1 > xlim[2])
{
xlim <- c(xlim[1], seqsize)
}
par(mfrow = c(2, 1), mar = c(0, 4, 4, 2) + 0.1) # division of the window for a closer between plots
par(xaxs = "i")
seqisize <- floor((dim(recd$li)[1])/3) # number of window by reading frame, we take the integer part
if ((dim(recd$li)[1])%%3 == 1) # adaptation of number of window between each reading frame
{
seqisize1 <- seqisize + 1 # for fr1
seqisize2 <- seqisize # for fr2
}
if ((dim(recd$li)[1])%%3 == 2)
{
seqisize1 <- seqisize + 1
seqisize2 <- seqisize + 1
}
if ((dim(recd$li)[1])%%3 == 0)
{
seqisize1 <- seqisize
seqisize2 <- seqisize
}
##
##direct strand##
##
if (direct)
{
plot((sizewin/2) + (0:(seqisize1 - 1))*shift, recd$li[1:seqisize1, fac], type = "l", lty = 1,
col = col[1], xlim = xlim, ylim = c(min(recd$li[, fac]), max(recd$li[, fac])),
main = "Direct strand", xlab = "", ylab = "Factor scores", bty = 'l') # reading frame 1
lines((sizewin/2) + (0:(seqisize2 - 1))*shift + 1, recd$li[(seqisize1 + 1):(seqisize1 + seqisize2), fac],
lty = 2, col = col[2], ylab = "2") # reading frame 2
lines((sizewin/2) + (0:(seqisize - 1))*shift + 2, recd$li[(seqisize1 + seqisize2 + 1):(dim(recd$li)[1]), fac],
lty = 3, col = col[3], ylab = "3") # reading frame 3
legend("topleft", legend = c(paste("Sequence name:", seqname), paste("Sequence length:", seqsize, "bp")),
inset = c(-0.15, -0.2), bty = "n", xpd = TRUE)
vstopdindphase <- numeric()
if (length(vstopd) > 0)
{ # test if vector is not empty because problem with modulo
vstopdindphase <- sapply(1:length(vstopd), function(x)
{ # index vector of reading frame of vector vstopd
if (vstopd[x]%%3 == 1)
{
vstopdindphase <- c(vstopdindphase, 2.5)
}
else
{
if (vstopd[x]%%3 == 2)
{
vstopdindphase <- c(vstopdindphase, 1.5)
}
else
{
vstopdindphase <- c(vstopdindphase, 0.5)
}
}
})
}
vinitdindphase <- numeric()
if (length(vinitd) > 0)
{ # test if vector is not empty because problem with modulo
vinitdindphase <- sapply(1:length(vinitd), function(x)
{ # index vector of reading frame of vector vinitd
if (vinitd[x]%%3 == 1)
{
vinitdindphase <- c(vinitdindphase, 3)
}
else
{
if (vinitd[x]%%3 == 2)
{
vinitdindphase <- c(vinitdindphase, 2)
}
else
{
vinitdindphase <- c(vinitdindphase, 1)
}
}
})
}
par(mar = c(5, 4, 3, 2) + 0.1)
plot(vstopd, vstopdindphase, pch = 25, cex = 0.7, xlim = xlim, ylim = c(0.25, 3), axes = TRUE,
ann = TRUE, tcl = -0.5, bty = 'l', yaxt = 'n', xlab = "Start/Stop positions (bp)",
ylab = '', xpd = FALSE) # stop codons positions
points(vinitd, vinitdindphase, pch = 24, bg = "slategray", cex = 0.7, col = 'slategray') # start codons positions
abline(h = c(3.1, 2.4, 2.1, 1.4, 1.1, 0.4), col = c(col[1], col[1], col[2], col[2], col[3], col[3]),
lty = c(1, 1, 2, 2, 3, 3))
text(x = (xlim[1]-(xlim[2]-xlim[1])*0.75/6), pos = 4, y = c(2.75, 1.75, 0.75), labels = paste("Ph. ", c(0, 1, 2)), xpd = TRUE)
}
##
##reverse strand##
##
if (!direct)
{
plot((sizewin/2) + (0:(seqisize1 - 1))*shift, recr$li[1:seqisize1, fac], type = "l", lty = 1,
col = col[1], xlim = xlim, ylim = c(min(recr$li[, fac]), max(recr$li[, fac])),
main = "Reverse strand", xlab = "", ylab = "Factor scores", bty = 'l') # reading frame 1
lines((sizewin/2) + (0:(seqisize2-1))*shift + 1, recr$li[(seqisize1 + 1):(seqisize1 + seqisize2), fac],
lty = 2, col = col[2], ylab="2") # reading frame 2
lines((sizewin/2) + (0:(seqisize - 1))*shift + 2, recr$li[(seqisize1 + seqisize2 + 1):(dim(recr$li)[1]), fac],
lty = 3, col = col[3], ylab = "3") # reading frame 3
legend("topleft", legend = c(paste("Sequence name:", seqname), paste("Sequence length:", seqsize, "bp")),
inset = c(-0.15, -0.2), bty = "n", xpd = TRUE)
vstoprindphase <- numeric()
if (length(vstopr) > 0)
{ # test if vector is not empty because problem with modulo
vstoprindphase <- sapply(1:length(vstopr), function(x)
{ # index vector of reading frame of vector vstopr
if (vstopr[x]%%3 == 1)
{
vstoprindphase <- c(vstoprindphase, 2.5)
}
else
{
if (vstopr[x]%%3 == 2)
{
vstoprindphase <- c(vstoprindphase, 1.5)
}
else
{
vstoprindphase <- c(vstoprindphase, 0.5)
}
}
})
}
vinitrindphase <- numeric()
if (length(vinitr) > 0)
{ # test if vector is not empty because problem with modulo
vinitrindphase <- sapply(1:length(vinitr), function(x)
{ # index vector of reading frame of vector vinitr
if (vinitr[x]%%3 == 1)
{
vinitrindphase <- c(vinitrindphase, 3)
}
else
{
if (vinitr[x]%%3 == 2)
{
vinitrindphase <- c(vinitrindphase, 2)
}
else
{
vinitrindphase <- c(vinitrindphase, 1)
}
}
})
}
par(mar = c(5, 4, 3, 2) + 0.1)
plot(vstopr, vstoprindphase, pch = 25, cex = 0.7, xlim = xlim, ylim = c(0.25, 3), axes = TRUE,
ann = TRUE, tcl = -0.5, bty = 'l', yaxt = 'n', xlab = "Start/Stop positions (bp)",
ylab = '', xpd = FALSE) # stop codons positions
points(vinitr, vinitrindphase, pch = 24, bg = "slategray", cex = 0.7, col = 'slategray') # start codons positions
abline(h = c(3.1, 2.4, 2.1, 1.4, 1.1, 0.4), col = c(col[1], col[1], col[2], col[2], col[3], col[3]),
lty = c(1, 1, 2, 2, 3, 3))
text(x = (xlim[1]-(xlim[2]-xlim[1])*0.75/6), pos = 4, y = c(2.75, 1.75, 0.75), labels = paste("Ph. ", c(0, 1, 2)), xpd = TRUE)
}
}
|