001/* This class is based on the original FATCAT implementation by
002 * <pre>
003 * Yuzhen Ye & Adam Godzik (2003)
004 * Flexible structure alignment by chaining aligned fragment pairs allowing twists.
005 * Bioinformatics vol.19 suppl. 2. ii246-ii255.
006 * https://www.ncbi.nlm.nih.gov/pubmed/14534198
007 * </pre>
008 *
009 * Thanks to Yuzhen Ye and A. Godzik for granting permission to freely use and redistribute this code.
010 *
011 * This code may be freely distributed and modified under the
012 * terms of the GNU Lesser General Public Licence.  This should
013 * be distributed with the code.  If you do not have a copy,
014 * see:
015 *
016 *      http://www.gnu.org/copyleft/lesser.html
017 *
018 * Copyright for this code is held jointly by the individual
019 * authors.  These should be listed in @author doc comments.
020 *
021 *
022 * Created on Jun 17, 2009
023 * Created by Andreas Prlic - RCSB PDB
024 *
025 */
026
027package org.biojava.nbio.structure.align.fatcat.calc;
028
029import org.biojava.nbio.structure.align.ce.ConfigStrucAligParams;
030
031import java.io.StringWriter;
032import java.lang.reflect.Method;
033import java.util.ArrayList;
034import java.util.List;
035
036
037public class FatCatParameters implements ConfigStrucAligParams
038{
039
040        public static final int DEFAULT_FRAGLEN = 8;
041
042        int fragLen  ; // the length of the fragments to consider...
043        int fragLenSq ;
044        Double rmsdCut; // cutoff for AFP detection.
045        double disCut; // for AFPs connection, to be tuned, 4.0
046        double afpDisCut;
047        double afpDisCut0;
048        double disSmooth; // for smooth calculation of twist penalty calculation
049        int misCut;
050        int maxGap;
051        int maxGapFrag;
052        double disFilter;
053        double badRmsd;
054        int maxTra; // the maximum number of Twists that are allowed...
055        double gapCreate;
056        double gapExtend;
057        double misScore;
058        double torsionPenalty;
059        double maxPenalty;
060        double resScore;
061        double fragScore;
062        int sparse;
063        boolean optimizeAlignment; //whether to do post-processing to improve the alignment
064        public FatCatParameters(){
065                reset();
066        }
067
068
069        @Override
070        public void reset(){
071                // Note: Update FatCatUserArgumentProcessor.FatCatStartupParams after
072                // modifying user-exposed values
073                fragLen = DEFAULT_FRAGLEN;
074                fragLenSq = fragLen * fragLen;
075                rmsdCut = 3.0; //cutoff for AFP detection
076                disCut = 5.0; //for AFPs connection, to be tuned, 4.0
077                afpDisCut = fragLenSq * disCut * disCut;
078                afpDisCut0 = fragLenSq * disCut;
079                disSmooth = 4.0; //for smoothly calculation of twist penalty calculation
080                misCut = 2 * fragLen; //structural-dismilar ranges allowed between AFPs
081                maxGap = 40; //try-1 30
082                maxGapFrag = fragLen + maxGap;
083                disFilter = 2.0 * rmsdCut; //for single AFP denifition to be tuned! //two CA-dis is 3.6
084                badRmsd = 4.0; //very important paramerter for twists detection
085                maxTra = 5;
086                gapCreate = -5.0;
087                gapExtend = -0.5;
088                misScore = gapExtend; //comparable to gapExtend
089                torsionPenalty = 5 * gapCreate; //to be tuned
090                maxPenalty = 1 * gapCreate; //to be tuned
091                resScore = 3.0; //on average, the score for each well-matched residue pair
092                fragScore = resScore * fragLen; //the score for each well-matched fragment
093                sparse = 0;
094                optimizeAlignment = true; //No effect at the moment
095        }
096
097
098        public Integer getFragLen()
099        {
100                return fragLen;
101        }
102
103
104        public void setFragLen(Integer fragLen)
105        {
106                this.fragLen = fragLen;
107        }
108
109
110        public int getFragLenSq()
111        {
112                return fragLenSq;
113        }
114
115
116        public void setFragLenSq(int fragLenSq)
117        {
118                this.fragLenSq = fragLenSq;
119        }
120
121
122        /** The cutoff to be used during AFP detection
123         *
124         * @return rmsdCut parameter
125         */
126        public Double getRmsdCut()
127        {
128                return rmsdCut;
129        }
130
131        /** The cutoff to be used during AFP detection
132         *
133         * @param rmsdCut
134         */
135        public void setRmsdCut(Double rmsdCut)
136        {
137                this.rmsdCut = rmsdCut;
138        }
139
140        /** Get the distance cutoff used during AFP chain connectivity checks
141         *
142         * @return distance Cutoff
143         */
144        public Double getDisCut()
145        {
146                return disCut;
147        }
148
149
150        public void setDisCut(Double disCut)
151        {
152                this.disCut = disCut;
153        }
154
155
156        public double getAfpDisCut()
157        {
158                return afpDisCut;
159        }
160
161
162        public void setAfpDisCut(double afpDisCut)
163        {
164                this.afpDisCut = afpDisCut;
165        }
166
167
168        public double getAfpDisCut0()
169        {
170                return afpDisCut0;
171        }
172
173
174        public void setAfpDisCut0(double afpDisCut0)
175        {
176                this.afpDisCut0 = afpDisCut0;
177        }
178
179
180        public double getDisSmooth()
181        {
182                return disSmooth;
183        }
184
185
186        public void setDisSmooth(double disSmooth)
187        {
188                this.disSmooth = disSmooth;
189        }
190
191
192        public int getMisCut()
193        {
194                return misCut;
195        }
196
197
198        public void setMisCut(int misCut)
199        {
200                this.misCut = misCut;
201        }
202
203
204        public int getMaxGap()
205        {
206                return maxGap;
207        }
208
209
210        public void setMaxGap(int maxGap)
211        {
212                this.maxGap = maxGap;
213        }
214
215
216        public int getMaxGapFrag()
217        {
218                return maxGapFrag;
219        }
220
221
222        public void setMaxGapFrag(int maxGapFrag)
223        {
224                this.maxGapFrag = maxGapFrag;
225        }
226
227
228        public double getDisFilter()
229        {
230                return disFilter;
231        }
232
233
234        public void setDisFilter(double disFilter)
235        {
236                this.disFilter = disFilter;
237        }
238
239
240        public double getBadRmsd()
241        {
242                return badRmsd;
243        }
244
245
246        public void setBadRmsd(double badRmsd)
247        {
248                this.badRmsd = badRmsd;
249        }
250
251
252        /** get the maximum number of Twists that are allowed...
253         *
254         * @return max nr of allowed twists
255         */
256        public Integer getMaxTra()
257        {
258                return maxTra;
259        }
260
261        /** set the maximum number of Twists that are allowed...
262         *
263         * @param maxTra
264         */
265        public void setMaxTra(Integer maxTra)
266        {
267                this.maxTra = maxTra;
268        }
269
270
271        public double getGapCreate()
272        {
273                return gapCreate;
274        }
275
276
277        public void setGapCreate(double gapCreate)
278        {
279                this.gapCreate = gapCreate;
280        }
281
282
283        public double getGapExtend()
284        {
285                return gapExtend;
286        }
287
288
289        public void setGapExtend(double gapExtend)
290        {
291                this.gapExtend = gapExtend;
292        }
293
294
295        public double getMisScore()
296        {
297                return misScore;
298        }
299
300
301        public void setMisScore(double misScore)
302        {
303                this.misScore = misScore;
304        }
305
306
307        public double getTorsionPenalty()
308        {
309                return torsionPenalty;
310        }
311
312
313        public void setTorsionPenalty(double torsionPenalty)
314        {
315                this.torsionPenalty = torsionPenalty;
316        }
317
318
319        public double getMaxPenalty()
320        {
321                return maxPenalty;
322        }
323
324
325        public void setMaxPenalty(double maxPenalty)
326        {
327                this.maxPenalty = maxPenalty;
328        }
329
330
331        public double getResScore()
332        {
333                return resScore;
334        }
335
336
337        public void setResScore(double resScore)
338        {
339                this.resScore = resScore;
340        }
341
342
343        public double getFragScore()
344        {
345                return fragScore;
346        }
347
348
349        public void setFragScore(double fragScore)
350        {
351                this.fragScore = fragScore;
352        }
353
354
355        public int getSparse()
356        {
357                return sparse;
358        }
359
360
361        public void setSparse(int sparse)
362        {
363                this.sparse = sparse;
364        }
365
366
367        @Override
368        public List<String> getUserConfigHelp() {
369                List<String> params = new ArrayList<String>();
370                String fragLen = "The length of the fragments.";
371                String rmsdCutHelp = "The RMSD cutoff to be used during AFP detection.";
372                String disCutHelp = "The distance cutoff used when calculate the connectivity of AFP pairs";
373                String twistHelp ="The number of twists that are allowed to be introduced. If set to 0 alignments are run in RIGID mode.";
374                params.add(fragLen);
375                params.add(rmsdCutHelp);
376                params.add(disCutHelp);
377                params.add(twistHelp);
378                return params;
379
380        }
381
382
383        @Override
384        public List<String> getUserConfigParameterNames() {
385                List<String> params = new ArrayList<String>();
386                params.add("Fragment Length");
387                params.add("RMSD Cutoff");
388                params.add("AFP Distance Cutoff");
389                params.add("Maximum Nr. of twists");
390                return params;
391        }
392
393
394        @Override
395        public List<String> getUserConfigParameters() {
396                List<String> params = new ArrayList<String>();
397                params.add("FragLen");
398                params.add("RmsdCut");
399                params.add("DisCut");
400                params.add("MaxTra");
401                return params;
402        }
403
404
405        @Override
406        @SuppressWarnings({  "rawtypes" })
407        public List<Class> getUserConfigTypes() {
408
409                List<Class> params = new ArrayList<Class>();
410                params.add(Integer.class);
411                params.add(Double.class);
412                params.add(Double.class);
413                params.add(Integer.class);
414                return params;
415        }
416
417
418        @Override
419        public String toString(){
420                StringWriter writer = new StringWriter();
421                writer.append("[");
422                if ( maxTra == 0)
423                        writer.append("Mode: rigid, ");
424                else
425                        writer.append("Mode: flexible, ");
426                List<String> params = getUserConfigParameters();
427
428                for ( String s : params){
429                        writer.append(s);
430                        writer.append(": ");
431                        Object val = getValue(s);
432                        writer.append(val.toString());
433                        writer.append(", ");
434                }
435                writer.append("]");
436                return writer.toString();
437        }
438
439        private Object  getValue(String name){
440
441                try {
442                        String methodName = "get" + name;
443
444                        Class<?> paramC = this.getClass();
445
446                        Method m =paramC.getMethod(methodName,(Class[])null);
447
448                        Object value = m.invoke(this);
449
450                        return value;
451                } catch (Exception e){
452                        e.printStackTrace();
453                        return null;
454                }
455
456
457        }
458
459        /**
460         * Whether the alignment algorithm should try its best to optimize the alignment,
461         * or we are happy with a quick and dirty result.
462         * NB: Not implemented in jFatCat
463         *
464         * @return optimizeAlignment
465         */
466        public boolean isOptimizeAlignment() {
467                return optimizeAlignment;
468        }
469
470        /**
471         * Whether the alignment algorithm should try its best to optimize the alignment,
472         * or we are happy with a quick and dirty result.
473         * NB: Not implemented in jFatCat
474         *
475         * @param optimizeAlignment
476         */
477        public void setOptimizeAlignment(boolean optimizeAlignment) {
478                this.optimizeAlignment = optimizeAlignment;
479        }
480}