annotate PLIDflow/scripts/pdbqtcorrector.R @ 0:6fcfa4756040 draft

Uploaded
author bitlab
date Tue, 14 Jan 2020 06:09:42 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
1 #pdbqtcorrector.R corrests the out PDBQT file from AutoDockTools prepare receptor
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
2
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
3 #!/usr/bin/env Rscript
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
4 args = commandArgs(trailingOnly=TRUE)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
5
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
6 if(length(args) < 1){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
7 stop("USE: Rscript pdbqtcorrector.R <receptor_name> <receptor_pdbqt_modified>")
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
8 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
9
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
10 #Argument definition
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
11 receptor_name <- args[1]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
12
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
13 #Scan file
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
14 original_file <- scan(args[1], what = character(), quiet = TRUE, na.strings = "NULLAJSKAJSFL")
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
15
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
16 #Calculate first root word and "TER"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
17 for(e in 1:length(original_file)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
18 if(original_file[e] == "ATOM" || original_file[e] == "HETATM" || original_file[e] == "TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
19 k <- e
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
20 break
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
21 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
22 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
23
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
24 #Calculate the row number for table which conteins aligned x,y,z coordenates
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
25 counter <- 0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
26 for(c in e:length(original_file)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
27 if(original_file[c] == "ATOM" || original_file[c] == "HETATM" || original_file[c] == "TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
28 counter <- counter + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
29 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
30 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
31
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
32 #Table to be fills in named tabla_ordenados
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
33 tabla_ordenados <- matrix(1, nrow = (counter), ncol = 13)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
34
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
35 #Calculate TER times and make a vector
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
36 ele_ter_vector <- 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
37 ter_vector <- c()
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
38 k_position <- c()
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
39 for(o in 1:(length(original_file))){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
40 if(original_file[o] =="TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
41 k_position <- c(k_position, o)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
42 for(g in o:(o+4)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
43 ter_vector <- c(ter_vector,original_file[g] )
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
44 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
45
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
46 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
47 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
48
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
49 #Fill in the tabla_ordenados with values scaned until counter-1 since last row (ter) has diferent length and this could give you back an error
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
50 for(i in 1:(counter-1)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
51 for(j in 1:13){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
52 tabla_ordenados[i,j] <- original_file[k]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
53 if(tabla_ordenados[i,13]=="ATOM" || tabla_ordenados[i,13]== "HETATM"|| tabla_ordenados[i,13]=="TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
54 corte <- c()
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
55 for(v in 4:12){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
56 corte <- c(corte,tabla_ordenados[i,v])
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
57 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
58 coo_corte <- 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
59 tabla_ordenados[i,4] <- ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
60 for(m in 5:13){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
61 tabla_ordenados[i,m] <- corte[coo_corte]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
62 coo_corte <- coo_corte + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
63 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
64 k <- k-1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
65 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
66 k <- k + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
67 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
68 if(tabla_ordenados[i,1]=="TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
69 k <- k - 8
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
70 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
71 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
72
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
73
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
74 #Fill in TER row until last one
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
75 star_ter <- 2
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
76 mmm <- 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
77 for(ii in 1:counter){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
78 if(tabla_ordenados[ii,1]=="TER"){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
79 k <- k_position[mmm] + 4
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
80 mmm <- mmm + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
81 y <- 2
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
82 for(l in star_ter:(star_ter+3)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
83 if(y%%3==0 && y!=6){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
84 tabla_ordenados[ii,y] <- ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
85 y <- y + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
86 tabla_ordenados[ii,y] <- ter_vector[l]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
87 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
88 tabla_ordenados[ii,y] <- ter_vector[l]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
89 y <- y +1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
90 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
91 star_ter <- star_ter + 5
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
92 for(b in 7:13){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
93 tabla_ordenados[ii,b] <- ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
94 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
95 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
96 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
97
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
98 #Fill in last row with TER row values
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
99 last_ter <- length(ter_vector)-4
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
100 for(jj in 1:6){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
101 tabla_ordenados[counter,jj] <- ter_vector[last_ter]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
102 if(jj%%3==0 && jj !=6){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
103 tabla_ordenados[counter, jj] <- ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
104 last_ter <- last_ter - 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
105 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
106 last_ter <- last_ter + 1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
107 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
108 for(jj in 7:13){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
109 tabla_ordenados[counter, jj] <- ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
110 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
111
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
112 #View(tabla_ordenados)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
113
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
114 #Write oredered table in a PDBQT file
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
115 for(xi in 1:nrow(tabla_ordenados)){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
116 cabecera <- tabla_ordenados[xi,1]
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
117 for(xj in 2:13){
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
118 cabecera <- paste(cabecera, tabla_ordenados[xi,xj], sep = " ")
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
119 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
120 write(cabecera, file = args[2], append = TRUE)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
121 }
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
122
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
123
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
124
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
125
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
126
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
127
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
128