Skip to content

Commit 245b98b

Browse files
committed
A new folder for further work
1 parent 32031bf commit 245b98b

File tree

6 files changed

+1903
-0
lines changed

6 files changed

+1903
-0
lines changed

StructAlign/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
all:
2+
gcc algorithm.c pdb.c -o align -lm
3+

StructAlign/algorithm.c

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
#include "pdb.h"
2+
#include <math.h>
3+
4+
int main (int argc, char **argv)
5+
{
6+
7+
/* Checking command line,
8+
throw exception if not complete */
9+
10+
if (argc != 4)
11+
{
12+
printf("\nUsage: %s <input file 1.pdb> <input file 2.pdb> <output file>", argv[0]);
13+
printf("\nExample: %s 3hdd.pdb 1puf.pdb superpos_3hdd_1puf.pdb\n\n", argv[0]);
14+
exit (1);
15+
} /* end if */
16+
17+
/* Done checking command line */
18+
19+
/* Reading command line arguments */
20+
21+
char *infile1, *infile2, *outfile;
22+
23+
infile1 = (char *)malloc( sizeof(char)*(strlen(argv[1])+1) );
24+
sscanf(argv[1],"%s", infile1);
25+
26+
infile2 = (char *)malloc( sizeof(char)*(strlen(argv[2])+1) );
27+
sscanf(argv[2],"%s", infile2);
28+
29+
outfile = (char *)malloc( sizeof(char)*(strlen(argv[3])+1) );
30+
sscanf(argv[3], "%s", outfile);
31+
32+
/* Done reading arguments */
33+
34+
/* DECLARATION AND ASSIGNMENT
35+
OF SOME VARIABLES */
36+
37+
struct atom *atoms_prot1 = NULL, *atoms_prot2 = NULL;
38+
struct atom *atoms_dna1 = NULL, *atoms_dna2 = NULL;
39+
struct atom *atoms_wat1 = NULL, *atoms_wat2 = NULL;
40+
struct atom *atoms_prot_CA1 = NULL, *atoms_prot_CA2 = NULL;
41+
struct atom *atoms_prot_i1 = NULL, *atoms_prot_i2 = NULL;
42+
struct atom *atoms_prot_j1 = NULL, *atoms_prot_j2 = NULL;
43+
44+
struct atomname *list1, *list2;
45+
46+
unsigned int maxnumber = 256; //primary number of atoms in each groups (DNA, protein, water)
47+
FILE *flow_out;
48+
unsigned int m1=0, n1=0, w1=0, i, j, m2=0, n2=0, w2=0;
49+
/* m - number of DNA atoms
50+
* n - number of protein atoms
51+
* w - number of water atoms */
52+
char *dna_chains1 = (char *)malloc( sizeof(char)*(2+1) );
53+
char *prot_chains1 = (char *)malloc( sizeof(char)*(2+1) );
54+
char *dna_chains2 = (char *)malloc( sizeof(char)*(2+1) );
55+
char *prot_chains2 = (char *)malloc( sizeof(char)*(2+1) );
56+
57+
/* Reading PDB file */
58+
59+
puts("Reading 1st PDB file...");
60+
readerPDB(infile1, &m1, &n1, &w1, maxnumber, &atoms_dna1, &dna_chains1, &atoms_prot1, &prot_chains1, &atoms_wat1, &list1);
61+
// pdb.c function, read PDB and put protein, DNA and water atoms in three different arrays
62+
printf("...done; %d atoms of dna, %d atoms of protein, %d atoms of water\n", m1, n1, w1);
63+
SelectChain(atoms_prot1, n1, &atoms_prot1, &n1, prot_chains1[1]);
64+
// pdb.c function, select only first chain of protein from PDB file.
65+
printf("Atoms in selected chain: %u\n\n", n1);
66+
// print to stdout number of protein atoms in selected chain
67+
68+
puts("Reading 2nd PDB file...");
69+
readerPDB(infile2, &m2, &n2, &w2, maxnumber, &atoms_dna2, &dna_chains2, &atoms_prot2, &prot_chains2, &atoms_wat2, &list2);
70+
printf("...done; %d atoms of dna, %d atoms of protein, %d atoms of water\n", m2, n2, w2);
71+
SelectChain(atoms_prot2, n2, &atoms_prot2, &n2, prot_chains2[1]);
72+
printf("Atoms in selected chain: %u\n\n", n2);
73+
74+
dna_chains1[0] = ' '; dna_chains2[0] = ' ';
75+
printf("DNA1 chains: %s; DNA2 chains: %s\n", dna_chains1, dna_chains2);
76+
/* Done reading */
77+
78+
/* Make lists of P, C1', OP1 atoms
79+
of dna and CA atoms of protein */
80+
81+
unsigned int *list_P1, *list_C11, *list_OP11, *list_OP21, *list_CA1, *list_P2, *list_C12, *list_OP12, *list_OP22, *list_CA2;
82+
unsigned int n_P1, n_C11, n_OP11, n_OP21, n_CA1, n_P2, n_C12, n_OP12, n_OP22, n_CA2;
83+
84+
getAtomsNumbers(atoms_dna1, m1, &list_P1, &n_P1, "P");
85+
// pdb.c function, get only indexes of atoms
86+
getAtomsNumbers(atoms_dna1, m1, &list_C11, &n_C11, "C1'");
87+
getAtomsNumbers(atoms_dna1, m1, &list_OP11, &n_OP11, "OP1");
88+
getAtomsNumbers(atoms_dna1, m1, &list_OP21, &n_OP21, "OP2");
89+
getAtomsNumbers(atoms_prot1, n1, &list_CA1, &n_CA1, "CA");
90+
correctC1_P(atoms_dna1, &list_C11, &n_C11, list_P1, n_P1);
91+
//corrects list_C1 to use rule list_P[i] and list_C1[i+1] are in the same nucleotide
92+
93+
getAtomsNumbers(atoms_dna2, m2, &list_P2, &n_P2, "P");
94+
getAtomsNumbers(atoms_dna2, m2, &list_C12, &n_C12, "C1'");
95+
getAtomsNumbers(atoms_dna2, m2, &list_OP12, &n_OP12, "OP1");
96+
getAtomsNumbers(atoms_dna2, m2, &list_OP22, &n_OP22, "OP2");
97+
getAtomsNumbers(atoms_prot2, n2, &list_CA2, &n_CA2, "CA");
98+
correctC1_P(atoms_dna2, &list_C12, &n_C12, list_P2, n_P2);
99+
100+
atoms_prot_CA1 = (struct atom *)malloc( sizeof(struct atom)*(n_CA1+1) );
101+
for (i=1; i<=n_CA1; i++) {
102+
atomcpy(&atoms_prot_CA1[i], atoms_prot1[list_CA1[i]]);
103+
//pdb.c function. Copy all properties of atom
104+
}
105+
printf("Done atoms:\tP %u\tC1 %u\tOP1 %u\tOP2 %u\tCA %u\n",n_P1, n_C11, n_OP11, n_OP21, n_CA1);
106+
107+
atoms_prot_CA2 = (struct atom *)malloc( sizeof(struct atom)*(n_CA2+1) );
108+
for (i=1; i<=n_CA2; i++) {
109+
atomcpy(&atoms_prot_CA2[i], atoms_prot2[list_CA2[i]]);
110+
}
111+
printf("Done atoms:\tP %u\tC1 %u\tOP1 %u\tOP2 %u\tCA %u\n",n_P2, n_C12, n_OP12, n_OP22, n_CA2);
112+
113+
/* Done making lists */
114+
115+
/* Create array of measures for
116+
all pairs of dna P atoms (list_measure).
117+
dim(list_measure) = n_P2 x n_P1 */
118+
119+
double **list_measure;
120+
unsigned int n_hit;
121+
unsigned int **list_hit;
122+
123+
list_measure = (double **)malloc( (n_P2+1)*sizeof(double *)*(n_P1+1) );
124+
for (i=1; i<=n_P1; i++) list_measure[i] = (double *)malloc( sizeof(double)*(n_P2+1) );
125+
//for (i=1; i<=n_P1; i++) for (j=1; j<=n_P2;j++) list_measure[i][j] = (unsigned int *)malloc( sizeof(unsigned int) );
126+
// Enable if measure function returns unsigned int
127+
128+
129+
for (i=1; i<=n_P1; i++){
130+
for (j=1; j<=n_P2; j++){
131+
ChangeSystem(atoms_prot_CA1, n_CA1, &atoms_prot_i1, atoms_dna1[list_P1[i]], atoms_dna1[list_C11[i+1]], atoms_dna1[list_OP11[i]], atoms_dna1[list_OP21[i]], 'E');
132+
// pdb.c function. Change the coordinate system of protein with given nucleotide
133+
ChangeSystem(atoms_prot_CA2, n_CA2, &atoms_prot_j2, atoms_dna2[list_P2[j]], atoms_dna2[list_C12[j+1]], atoms_dna2[list_OP12[j]], atoms_dna2[list_OP22[j]], 'F');
134+
BidirectionalHit(atoms_prot_i1, n_CA1, atoms_prot_j2, n_CA2, &list_hit, &n_hit);
135+
// pdb.c function.
136+
Measure2_p(&(list_measure[i][j]), list_hit, n_hit, atoms_prot_i1, atoms_prot_j2);
137+
// pdb.c function.
138+
// printf("Measure: %f i: %u j: %u n_P1: %u n_P2: %u \n",(list_measure[i][j]), i,j, n_P1, n_P2);
139+
// Enable in test mode
140+
}
141+
}
142+
143+
/* Done creation of array of measures */
144+
145+
146+
/* Start working with diagonals */
147+
148+
unsigned int i_max, j_max, i_start, j_start, i_max_measure, j_max_measure;
149+
unsigned int compl1, compl2, n_first_chain, m_first_chain;
150+
double S_max;
151+
struct atom *atoms_dna_P1 = NULL;
152+
struct atom *atoms_dna_P2 = NULL;
153+
154+
// print measure-table
155+
/*printf(" ");
156+
for (j=1; j<=n_P2; j++) printf("%4d", j);
157+
puts("");
158+
for (i=n_P1; i>=1; i--){
159+
printf("%2d", i);
160+
for (j=1; j<=n_P2; j++){
161+
printf("%4.0f", list_measure[i][j]>0 ? list_measure[i][j] : 0);
162+
}
163+
puts("");
164+
}
165+
printf(" ");
166+
for (j=1; j<=n_P2; j++) printf("%4d", j);
167+
puts("");
168+
*/
169+
170+
i_max_measure=0;
171+
j_max_measure=0;
172+
atoms_dna_P1 = (struct atom *)malloc( sizeof(struct atom)*(n_P1+1) );
173+
for (i=1; i<=n_P1; i++) {
174+
atomcpy(&atoms_dna_P1[i], atoms_dna1[list_P1[i]]);
175+
}
176+
atoms_dna_P2 = (struct atom *)malloc( sizeof(struct atom)*(n_P2+1) );
177+
for (i=1; i<=n_P2; i++) {
178+
atomcpy(&atoms_dna_P2[i], atoms_dna2[list_P2[i]]);
179+
180+
}
181+
182+
find_compl(atoms_dna1, list_P1, list_C11, list_OP11, list_OP21, atoms_dna_P1, n_P1, &compl1, &n_first_chain);
183+
find_compl(atoms_dna2, list_P2, list_C12, list_OP12, list_OP22, atoms_dna_P2, n_P2, &compl2, &m_first_chain);
184+
BestDiag(list_measure, n_P1, n_P2, &S_max, &i_max, &j_max, &i_start, &j_start, &i_max_measure, &j_max_measure,
185+
atoms_dna1, list_P1, atoms_dna2, list_P2, compl1, compl2, n_first_chain, m_first_chain);
186+
// pdb.c function
187+
188+
/* Done diagonal search */
189+
190+
191+
struct atom *atoms_dna_i1 = NULL;
192+
struct atom *atoms_dna_j2 = NULL;
193+
/* Change the system to i and j coordinates, write the alignment to file */
194+
195+
ChangeSystem(atoms_prot1, n1, &atoms_prot_i1, atoms_dna1[list_P1[i_max_measure]], atoms_dna1[list_C11[i_max_measure+1]], atoms_dna1[list_OP11[i_max_measure]], atoms_dna1[list_OP21[i_max_measure]], 'E');
196+
// Note that names of chains will be changed to 'E' and 'F' by default! Modify if required.
197+
ChangeSystem(atoms_prot2, n2, &atoms_prot_j2, atoms_dna2[list_P2[j_max_measure]], atoms_dna2[list_C12[j_max_measure+1]], atoms_dna2[list_OP12[j_max_measure]], atoms_dna2[list_OP22[j_max_measure]], 'F');
198+
ChangeSystem(atoms_dna1, m1, &atoms_dna_i1, atoms_dna1[list_P1[i_max_measure]], atoms_dna1[list_C11[i_max_measure+1]], atoms_dna1[list_OP11[i_max_measure]], atoms_dna1[list_OP21[i_max_measure]], 'C');
199+
ChangeSystem(atoms_dna2, m2, &atoms_dna_j2, atoms_dna2[list_P2[j_max_measure]], atoms_dna2[list_C12[j_max_measure+1]], atoms_dna2[list_OP12[j_max_measure]], atoms_dna2[list_OP22[j_max_measure]], 'D');
200+
201+
puts("\nFix 'nan' in pdb with this data:");
202+
createPDB(outfile, outfile);
203+
// pdb.c function
204+
writetoPDB(outfile, atoms_dna_i1, m1);
205+
writetoPDB(outfile,
206+
atoms_prot_i1, n1);
207+
// pdb.c function. Write protein atoms to outfile
208+
209+
writetoPDB(outfile,
210+
atoms_prot_j2, n2);
211+
writetoPDB(outfile, atoms_dna_j2, m2);
212+
endPDB(outfile);
213+
214+
return 0;
215+
}
216+
/* End main */

StructAlign/align

58.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)