comparison PLIDflow/scripts/pdbqtcorrector.R @ 2:afd5b5ffc38f draft

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