comparison PLIDflow/scripts/clusterfilemaker.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 #clusterfilemaker.R makes a file containg geometric center coordenates for FILL_Xout1.pdb files. X represents envelopes size from 10 to 100
2
3 #!/usr/bin/env Rscript
4 args = commandArgs(trailingOnly=TRUE)
5
6 if(length(args) < 1){
7 stop("USE: Rscript clusterfilemaker.R <session_id>")
8 }
9
10 #Select the directory where all files are being stored
11
12 session_id <- args[1]
13
14 print(session_id)
15
16 setwd(session_id)
17
18 #Scan dataset containig FILL_<point>out1.pdb with point from 10 to 500
19 fill_outs_1 <- scan("templatefillouts1.txt", what = character(), quiet = TRUE)
20
21 #Write the head for the file later created which contains the middle point from FILL_<point>out1.pdb with point from 10 to 500
22 cabecera_fillfile <- paste("npts", sep = ";")
23 cabecera <- c("x","y","z")
24
25 for(i in 1:3){
26 cabecera_fillfile <- paste(cabecera_fillfile, cabecera[i], sep=";")
27 }
28 write(cabecera_fillfile, file="fillouts1file.txt", append= TRUE)
29
30 #Loop to read the files FILL_<point>out1.pdb and calculate the middle point
31 num_points <- 0
32 start_env <- 10 # to fit the first envelope size. In case to change envelope size, only modify this parameter
33 jp <- 10 #jump between envelopes size. In case modify jump between envelopes size, only modify this parameter
34 #In case modify start envelope size and jump, only modify start_env and jp parameters in the script nothing in following steps
35
36
37
38
39
40 num_points <- (start_env - jp)
41 for(f in 1:length(fill_outs_1)){
42 # print(paste("Testing file ", fill_outs_1[f]))
43 if(file_test("-f", fill_outs_1[f])){
44 archivo <- scan(fill_outs_1[f], what = character(), quiet = TRUE)
45 }else{
46 next
47 }
48
49 #Make a table with only x, y, z coordenates for C atoms only
50 salto <- 0
51 for(i in 1:(length(archivo)-2)){
52 if(archivo[i] == "ATOM" && ( archivo[i+2] == "C" || archivo[i+2] == "O" || archivo[i+2] == "H" )){
53 salto <- salto + 1
54 }
55 }
56 tablaC <- matrix(1, nrow = salto, ncol = 4)
57
58 #Names for columns
59 ##First column correspond to position for atoms C. This column will be created when the C atom positions will be know
60 ###Write the name for columns and rows
61 colnames(tablaC) <- c("C Position","X", "Y", "z")
62 rownames(tablaC) <- 1:salto
63
64 #Calculate the number of C atoms and to write theirs coordenates x,y,z in the tablaC
65 salto <- 0
66 posicionC <- c()
67 for(i in 1:(length(archivo)-2)){
68 if(archivo[i] == "ATOM" && ( archivo[i+2] == "C" || archivo[i+2] == "O" || archivo[i+2] == "H" )){
69 salto <- salto + 1
70 posicionC <- c(posicionC, archivo[i+1])
71 tablaC[salto,2] <- as.numeric(archivo[i+5])
72 tablaC[salto,3] <- as.numeric(archivo[i+6])
73 tablaC[salto,4] <- as.numeric(archivo[i+7])
74 }
75 }
76
77 #Write the C atoms positions in column 1 of the table tablaC
78 for(i in 1:salto){
79 tablaC[i,1] <- as.numeric(posicionC[i])
80 }
81
82 #Calculate middle point for the FILL_<point>out1.pdb given
83 pto_x_medio <- (max(tablaC[,2]) + min(tablaC[,2]))/2
84 pto_y_medio <- (max(tablaC[,3]) + min(tablaC[,3]))/2
85 pto_z_medio <- (max(tablaC[,4]) + min(tablaC[,4]))/2
86
87 #Write a plain text called fillouts1file.txt which contain in the first column number of point
88 #for the envelope according to AutoLigand program. Columns 2,3,4 for coordenates x, y ,z
89 #for the middle points for FILL_<point>out1.pdb from 10 to 500 points
90 num_points <- num_points + jp
91 write(paste(num_points,pto_x_medio, pto_y_medio, pto_z_medio, sep=";"),file="fillouts1file.txt", append= TRUE)
92 }
93
94
95
96
97
98
99
100
101