Repository navigation
Expand file tree
/
Copy pathBioJavaStructureAlignment.java
More file actions
209 lines (160 loc) · 5.49 KB
/
Copy pathBioJavaStructureAlignment.java
File metadata and controls
209 lines (160 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
* Created on Oct 2, 2009
* Author: Andreas Prlic
*
*/
package org.biojava.nbio.structure.align;
import org.biojava.nbio.structure.Atom;
import org.biojava.nbio.structure.Group;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.StructureTools;
import org.biojava.nbio.structure.align.ce.ConfigStrucAligParams;
import org.biojava.nbio.structure.align.helper.IndexPair;
import org.biojava.nbio.structure.align.model.AFPChain;
import org.biojava.nbio.structure.align.pairwise.AlternativeAlignment;
import org.biojava.nbio.structure.jama.Matrix;
/** Wrapper for the BioJava Structure Alignment Implementation
*
* @author Andreas Prlic
*
*/
public class BioJavaStructureAlignment
implements StructureAlignment {
public static final String algorithmName = "BioJava_structure";
private static final float versionNr = 0.1f;
StrucAligParameters params;
public BioJavaStructureAlignment(){
params = new StrucAligParameters();
}
@Override
public String getAlgorithmName() {
return algorithmName;
}
@Override
public ConfigStrucAligParams getParameters() {
return null;//TODO shall we update it?
}
@Override
public void setParameters(ConfigStrucAligParams o){
//TODO what is the relation between StrucAligParameters and ConfigStrucAligParams?
if ( ! (o instanceof StrucAligParameters)){
throw new IllegalArgumentException("Provided parameters are not of type StrucAligParameters!");
}
params = (StrucAligParameters) o;
}
@Override
public String getVersion() {
return String.valueOf(versionNr);
}
public String printHelp() {
return "not implemented yet. Algorithm still under development.";
}
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2) throws StructureException {
StrucAligParameters params = StrucAligParameters.getDefaultParameters();
return align(ca1,ca2,params);
}
@Override
public AFPChain align(Atom[] ca1, Atom[] ca2, Object params)
throws StructureException {
if ( ! (params instanceof StrucAligParameters)){
throw new IllegalArgumentException("BioJava structure alignment requires a StrucAligParameters class for the arguments.");
}
this.params = (StrucAligParameters) params;
AFPChain afpChain = new AFPChain(algorithmName);
StructurePairAligner aligner = new StructurePairAligner();
aligner.align(ca1,ca2,this.params);
// copy the results over into the AFPChain...
AlternativeAlignment[] aligs = aligner.getAlignments();
if ( aligs.length > 0){
AlternativeAlignment altAlig = aligs[0];
// copy the results over!
copyResults(afpChain,altAlig,ca1,ca2);
}
return afpChain;
}
private void copyResults(AFPChain afpChain, AlternativeAlignment altAlig, Atom[] ca1, Atom[] ca2) {
afpChain.setAlgorithmName(getAlgorithmName());
afpChain.setVersion(getVersion());
afpChain.setAlignScore(altAlig.getScore());
afpChain.setOptLength(altAlig.getEqr());
afpChain.setBlockRotationMatrix(new Matrix[]{altAlig.getRotationMatrix()});
afpChain.setBlockShiftVector(new Atom[]{altAlig.getShift() });
afpChain.setBlockNum(1);
double rmsd = altAlig.getRmsd();
afpChain.setBlockRmsd(new double[]{rmsd});
int nAtom = altAlig.getEqr();
int lcmp = altAlig.getPath().length;
int[] optLen = new int[]{nAtom};
afpChain.setOptLen(optLen);
afpChain.setOptLength(nAtom);
afpChain.setAlnLength(lcmp);
int[][][] optAln = new int[1][2][lcmp];
afpChain.setOptAln(optAln);
afpChain.setOptRmsd(new double[]{rmsd});
afpChain.setTotalRmsdOpt(rmsd);
afpChain.setChainRmsd(rmsd);
//afpChain.setProbability(-1);
int nse1 = ca1.length;
int nse2 = ca2.length;
char[] alnseq1 = new char[nse1+nse2+1];
char[] alnseq2 = new char[nse1+nse2+1] ;
char[] alnsymb = new char[nse1+nse2+1];
IndexPair[] path = altAlig.getPath();
int pos = 0;
for(int ia=0; ia<lcmp; ia++) {
IndexPair align_se = path[ia];
// no gap
if(align_se.getRow() !=-1 && align_se.getCol()!=-1) {
optAln[0][0][pos] = align_se.getRow();
optAln[0][1][pos] = align_se.getCol();
char l1 = getOneLetter(ca1[align_se.getRow()].getGroup());
char l2 = getOneLetter(ca2[align_se.getCol()].getGroup());
alnseq1[ia] = Character.toUpperCase(l1);
alnseq2[ia] = Character.toUpperCase(l2);
alnsymb[ia] = '1';
pos++;
} else {
// there is a gap on this position
alnsymb[ia] = ' ';
if (align_se.getRow() == -1 ) {
alnseq1[ia] = '-';
} else {
char l1 = getOneLetter(ca1[align_se.getRow()].getGroup());
alnseq1[ia] = Character.toLowerCase(l1);
}
if ( align_se.getCol() == -1 ) {
alnseq2[ia] = '-';
} else {
char l2 = getOneLetter(ca2[align_se.getCol()].getGroup());
alnseq2[ia] = Character.toLowerCase(l2);
}
}
}
afpChain.setAlnseq1(alnseq1);
afpChain.setAlnseq2(alnseq2);
afpChain.setAlnsymb(alnsymb);
}
private static char getOneLetter(Group g){
if (g==null) return StructureTools.UNKNOWN_GROUP_LABEL;
return StructureTools.get1LetterCode(g.getPDBName());
}
}