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