comparison PLIDflow/scripts/pdbqtcorrector2step.R @ 6:795e11fac81b draft default tip

Included new tools for standardization
author bitlab
date Wed, 22 Apr 2020 06:12:00 -0400
parents 6fcfa4756040
children
comparison
equal deleted inserted replaced
5:97f12f7cc852 6:795e11fac81b
1 #pdbqtcorrector2step.R prepare the out PDBQT file from pdbqtcorrector.R to run Vina
2
3 #!/usr/bin/env Rscript
4 args = commandArgs(trailingOnly=TRUE)
5
6 if(length(args) < 2){
7 stop("USE: Rscript pdbqtcorrector.R <receptor_name> <galaxy_file_pdbqt> <receptor_types>")
8 }
9
10 #Argument definition
11 receptor_name <- args[1]
12 receptor_types_file_out <- args[3]
13
14 #Scan file
15 original_file <- scan(args[1], what = character(), quiet = TRUE, na.strings = "NULLAJSKAJSFL")
16
17 #13FEB2019
18 #In order to avoid col 1 and col 2 fussion, split by characters all words. Then paste characters fron col 1 in a word, and those for col 2, rest columns change by " "
19
20 buscador <- c()
21 for(of in 1:length(original_file)){
22 buscador <- c(buscador,strsplit(original_file[of], ""))
23 }
24
25 fix_row_1 <- 0
26 for(off in 1:length(buscador)){
27 if(buscador[[off]][1] == "A"){
28 if(length(buscador[[off]]) >= 3){
29 if(buscador[[off]][2] == "T"){
30 if(buscador[[off]][3] == "O"){
31 if(buscador[[off]][4] == "M"){
32 fix_row_1 <- fix_row_1 + 1
33 buscador[[off]][1] <- paste(buscador[[off]][1], buscador[[off]][2], buscador[[off]][3], buscador[[off]][4], sep = "")
34 if(length(buscador[[off]]) == 4){
35 for(off1 in 2:length(buscador[[off]])){
36 buscador[[off]][off1] <- ""
37 }
38 for(qu in 1:(length(buscador[[off]])-1)){
39 buscador[[off]] <- buscador[[off]][-length(buscador[[off]])]
40
41
42 }
43 }
44 if(length(buscador[[off]]) > 4){
45 var_aux <- c()
46 for(off1 in 5:length(buscador[[off]])){
47 var_aux <- c(var_aux, paste(buscador[[off]][off1]))
48 }
49 termino <- var_aux[1]
50 for(ofu in 2:length(var_aux)){
51 termino <- paste(termino, var_aux[ofu], sep = "")
52 }
53
54 buscador[[off]][2] <- termino
55
56 for(off1 in 3:length(buscador[[off]])){
57 buscador[[off]][off1] <- ""
58 }
59 for(qu in 2:(length(buscador[[off]])-1)){
60 buscador[[off]] <- buscador[[off]][-length(buscador[[off]])]
61
62
63 }
64 }
65 }
66 }
67 }
68 }
69 }
70 }
71 #print(fix_row_1)
72
73
74 fix_row_2 <- 0
75 for(off in 1:length(buscador)){
76 if(buscador[[off]][1] == "H"){
77 if(length(buscador[[off]]) >= 3){
78 if(buscador[[off]][2] == "E"){
79 if(buscador[[off]][3] == "T"){
80 if(buscador[[off]][4] == "A"){
81 if(buscador[[off]][5] == "T"){
82 if(buscador[[off]][6] == "M"){
83 fix_row_2 <- fix_row_2 + 1
84 buscador[[off]][1] <- paste(buscador[[off]][1], buscador[[off]][2], buscador[[off]][3], buscador[[off]][4], buscador[[off]][5], buscador[[off]][6], sep = "")
85 if(length(buscador[[off]]) == 6){
86 for(off1 in 2:length(buscador[[off]])){
87 buscador[[off]][off1] <- ""
88 }
89 for(qu in 1:(length(buscador[[off]])-1)){
90 buscador[[off]] <- buscador[[off]][-length(buscador[[off]])]
91
92
93 }
94 }
95 if(length(buscador[[off]]) > 6){
96 var_aux <- c()
97 for(off1 in 7:length(buscador[[off]])){
98 var_aux <- c(var_aux, paste(buscador[[off]][off1]))
99 }
100 termino <- var_aux[1]
101 for(ofu in 2:length(var_aux)){
102 termino <- paste(termino, var_aux[ofu], sep = "")
103 }
104
105 buscador[[off]][2] <- termino
106
107 for(off1 in 3:length(buscador[[off]])){
108 buscador[[off]][off1] <- ""
109 }
110
111 for(qu in 2:(length(buscador[[off]])-1)){
112 buscador[[off]] <- buscador[[off]][-length(buscador[[off]])]
113 }
114 }
115 }
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 #print(fix_row_2)
124
125 fix_row_3 <- 0
126 for(off in 1:length(buscador)){
127 if(buscador[[off]][1] == "T"){
128 if(length(buscador[[off]]) >= 3){
129 if(buscador[[off]][2] == "E"){
130 if(buscador[[off]][3] == "R"){
131 fix_row_3 <- fix_row_3 + 1
132 }
133 }
134 }
135 }
136 }
137 #print(fix_row_3)
138
139 final_row <- fix_row_1 + fix_row_2 + fix_row_3
140
141 #counter <- final_row
142 #print(counter)
143
144 # At this point roots "ATOM", "HETATM" and "TER" are isolated in case fusion. This step component differrent for those are pasted
145 for(off in 1:length(buscador)){
146 if(as.character(buscador[[off]][1]) != "ATOM" && buscador[[off]][1] != "HETATM"){
147 #print(off)
148 pegado <- buscador[[off]][1]
149 for(fus in 2:length(buscador[[off]])){
150 if(length(buscador[[off]]) > 1){
151 pegado <- paste(pegado, buscador[[off]][fus], sep = "")
152 buscador[[off]][1] <- pegado
153 }
154 }
155 if(length(buscador[[off]]) > 1){
156 for(qu in 1:(length(buscador[[off]])-1)){
157 buscador[[off]] <- buscador[[off]][-length(buscador[[off]])]
158 }
159 }
160 }
161 }
162
163
164 # strsplit applied to the original_file return a list format. In this steps it is for changing list for vector format for buscador varible
165
166 total_original_file <- c()
167 for(si in 1:length(buscador)){
168 total_original_file <- c(total_original_file, buscador[[si]])
169 }
170 #13feb2019
171
172 original_file <- total_original_file
173
174 #Starts pdbqtcorrector
175
176 #Calculate first root word and "TER"
177 for(e in 1:length(original_file)){
178 if(original_file[e] == "ATOM" || original_file[e] == "HETATM" || original_file[e] == "TER"){
179 k <- e
180 break
181 }
182 }
183
184 #Calculate the row number for table which conteins aligned x,y,z coordenates
185 counter <- 0
186 for(c in e:length(original_file)){
187 if(original_file[c] == "ATOM" || original_file[c] == "HETATM" || original_file[c] == "TER"){
188 counter <- counter + 1
189 }
190 }
191
192 #Table to be fills in named tabla_ordenados
193 tabla_ordenados <- matrix(1, nrow = (counter), ncol = 13)
194
195 #Calculate TER times and make a vector
196 ele_ter_vector <- 1
197 ter_vector <- c()
198 k_position <- c()
199 #ter_pos <- 0 #21sep2018
200 for(o in 1:(length(original_file))){
201 if(original_file[o] =="TER"){
202 k_position <- c(k_position, o)
203 ter_pos <- o #21sep
204 for(g in o:(o+4)){
205 ter_vector <- c(ter_vector,original_file[g] )
206 }
207
208 }
209 }
210
211
212 #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
213 for(i in 1:(counter-1)){
214 for(j in 1:13){
215 tabla_ordenados[i,j] <- original_file[k]
216 if(tabla_ordenados[i,13]=="ATOM" || tabla_ordenados[i,13]== "HETATM"|| tabla_ordenados[i,13]=="TER"){
217 corte <- c()
218 for(v in 4:12){
219 corte <- c(corte,tabla_ordenados[i,v])
220 }
221 coo_corte <- 1
222 tabla_ordenados[i,4] <- ""
223 for(m in 5:13){
224 tabla_ordenados[i,m] <- corte[coo_corte]
225 coo_corte <- coo_corte + 1
226 }
227 k <- k-1
228 }
229 # #################02julio2019################################
230
231 if(tabla_ordenados[i,12]=="ATOM" || tabla_ordenados[i,12]== "HETATM"|| tabla_ordenados[i,12]=="TER"){
232
233
234 #print("ENTERING")
235 #stop()
236
237 corte_2 <- c()
238 for(iv in 5:11){
239 corte_2 <- c(corte_2,tabla_ordenados[i,iv])
240 }
241
242 #print(corte_2)
243
244 first_number <- substr(corte_2[5], 1, 4)
245 second_number <- substr(corte_2[5], 5, 1000)
246
247
248
249 coo_corte_2 <- 1
250 tabla_ordenados[i,5] <- ""
251 tabla_ordenados[i,12] <- ""
252 tabla_ordenados[i,13] <- ""
253 for(im in 6:13){
254 tabla_ordenados[i,im] <- corte_2[coo_corte_2]
255 coo_corte_2 <- coo_corte_2 + 1
256 }
257 k <- k-2
258
259 tabla_ordenados[i,12] <- corte_2[6]
260 tabla_ordenados[i,10] <- first_number
261 tabla_ordenados[i,11] <- second_number
262
263
264
265
266 }
267
268
269
270 #################02julio2019################################
271
272
273 k <- k + 1
274 }
275 if(tabla_ordenados[i,1]=="TER"){
276 k <- k - 8
277 }
278 }
279
280 #Fill in TER row until last one
281 star_ter <- 2
282 mmm <- 1
283 for(ii in 1:counter){
284 if(tabla_ordenados[ii,1]=="TER"){
285 k <- k_position[mmm] + 4
286 mmm <- mmm + 1
287 y <- 2
288 for(l in star_ter:(star_ter+3)){
289 if(y%%3==0 && y!=6){
290 tabla_ordenados[ii,y] <- ""
291 y <- y + 1
292 tabla_ordenados[ii,y] <- ter_vector[l]
293 }
294 tabla_ordenados[ii,y] <- ter_vector[l]
295 y <- y +1
296 }
297 star_ter <- star_ter + 5
298 for(b in 7:13){
299 tabla_ordenados[ii,b] <- ""
300 }
301 }
302 }
303
304 ##Fill if last row is not TER root
305 if(ter_pos < (length(original_file)-14)){
306 tpnt <- 0
307 ntn <- length(original_file) - 12
308 for(jnt in 1:13){
309 tabla_ordenados[nrow(tabla_ordenados),jnt] <- original_file[ntn]
310
311 ntn <- ntn + 1
312 }
313 }
314
315 ##Fill in last row with TER row values ##
316 #ajustcel4 <-0
317 if(ter_pos > (length(original_file)-14)){
318 for(rtv in 1:length(ter_vector)){
319 ajustcel4 <- rtv #14nov2018
320 if(is.na(ter_vector[rtv])){
321 ajustcel4 <- rtv - 1
322 }
323 }
324
325 ter_vector_numeric <- strsplit(ter_vector[ajustcel4], "")
326
327 last_ter <- length(ter_vector)-4
328 if(length(ter_vector_numeric[[1]]) != 1){
329 if(length(ter_vector) < 5){
330
331 for(jj in 1:6){
332 tabla_ordenados[counter,jj] <- ter_vector[last_ter]
333
334 if(jj%%3==0 && jj !=6 || jj == 4){ #he incluido el jj == 4
335 tabla_ordenados[counter, jj] <- ""
336 last_ter <- last_ter - 1
337 }
338 last_ter <- last_ter + 1
339 }
340 for(jj in 7:13){
341 tabla_ordenados[counter, jj] <- ""
342 }
343 }
344
345 if(length(ter_vector) >= 5){
346 for(jj in 1:7){
347 tabla_ordenados[counter,jj] <- ter_vector[last_ter]
348 if(jj%%3==0 && jj !=6){ #he incluido el jj == 4
349 tabla_ordenados[counter, jj] <- ""
350 last_ter <- last_ter -1
351 }
352 last_ter <- last_ter + 1
353 }
354 for(jj in 8:13){
355 tabla_ordenados[counter, jj] <- ""
356 }
357 }
358 }
359
360 if(length(ter_vector_numeric[[1]]) == 1){
361 if(length(ter_vector) <= 5){
362
363 for(jj in 1:6){
364 tabla_ordenados[counter,jj] <- ter_vector[last_ter]
365
366 if(jj%%3==0 && jj !=6 ){ #he incluido el jj == 4
367 tabla_ordenados[counter, jj] <- ""
368 last_ter <- last_ter - 1
369 }
370 last_ter <- last_ter + 1
371 }
372 for(jj in 7:13){
373 tabla_ordenados[counter, jj] <- ""
374 }
375 }
376
377 if(length(ter_vector) > 5){
378 for(jj in 1:7){
379 tabla_ordenados[counter,jj] <- ter_vector[last_ter]
380 if(jj%%3==0 && jj !=6){ #he incluido el jj == 4
381 tabla_ordenados[counter, jj] <- ""
382 last_ter <- last_ter -1
383 }
384 last_ter <- last_ter + 1
385 }
386 for(jj in 8:13){
387 tabla_ordenados[counter, jj] <- ""
388 }
389 }
390 }
391
392 }
393
394
395 #View(tabla_ordenados)
396
397 #19octubre2018
398
399 #listacol11 <- matrix(0, nrow = nrow(tabla_ordenados), ncol = 1)
400 twopoint <- c()
401 for(dc11 in 1:nrow(tabla_ordenados)){
402 listacol11 <-strsplit(tabla_ordenados[dc11,11], "")
403
404 if(length(listacol11[[1]]) != 0){
405 num_poin <- 0
406 for(findpoint in 1:length(listacol11[[1]])){
407 if(listacol11[[1]][findpoint] == "."){
408 num_poin <- num_poin + 1
409 }
410 }
411 if(num_poin == 2){
412 twopoint <- c(twopoint, dc11)
413 unopto0 <- listacol11[[1]][1]
414 dospto0 <- listacol11[[1]][5]
415 for(div1pto in 2:4){
416 unopto0 <- paste(unopto0, listacol11[[1]][div1pto], sep = "")
417 }
418 for(div2pto in 6:length(listacol11[[1]])){
419 dospto0 <- paste(dospto0, listacol11[[1]][div2pto], sep = "")
420 }
421 #19oct2018 Voy a guardar cada fila en un vector para luego pegarlo
422 vec_guarfilas <- c()
423 for(vgf in 1:10){
424
425 if(tabla_ordenados[dc11,vgf] != ""){
426 vec_guarfilas <- c(vec_guarfilas, tabla_ordenados[dc11,vgf])
427 }
428 }
429 vec_guarfilas[10] <- unopto0
430 vec_guarfilas[11] <- dospto0
431 vec_guarfilas[12] <- tabla_ordenados[dc11,12]
432 vec_guarfilas[13] <- tabla_ordenados[dc11,13]
433
434 #print(vec_guarfilas)
435 for(mvc in 1:13){
436 tabla_ordenados[dc11,mvc] <- vec_guarfilas[mvc]
437 }
438
439 }
440 }
441 }
442
443 #View(tabla_ordenados)
444 #acaba 19octubre2018
445
446
447
448 #Make a table containing for each cell the number of characters for each for the tabla_ordenados
449 tabla_ordenados_numcarac <- matrix(1, nrow = nrow(tabla_ordenados), ncol = ncol(tabla_ordenados))
450
451 for(i in 1:nrow(tabla_ordenados)){
452 for(j in 1:ncol(tabla_ordenados)){
453 caracteres <- strsplit(tabla_ordenados[i,j], "")
454 num_carac <- 0
455 # if(tabla_ordenados[i,j] == ""){
456 # num_carac <- ""
457 # }
458 #if(tabla_ordenados[i,j] != ""){
459 for(k in 1:length(caracteres[[1]])){
460 num_carac <- num_carac + 1
461 }
462 tabla_ordenados_numcarac[i,j] <- num_carac
463 #}
464 }
465 }
466 #View(tabla_ordenados_numcarac) #27mar2019
467
468 #################03julio2019###################3 ##
469
470 for(i in 1:nrow(tabla_ordenados)){
471
472 if(tabla_ordenados_numcarac[i,4] == 2 && tabla_ordenados_numcarac[i,5] == 3){
473 cambio_posicion5 <- tabla_ordenados[i,5]
474 tabla_ordenados[i,5] <- ""
475 tabla_ordenados_numcarac[i,5] <- 2
476 tabla_ordenados[i,4] <- cambio_posicion5
477 tabla_ordenados_numcarac[i,4] <- 3
478 }
479 }
480
481 for(i in 1:nrow(tabla_ordenados)){
482 if(tabla_ordenados_numcarac[i,5] == 2 && tabla_ordenados_numcarac[i,6] == 5){
483 Aaposicion5 <- substr(tabla_ordenados[i,6], 1, 1)
484 cambio_posicion5 <- substr(tabla_ordenados[i,6], 2, 5)
485 tabla_ordenados[i,5] <- Aaposicion5
486 tabla_ordenados_numcarac[i,5] <- 1
487 tabla_ordenados[i,6] <- cambio_posicion5
488 tabla_ordenados_numcarac[i,6] <- 4
489 }
490 }
491
492 for(i in 1:nrow(tabla_ordenados)){
493 if(tabla_ordenados[i, 3] < 6 && tabla_ordenados[i, 4] == ""){
494 tabla_ordenados[i, 4] <- "XX"
495 }
496 }
497
498 #################03julio2019###################3 ##
499
500 # &&&&& 03sep2019 &&&&&&&&&&&&
501 if(tabla_ordenados_numcarac[counter,5] >= 5){
502 ter_5_col <- substr(tabla_ordenados[counter, 5], 1, 1)
503 ter_6_col <- substr(tabla_ordenados[counter, 5], 2, 1000)
504
505
506 tabla_ordenados[counter, 5] <- ter_5_col
507 tabla_ordenados[counter, 6] <- ter_6_col
508 }
509
510 # &&&&& 03sep2019 &&&&&&&&&&&&
511
512
513 ####····̣# &&&&& 30oct2019 &&&&&&&&&&&&
514 for(ac3 in 1:counter){
515 if(tabla_ordenados_numcarac[ac3,3] >= 7){
516 ter_3_col <- substr(tabla_ordenados[ac3, 3], 1, 4)
517 ter_4_col <- substr(tabla_ordenados[ac3, 3], 5, 1000)
518
519
520 tabla_ordenados[ac3, 3] <- ter_3_col
521 tabla_ordenados[ac3, 4] <- ter_4_col
522 tabla_ordenados_numcarac[ac3, 3] <- 4
523 tabla_ordenados_numcarac[ac3, 4] <- 3
524 }
525
526 }
527
528 ####····̣# &&&&& 30oct2019 &&&&&&&&&&&&
529
530
531
532
533
534 #:;:;:;:;:;:;:;:;________09septiembre2019. Remove line with "Na" in column 13 in tabla_ordenados and tabla_ordenados_numcarac
535
536 # quitar_fila <- 0
537 # for(ena in 1:counter){
538 # if(tabla_ordenados[ena,13] == "Na"){
539 # print(ena)
540 # tabla_ordenados_numcarac <- tabla_ordenados_numcarac[-ena,]
541 # ena <- ena - 1
542 # quitar_fila <- quitar_fila + 1
543 # counter <- counter - quitar_fila
544 #
545 # }
546 # }
547 #
548 # tabla_ordenados <- subset(tabla_ordenados, tabla_ordenados[,13] != "Na")
549
550 #:;:;:;:;:;:;:;:;________09septiembre2019
551
552 #View(tabla_ordenados)
553 #View(tabla_ordenados_numcarac)
554
555
556
557
558 #Fit spaces for write()
559 #Fit spaces for write()
560 #Pairwise 1col-2col con 1col == "ATOM"
561
562 for(i in 1:nrow(tabla_ordenados)){
563 linea <- c()
564 if(tabla_ordenados_numcarac[i,1] == 4){
565 num_espacios <- 6
566 ajuste <- 0
567 for(a in 1:(tabla_ordenados_numcarac[i,2])){
568 if(a != tabla_ordenados_numcarac[i,2]){
569 ajuste <- ajuste + 1
570 }
571 if(a == tabla_ordenados_numcarac[i,2]){
572 espacios <- rep(" ", num_espacios-ajuste)
573 linea <- c(espacios, tabla_ordenados[i,2])
574 break
575 }
576 }
577 }
578
579 #1col == HETATM INI
580 if(tabla_ordenados_numcarac[i,1] == 6){
581 num_espacios <- 4
582 ajuste <- 0
583 for(a in 1:(tabla_ordenados_numcarac[i,2])){
584 if(a != tabla_ordenados_numcarac[i,2]){
585 ajuste <- ajuste + 1
586 }
587 if(a == tabla_ordenados_numcarac[i,2]){
588 espacios <- rep(" ", num_espacios-ajuste)
589 linea <- c(espacios, tabla_ordenados[i,2])
590
591 ###21feb2019
592 if(tabla_ordenados_numcarac[i,2] == 5){
593 espacios <- rep(" ", (num_espacios-ajuste) + 1)
594 linea <- c(espacios, tabla_ordenados[i,2])
595 }
596 ###21feb2019
597
598 break
599 }
600 }
601 }
602 #1col == HETATM FIN
603
604 ##1col == TER INICIO
605 if(tabla_ordenados_numcarac[i,1] == 3){
606 num_espacios <- 7
607 ajuste <- 0
608 for(a in 1:(tabla_ordenados_numcarac[i,2])){
609 if(a != tabla_ordenados_numcarac[i,2]){
610 ajuste <- ajuste + 1
611 espacios <- rep(" ", num_espacios-ajuste)
612 }
613 if(a == tabla_ordenados_numcarac[i,2]){
614 espacios <- rep(" ", num_espacios-ajuste)
615 linea <- c(espacios, tabla_ordenados[i,2])
616 break
617 }
618 }
619 }
620 ##1col == TER FIN
621
622 ##Pairwise 2col-3col
623 linea2 <- c()
624 for(b in 1:(tabla_ordenados_numcarac[i,3])){
625 if(b < 4){
626 espacios2 <- rep(" ", 2)
627 }
628 if(b >= 4){
629 if(tabla_ordenados[i,4] == ""){
630 espacios2 <- rep(" ", 2)
631 }
632
633 if(tabla_ordenados[i,4]!= ""){
634 espacios2 <- rep(" ", 1)
635 }
636 }
637 }
638
639 if(tabla_ordenados_numcarac[i,3] >= 8){
640 e_espacios2 <- length(espacios2)-1
641 espacios2 <- rep(" ",e_espacios2)
642
643
644 }
645
646 linea2 <- c(linea, espacios2, tabla_ordenados[i,3])
647
648 ###21feb2019
649 if(tabla_ordenados_numcarac[i,1] == 6 && tabla_ordenados_numcarac[i,2] == 5){
650 espacios2 <- espacios2[-length(espacios2)]
651 linea2 <- c(linea, espacios2, tabla_ordenados[i,3])
652 }
653 ###21feb2019
654
655 ###Pairwise 3col-4col
656 linea3 <- c()
657
658 for(c in 1:(tabla_ordenados_numcarac[i,4])){
659
660 #28nov
661 if(c == 2){
662 if(tabla_ordenados_numcarac[i,1] == 6 && tabla_ordenados_numcarac[i,3] == 1){
663 espacios3 <- rep(" ", 2)
664 }
665 if(tabla_ordenados_numcarac[i,1] == 6 && tabla_ordenados_numcarac[i,3] == 2){
666 espacios3 <- rep(" ", 1)
667 }
668 if(tabla_ordenados_numcarac[i,1] == 6 && tabla_ordenados_numcarac[i,3] == 2 && tabla_ordenados_numcarac[i,5] == 1){
669 espacios3 <- rep(" ", 3)
670 }
671
672 #########21junio2019
673
674 if(tabla_ordenados_numcarac[i,1] == 4 && tabla_ordenados_numcarac[i,3] == 1 && tabla_ordenados_numcarac[i,6] == 5){
675 espacios3 <- rep(" ", 2)
676 }
677 if(tabla_ordenados_numcarac[i,1] == 4 && tabla_ordenados_numcarac[i,3] == 2 && tabla_ordenados_numcarac[i,6] == 5){
678 espacios3 <- rep(" ", 1)
679 }
680
681 ########21junio2019
682
683
684
685
686 }
687 #28nov. Hace falta corregir para el resto de HETATM
688
689
690 if(c == 3){
691 if(b == 1){
692 espacios3 <- rep(" ", 3)
693 }
694 if(b == 2){
695 espacios3 <- rep(" ", 2)
696 }
697 if(b >= 3){
698 espacios3 <- rep(" ", 1)
699 }
700 }
701 if(c == 4){
702 if(b == 1){
703 espacios3 <- rep(" ", 2)
704 }
705 if(b >= 2){
706 espacios3 <- rep(" ", 1)
707 }
708 }
709 #27mar2019 ######################################
710 if(c == 5){
711 if(b >= 2){
712 espacios3 <- rep("", 1)
713 }
714 }
715 #27mar2019 ######################################
716 }
717
718 linea3 <- c(linea2, espacios3, tabla_ordenados[i,4])
719 ####03julio2019####################### #####################
720 # if(tabla_ordenados_numcarac[i,3] == 3 && tabla_ordenados_numcarac[i,4] == 3 && tabla_ordenados_numcarac[i,5] == 2 && tabla_ordenados_numcarac[i,6] == 5){
721 # linea3 <- c(linea2, " ", tabla_ordenados[i,4])
722 # }
723 ####03julio2019####################### #####################
724
725 #TER
726 if(tabla_ordenados_numcarac[i,1] == 3){
727 num_espacios4 <- 8
728 ajuste_t1 <- 0
729 for(l in 1:tabla_ordenados_numcarac[i,4]){
730 if(l != tabla_ordenados_numcarac[i,4]){
731 ajuste_t1 <-ajuste_t1 + 1
732 num_espacios4 <- 8 - ajuste_t1
733 }
734 if(l == tabla_ordenados_numcarac[i,4]){
735 num_espacios4 <- 8 - ajuste_t1
736 }
737 }
738 linea3 <- c(linea, rep(" ", num_espacios4), tabla_ordenados[i,4])
739
740 }
741
742 ####Pairwise 4col-5col
743 linea4 <- c()
744 if(tabla_ordenados_numcarac[i,1] != 3){
745 if(tabla_ordenados_numcarac[i,3] >= 7){
746 linea4 <- c(linea3, tabla_ordenados[i,5])
747 }
748 if(tabla_ordenados_numcarac[i,3] < 7){
749 linea4 <- c(linea3, " ", tabla_ordenados[i,5])
750 ###18oct2018
751 if(tabla_ordenados_numcarac[i,3] >= 3 && tabla_ordenados[i,4] == ""){
752 linea4 <- c(linea2, " ", tabla_ordenados[i,5])
753 }
754 ###18oct2018
755 }
756 #------------29julio2019--------------------#
757
758 if(isTRUE(tabla_ordenados[i,3] == "NA") && tabla_ordenados[i,4] == ""){
759 linea4 <- c(linea2, rep(" ", 6), tabla_ordenados[i,5])
760 }
761
762
763 #------------29julio2019--------------------#
764 }
765
766
767
768
769 if(tabla_ordenados_numcarac[i,1] == 3){
770
771 linea4 <- c(linea3, " ", tabla_ordenados[i,5])
772 ##
773 if(tabla_ordenados[i,4] == ""){
774 linea4 <- c(linea2,rep(" ", 4),tabla_ordenados[i,5])
775 }
776
777 ##
778
779
780 }
781
782 #####Pairwise 5col-6col. NO espacios4
783 if(tabla_ordenados_numcarac[i,1] != 3){
784 linea5 <-c()
785 for(d in 1:(tabla_ordenados_numcarac[i,6])){
786 if(d == 1){
787 espacios5 <- rep(" ", 3)
788 }
789 if(d == 2){
790 espacios5 <- rep(" ", 2)
791 }
792 if(d >= 3){
793 espacios5 <- rep(" ", 1)
794 }
795
796 ##################21junio2109#############
797
798 if(tabla_ordenados_numcarac[i,3] == 2 && tabla_ordenados_numcarac[i,5] == 2 && tabla_ordenados_numcarac[i,6] == 5){
799 espacios5 <- rep(" ", 2)
800 }
801
802 ##################21junio2109#############
803 ###########03julio################ ############
804 # if(tabla_ordenados_numcarac[i,3] == 1 && tabla_ordenados_numcarac[i,4] == 3 && tabla_ordenados_numcarac[i,5] == 2 && tabla_ordenados_numcarac[i,6] == 5){
805 #
806 # espacios5 <- ""
807 # }
808
809 ###########03julio################ ############
810
811
812 }
813 linea5 <- c(linea4, espacios5, tabla_ordenados[i,6])
814
815
816 }
817 if(tabla_ordenados_numcarac[i,1] == 3){
818 for(dd in 1:(tabla_ordenados_numcarac[i,6])){
819 if(dd == 1){
820 espacios55 <- rep(" ", 3)
821 }
822
823 #14nov
824 if(dd == 1 && tabla_ordenados_numcarac[i,5] == 3){
825 espacios55 <- rep(" ", 1)
826 }
827 #14nov
828
829 if(dd == 2){
830 espacios55 <- rep(" ", 2)
831 }
832 if(dd >= 3){
833 espacios55 <- rep(" ", 1)
834 }
835
836
837 }
838 linea5 <- c(linea4, espacios55, tabla_ordenados[i,6])
839
840 #------------------05sep2019------------#
841
842 if(tabla_ordenados_numcarac[i,6] == 1 && tabla_ordenados_numcarac[i,5] >= 5){
843 espacios55 <- rep(" ", 1)
844 linea5 <- c(linea4, espacios55, tabla_ordenados[i,6])
845 }
846
847 #------------------05sep2019------------#
848
849 }
850
851
852
853
854 ######Pairwise 6col-7col
855 linea6 <- c()
856 if(tabla_ordenados_numcarac[i,7] == 5){
857 espacios6 <- rep(" ", 7)
858 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
859
860 ###################21junio2109#################
861 if(tabla_ordenados_numcarac[i,3] == 4 && tabla_ordenados_numcarac[i,6] == 5){
862 espacios6 <- rep(" ", 6)
863 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
864 }
865
866 ###################21junio2109#################
867
868 ## 03julio2019 #########
869
870 if(tabla_ordenados_numcarac[i,6] == 4 && tabla_ordenados_numcarac[i,6] == 4){
871 espacios6 <- rep(" ", 6)
872 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
873 }
874
875 ## 03julio2019 #########
876
877
878 }
879
880 if(tabla_ordenados_numcarac[i,7] > 5){
881 out_spaces <- tabla_ordenados_numcarac[i,7] - 5
882 espacios6 <- rep(" ", (7-out_spaces))
883 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
884
885 ###################21junio2109#################
886 if(tabla_ordenados_numcarac[i,3] == 4 && tabla_ordenados_numcarac[i,6] == 5){
887 out_spaces <- tabla_ordenados_numcarac[i,7] - 4
888 espacios6 <- rep(" ", (7-out_spaces))
889 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
890 }
891
892 ###################21junio2109#################
893 ## 03julio2019 #########
894
895 if(tabla_ordenados_numcarac[i,6] == 4 && tabla_ordenados_numcarac[i,6] == 4){
896 out_spaces_2 <- tabla_ordenados_numcarac[i,7] - 4
897 espacios6 <- rep(" ", (7-out_spaces_2))
898 linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
899 }
900
901 ## 03julio2019 #########
902
903
904 }
905
906 ######################################27mar2019
907 #
908 # if(tabla_ordenados_numcarac[i,4] == 5){
909 # espacios6 <- rep(" ",5)
910 # linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
911 # }
912 #
913 # if(tabla_ordenados_numcarac[i,4] > 5){
914 # espacios6 <- rep(" ",4)
915 # linea6 <-c(linea5, espacios6, tabla_ordenados[i,7])
916 # }
917
918 ######################################27mar2019
919
920
921 #######Pairwise 7col-8col
922 linea7 <- c()
923 ajuste3 <- 0
924 if(tabla_ordenados_numcarac[i,8] == 5){
925 espacios7 <- rep(" ", 3)
926 linea7 <-c(linea6, espacios7, tabla_ordenados[i,8])
927 }
928 if(tabla_ordenados_numcarac[i,8] == 6){
929 espacios7 <- rep(" ", 2)
930 linea7 <-c(linea6, espacios7, tabla_ordenados[i,8])
931 }
932 if(tabla_ordenados_numcarac[i,8] > 6){
933 espacios7 <- rep(" ", 1)
934 linea7 <-c(linea6, espacios7, tabla_ordenados[i,8])
935 }
936
937 ########Pairwise 8col-9col
938 linea8 <- c()
939 ajuste4 <- 0
940 if(tabla_ordenados_numcarac[i,9] == 5){
941 espacios8 <- rep(" ", 3)
942 linea8 <-c(linea7, espacios8, tabla_ordenados[i,9])
943 }
944 if(tabla_ordenados_numcarac[i,9] == 6){
945 espacios8 <- rep(" ", 2)
946 linea8 <-c(linea7, espacios8, tabla_ordenados[i,9])
947 }
948 if(tabla_ordenados_numcarac[i,9] > 6){
949 espacios8 <- rep(" ", 1)
950 linea8 <-c(linea7, espacios8, tabla_ordenados[i,9])
951 }
952
953 #########Pairwise 9col-10col
954 linea9 <- c()
955 if(tabla_ordenados_numcarac[i,10] == 4){
956 espacios9 <- rep(" ", 2)
957 linea9 <- c(linea8, espacios9, tabla_ordenados[i,10])
958 }
959 if(tabla_ordenados_numcarac[i,10] > 4){
960 espacios9 <- rep(" ", 1)
961 linea9 <- c(linea8, espacios9, tabla_ordenados[i,10])
962 }
963
964 ##########Pairwise 10col-11col
965 # linea10 <- c()
966 # if(tabla_ordenados_numcarac[i,11] == 4){
967 # espacios10 <- rep(" ", 2)
968 # linea10 <- c(linea9, espacios10, tabla_ordenados[i,11])
969 # }
970 # if(tabla_ordenados_numcarac[i,11] > 4){
971 # espacios10 <- rep(" ", 1)
972 # linea10 <- c(linea9, espacios10, tabla_ordenados[i,11])
973 # }
974 #22oct2018
975 ##########Pairwise 10col-11col
976 linea10 <- c()
977 if(tabla_ordenados_numcarac[i,11] == 4){
978 espacios10 <- rep(" ", 3)
979 linea10 <- c(linea9, espacios10, tabla_ordenados[i,11])
980 }
981 if(tabla_ordenados_numcarac[i,11] == 5){
982 espacios10 <- rep(" ", 2)
983 linea10 <- c(linea9, espacios10, tabla_ordenados[i,11])
984 }
985
986 if(tabla_ordenados_numcarac[i,11] > 5){
987 espacios10 <- rep(" ", 1)
988 linea10 <- c(linea9, espacios10, tabla_ordenados[i,11])
989 }
990 #22oct2018
991
992
993 ###########Pairwise 11col-12col
994 linea11 <- c()
995 if(tabla_ordenados_numcarac[i,12] == 5){
996 espacios11 <- rep(" ", 5)
997 linea11 <-c(linea10, espacios11, tabla_ordenados[i,12])
998 }
999 ajuste5 <- 0
1000 for(h in 6:tabla_ordenados_numcarac[i,12]){
1001 if(tabla_ordenados_numcarac[i,12] > 5){
1002 ajuste5 <- ajuste5 + 1
1003 espacios11 <- rep(" ", (5-ajuste5))
1004 ##espacios11 <- rep(" ", (5-ajuste5))
1005 linea11 <-c(linea10, espacios11, tabla_ordenados[i,12])
1006 }
1007 }
1008
1009 ############Pairwise 12col-13col
1010 linea12 <- c(linea11," ", tabla_ordenados[i,13])
1011
1012 #TER
1013 if(tabla_ordenados_numcarac[i,1] == 3){
1014 cabecera <- tabla_ordenados[i,1]
1015 for(w in 1:length(linea5)){
1016 cabecera <- paste(cabecera,linea5[w], sep = "")
1017 }
1018 #write(cabecera, file = "1z95_wo_198andwater_ph7_MOD.pdbqt", append = TRUE)
1019 write(cabecera, file = args[2], append = TRUE)
1020 }
1021
1022 #!= TER
1023 if(tabla_ordenados_numcarac[i,1] != 3){
1024 cabecera <- tabla_ordenados[i,1]
1025 for(w in 1:length(linea12)){
1026 cabecera <- paste(cabecera,linea12[w], sep = "")
1027 }
1028 #write(cabecera, file = "1z95_wo_198andwater_ph7_MOD.pdbqt", append = TRUE)
1029 write(cabecera, file = args[2], append = TRUE)
1030 }
1031 }
1032
1033 #21junio2019
1034 # #### Make file receptor_atm_types.txt to be paste in the GPF file ###
1035
1036 prereceptor_atmtypes <- c()
1037 for(i in 1:nrow(tabla_ordenados)){
1038 if(tabla_ordenados[i,13] != ""){
1039 prereceptor_atmtypes <- c(prereceptor_atmtypes, tabla_ordenados[i,13])
1040 }
1041 }
1042 #
1043 receptor_atmtypes <- unique(prereceptor_atmtypes)
1044 #
1045
1046 filtered_receptor <- c()
1047 for(i in 1:length(receptor_atmtypes)){
1048
1049 #print(receptor_atmtypes[i])
1050 #print(is.na(as.numeric(receptor_atmtypes[i])))
1051
1052 if(suppressWarnings(is.na(as.numeric(receptor_atmtypes[i])))){
1053 filtered_receptor <- c(filtered_receptor, receptor_atmtypes[i])
1054 }
1055
1056 }
1057
1058 receptor_atmtypes <- filtered_receptor
1059
1060 cabeceratm <- receptor_atmtypes[1]
1061 for(rat in 2:length(receptor_atmtypes)){
1062
1063 cabeceratm <- paste(cabeceratm, receptor_atmtypes[rat], sep = " ")
1064 }
1065
1066 write(cabeceratm, file = receptor_types_file_out, append = FALSE)
1067
1068
1069 #21junio2019
1070
1071
1072
1073
1074 # #::::::::06sep2019:::::::::::::::::#
1075 #
1076 # #Make the file receptor_types_file_out.txt removing duplicates and Na
1077 # #21junio2019
1078 #
1079 # #
1080 # prereceptor_atmtypes <- c()
1081 # for(i in 1:nrow(tabla_ordenados)){
1082 # if(tabla_ordenados[i,13] != ""){
1083 # prereceptor_atmtypes <- c(prereceptor_atmtypes, tabla_ordenados[i,13])
1084 # }
1085 # }
1086 # #
1087 # # #print(prereceptor_atmtypes)
1088 # #
1089 # receptor_atmtypes <- unique(prereceptor_atmtypes)
1090 # #21junio2019
1091 #
1092 # quitar <- 0
1093 # for(i in 1:length(receptor_atmtypes)){
1094 # if(isTRUE(receptor_atmtypes[i] == "Na")){
1095 # quitar <- i
1096 # break
1097 # }
1098 # }
1099 #
1100 # if(quitar == 0){
1101 # cabeceratm <- receptor_atmtypes[1]
1102 # for(rat in 2:length(receptor_atmtypes)){
1103 # cabeceratm <- paste(cabeceratm, receptor_atmtypes[rat], sep = " ")
1104 # }
1105 #
1106 # write(cabeceratm, file = "receptor_types_file_out.txt", append = FALSE)
1107 # }
1108 #
1109 # if(quitar != 0){
1110 # receptor_atmtypes <- receptor_atmtypes[-quitar]
1111 # cabeceratm_types <- receptor_atmtypes[1]
1112 # for(at_t in 2:length(receptor_atmtypes)){
1113 # cabeceratm_types <- paste(cabeceratm_types, receptor_atmtypes[at_t], sep = " ")
1114 # }
1115 # write(cabeceratm_types, file = "receptor_types_file_out.txt", append = FALSE)
1116 # }
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127