Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.analysis

File AlignSeq.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
21% of files have more coverage

Code metrics

222
512
46
1
1,541
1,019
179
0.35
11.13
46
3.89

Classes

Class Line # Actions
AlignSeq 54 512 179
0.6487179464.9%
 

Contributing tests

This file is covered by 223 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.analysis;
22   
23    import jalview.analysis.scoremodels.PIDModel;
24    import jalview.analysis.scoremodels.ScoreMatrix;
25    import jalview.analysis.scoremodels.ScoreModels;
26    import jalview.analysis.scoremodels.SimilarityParams;
27    import jalview.api.analysis.SimilarityParamsI;
28    import jalview.datamodel.AlignmentAnnotation;
29    import jalview.datamodel.AlignmentI;
30    import jalview.datamodel.Mapping;
31    import jalview.datamodel.Sequence;
32    import jalview.datamodel.SequenceI;
33    import jalview.math.MiscMath;
34    import jalview.util.Comparison;
35    import jalview.util.Format;
36    import jalview.util.MapList;
37    import jalview.util.MessageManager;
38   
39    import java.awt.Color;
40    import java.awt.Graphics;
41    import java.io.PrintStream;
42    import java.lang.IllegalArgumentException;
43    import java.util.ArrayList;
44    import java.util.Arrays;
45    import java.util.HashMap;
46    import java.util.List;
47    import java.util.StringTokenizer;
48    import java.util.Locale;
49   
50    /**
51    * @author $author$
52    * @version $Revision$
53    */
 
54    public class AlignSeq
55    {
56    private static final int MAX_NAME_LENGTH = 30;
57   
58    private static final int DEFAULT_OPENCOST = 120;
59   
60    private static final int DEFAULT_EXTENDCOST = 20;
61   
62    private int GAP_OPEN_COST = DEFAULT_OPENCOST;
63   
64    private int GAP_EXTEND_COST = DEFAULT_EXTENDCOST;
65   
66    private static final int GAP_INDEX = -1;
67   
68    public static final String PEP = "pep";
69   
70    public static final String DNA = "dna";
71   
72    private static final String NEWLINE = System.lineSeparator();
73   
74    float[][] score;
75   
76    float alignmentScore;
77   
78    float[][] E;
79   
80    float[][] F;
81   
82    int[][] traceback; // todo is this actually used?
83   
84    int[] seq1;
85   
86    int[] seq2;
87   
88    SequenceI s1;
89   
90    SequenceI s2;
91   
92    public String s1str;
93   
94    public String s2str;
95   
96    int maxi;
97   
98    int maxj;
99   
100    int[] aseq1;
101   
102    int[] aseq2;
103   
104    /*
105    * matches in alignment
106    */
107    int match=-1;
108   
109    public String astr1 = "";
110   
111    public String astr2 = "";
112   
113    public String indelfreeAstr1 = "";
114   
115    public String indelfreeAstr2 = "";
116   
117    /** DOCUMENT ME!! */
118    public int seq1start;
119   
120    /** DOCUMENT ME!! */
121    public int seq1end;
122   
123    /** DOCUMENT ME!! */
124    public int seq2start;
125   
126    public int seq2end;
127   
128    int count;
129   
130    public float maxscore;
131   
132    public float meanScore; // needed for PaSiMap
133   
134    public int hypotheticMaxScore; // needed for PaSiMap
135   
136    int prev = 0;
137   
138    StringBuffer output = new StringBuffer();
139   
140    String type; // AlignSeq.PEP or AlignSeq.DNA
141   
142    private ScoreMatrix scoreMatrix;
143   
144    /**
145    * Creates a new AlignSeq object.
146    *
147    * @param s1
148    * first sequence for alignment
149    * @param s2
150    * second sequence for alignment
151    * @param type
152    * molecule type, either AlignSeq.PEP or AlignSeq.DNA
153    */
 
154  0 toggle public AlignSeq(int opencost, int extcost)
155    {
156  0 GAP_OPEN_COST = opencost;
157  0 GAP_EXTEND_COST = extcost;
158    }
159   
 
160  70 toggle public AlignSeq(SequenceI s1, SequenceI s2, String type)
161    {
162  70 seqInit(s1, s1.getSequenceAsString(), s2, s2.getSequenceAsString(),
163    type);
164    }
165   
166    /**
167    * Creates a new AlignSeq object.
168    *
169    * @param s1,string1
170    * s1 reference sequence for string1
171    * @param s2,string2
172    * s2 reference sequence for string2
173    * @param type
174    * molecule type, either AlignSeq.PEP or AlignSeq.DNA
175    */
 
176  2 toggle public AlignSeq(SequenceI s1, String string1, SequenceI s2,
177    String string2, String type)
178    {
179  2 seqInit(s1, string1.toUpperCase(Locale.ROOT), s2,
180    string2.toUpperCase(Locale.ROOT), type);
181    }
182   
 
183  68 toggle public AlignSeq(SequenceI s1, SequenceI s2, String type, int opencost,
184    int extcost)
185    {
186  68 this(s1, s2, type);
187  68 GAP_OPEN_COST = opencost;
188  68 GAP_EXTEND_COST = extcost;
189    }
190   
 
191  2 toggle public AlignSeq(SequenceI s12, String string1, SequenceI s22,
192    String string2, String type2, int defaultOpencost,
193    int defaultExtendcost)
194    {
195  2 this(s12, string1, s22, string2, type2);
196  2 GAP_OPEN_COST = defaultOpencost;
197  2 GAP_EXTEND_COST = defaultExtendcost;
198    }
199   
200    /**
201    * DOCUMENT ME!
202    *
203    * @return DOCUMENT ME!
204    */
 
205  32 toggle public float getMaxScore()
206    {
207  32 return maxscore;
208    }
209   
210    /**
211    * returns the overall score of the alignment
212    *
213    * @return
214    */
 
215  2 toggle public float getAlignmentScore()
216    {
217  2 return alignmentScore;
218    }
219   
220    /**
221    * DOCUMENT ME!
222    *
223    * @return DOCUMENT ME!
224    */
 
225  131 toggle public int getSeq2Start()
226    {
227  131 return seq2start;
228    }
229   
230    /**
231    * DOCUMENT ME!
232    *
233    * @return DOCUMENT ME!
234    */
 
235  37 toggle public int getSeq2End()
236    {
237  37 return seq2end;
238    }
239   
240    /**
241    * DOCUMENT ME!
242    *
243    * @return DOCUMENT ME!
244    */
 
245  131 toggle public int getSeq1Start()
246    {
247  131 return seq1start;
248    }
249   
250    /**
251    * DOCUMENT ME!
252    *
253    * @return DOCUMENT ME!
254    */
 
255  37 toggle public int getSeq1End()
256    {
257  37 return seq1end;
258    }
259   
260    /**
261    * DOCUMENT ME!
262    *
263    * @return DOCUMENT ME!
264    */
 
265  4 toggle public String getOutput()
266    {
267  4 return output.toString();
268    }
269   
270    /**
271    * DOCUMENT ME!
272    *
273    * @return DOCUMENT ME!
274    */
 
275  38 toggle public String getAStr1()
276    {
277  38 return astr1;
278    }
279   
280    /**
281    * DOCUMENT ME!
282    *
283    * @return DOCUMENT ME!
284    */
 
285  38 toggle public String getAStr2()
286    {
287  38 return astr2;
288    }
289   
290    /**
291    * DOCUMENT ME!
292    *
293    * @return DOCUMENT ME!
294    */
 
295  2 toggle public int[] getASeq1()
296    {
297  2 return aseq1;
298    }
299   
300    /**
301    * DOCUMENT ME!
302    *
303    * @return DOCUMENT ME!
304    */
 
305  0 toggle public int[] getASeq2()
306    {
307  0 return aseq2;
308    }
309   
310    /**
311    *
312    * @return aligned instance of Seq 1
313    */
 
314  36 toggle public SequenceI getAlignedSeq1()
315    {
316  36 SequenceI alSeq1 = new Sequence(s1.getName(), getAStr1());
317  36 alSeq1.setStart(s1.getStart() + getSeq1Start() - 1);
318  36 alSeq1.setEnd(s1.getStart() + getSeq1End() - 1);
319  36 alSeq1.setDatasetSequence(
320  36 s1.getDatasetSequence() == null ? s1 : s1.getDatasetSequence());
321  36 return alSeq1;
322    }
323   
324    /**
325    *
326    * @return aligned instance of Seq 2
327    */
 
328  36 toggle public SequenceI getAlignedSeq2()
329    {
330  36 SequenceI alSeq2 = new Sequence(s2.getName(), getAStr2());
331  36 alSeq2.setStart(s2.getStart() + getSeq2Start() - 1);
332  36 alSeq2.setEnd(s2.getStart() + getSeq2End() - 1);
333  36 alSeq2.setDatasetSequence(
334  36 s2.getDatasetSequence() == null ? s2 : s2.getDatasetSequence());
335  36 return alSeq2;
336    }
337    /**
338    * fraction of seq2 matched in the alignment
339    *
340    * @return NaN or [0..1]
341    */
 
342  31 toggle public double getS2Coverage()
343    {
344  31 if (match >= 0)
345    {
346  31 return ((double) match) / ((double) s2.getEnd() - s2.getStart() + 1);
347    }
348  0 return Double.NaN;
349    }
350   
351    /**
352    * fraction of seq1 matched in the alignment
353    *
354    * @return NaN or [0..1]
355    */
 
356  32 toggle public double getS1Coverage()
357    {
358  32 if (match >= 0)
359    {
360  32 return ((double) match) / ((double) s1.getEnd() - s1.getStart() + 1);
361    }
362  0 return Double.NaN;
363    }
364   
365    /**
366    * Construct score matrix for sequences with standard DNA or PEPTIDE matrix
367    *
368    * @param s1
369    * - sequence 1
370    * @param string1
371    * - string to use for s1
372    * @param s2
373    * - sequence 2
374    * @param string2
375    * - string to use for s2
376    * @param type
377    * DNA or PEPTIDE
378    */
 
379  72 toggle public void seqInit(SequenceI s1, String string1, SequenceI s2,
380    String string2, String type)
381    {
382  72 seqInit(s1, string1, s2, string2, type, GAP_OPEN_COST, GAP_EXTEND_COST);
383    }
384   
 
385  72 toggle public void seqInit(SequenceI s1, String string1, SequenceI s2,
386    String string2, String type, int opening, int extension)
387    {
388  72 GAP_OPEN_COST = opening;
389  72 GAP_EXTEND_COST = extension;
390  72 this.s1 = s1;
391  72 this.s2 = s2;
392  72 setDefaultParams(type);
393  72 seqInit(string1, string2);
394    }
395   
396    /**
397    * construct score matrix for string1 and string2 (after removing any existing
398    * gaps
399    *
400    * @param string1
401    * @param string2
402    */
 
403  72 toggle private void seqInit(String string1, String string2)
404    {
405  72 s1str = extractGaps(jalview.util.Comparison.GapChars, string1);
406  72 s2str = extractGaps(jalview.util.Comparison.GapChars, string2);
407   
408  72 if (s1str.length() == 0 || s2str.length() == 0)
409    {
410  0 output.append(
411  0 "ALL GAPS: " + (s1str.length() == 0 ? s1.getName() : " ")
412  0 + (s2str.length() == 0 ? s2.getName() : ""));
413  0 return;
414    }
415   
416  72 score = new float[s1str.length()][s2str.length()];
417   
418  72 E = new float[s1str.length()][s2str.length()];
419   
420  72 F = new float[s1str.length()][s2str.length()];
421  72 traceback = new int[s1str.length()][s2str.length()];
422   
423  72 seq1 = indexEncode(s1str);
424   
425  72 seq2 = indexEncode(s2str);
426    }
427   
 
428  72 toggle private void setDefaultParams(String moleculeType)
429    {
430  72 if (!PEP.equals(moleculeType) && !DNA.equals(moleculeType))
431    {
432  0 output.append("Wrong type = dna or pep only");
433  0 throw new Error(MessageManager
434    .formatMessage("error.unknown_type_dna_or_pep", new String[]
435    { moleculeType }));
436    }
437   
438  72 type = moleculeType;
439  72 scoreMatrix = ScoreModels.getInstance()
440    .getDefaultModel(PEP.equals(type));
441    }
442   
443    /**
444    * DOCUMENT ME!
445    */
 
446  70 toggle public void traceAlignment()
447    {
448    // Find the maximum score along the rhs or bottom row
449  70 float max = -Float.MAX_VALUE;
450   
451  10408 for (int i = 0; i < seq1.length; i++)
452    {
453  10338 if (score[i][seq2.length - 1] > max)
454    {
455  6161 max = score[i][seq2.length - 1];
456  6161 maxi = i;
457  6161 maxj = seq2.length - 1;
458    }
459    }
460   
461  11393 for (int j = 0; j < seq2.length; j++)
462    {
463  11323 if (score[seq1.length - 1][j] > max)
464    {
465  15 max = score[seq1.length - 1][j];
466  15 maxi = seq1.length - 1;
467  15 maxj = j;
468    }
469    }
470   
471  70 int i = maxi;
472  70 int j = maxj;
473  70 int trace;
474  70 maxscore = score[i][j] / 10f;
475   
476  70 seq1end = maxi + 1;
477  70 seq2end = maxj + 1;
478   
479  70 aseq1 = new int[seq1.length + seq2.length];
480  70 aseq2 = new int[seq1.length + seq2.length];
481  70 match = 0;
482  70 StringBuilder sb1 = new StringBuilder(aseq1.length);
483  70 StringBuilder sb2 = new StringBuilder(aseq2.length);
484   
485  70 count = (seq1.length + seq2.length) - 1;
486   
487  8592 while (i > 0 && j > 0)
488    {
489  8522 aseq1[count] = seq1[i];
490  8522 sb1.append(s1str.charAt(i));
491  8522 aseq2[count] = seq2[j];
492  8522 sb2.append(s2str.charAt(j));
493  8522 trace = findTrace(i, j);
494   
495  8522 if (trace == 0)
496    {
497  8519 match++;
498  8519 i--;
499  8519 j--;
500    }
501  3 else if (trace == 1)
502    {
503  0 j--;
504  0 aseq1[count] = GAP_INDEX;
505  0 sb1.replace(sb1.length() - 1, sb1.length(), "-");
506    }
507  3 else if (trace == -1)
508    {
509  3 i--;
510  3 aseq2[count] = GAP_INDEX;
511  3 sb2.replace(sb2.length() - 1, sb2.length(), "-");
512    }
513   
514  8522 count--;
515    }
516   
517  70 seq1start = i + 1;
518  70 seq2start = j + 1;
519   
520  70 if (aseq1[count] != GAP_INDEX)
521    {
522  70 aseq1[count] = seq1[i];
523  70 sb1.append(s1str.charAt(i));
524    }
525   
526  70 if (aseq2[count] != GAP_INDEX)
527    {
528  70 aseq2[count] = seq2[j];
529  70 sb2.append(s2str.charAt(j));
530  70 if (aseq1[count] != GAP_INDEX)
531    {
532  70 match++;
533    }
534    }
535   
536    /*
537    * we built the character strings backwards, so now
538    * reverse them to convert to sequence strings
539    */
540  70 astr1 = sb1.reverse().toString();
541  70 astr2 = sb2.reverse().toString();
542    }
543   
544    /**
545    * DOCUMENT ME!
546    */
 
547  0 toggle public void traceAlignmentWithEndGaps()
548    {
549    // Find the maximum score along the rhs or bottom row
550  0 float max = -Float.MAX_VALUE;
551   
552  0 for (int i = 0; i < seq1.length; i++)
553    {
554  0 if (score[i][seq2.length - 1] > max)
555    {
556  0 max = score[i][seq2.length - 1];
557  0 maxi = i;
558  0 maxj = seq2.length - 1;
559    }
560    }
561   
562  0 for (int j = 0; j < seq2.length; j++)
563    {
564  0 if (score[seq1.length - 1][j] > max)
565    {
566  0 max = score[seq1.length - 1][j];
567  0 maxi = seq1.length - 1;
568  0 maxj = j;
569    }
570    }
571   
572  0 int i = maxi;
573  0 int j = maxj;
574  0 int trace;
575  0 maxscore = score[i][j] / 10f;
576   
577    // prepare trailing gaps
578  0 while ((i < seq1.length - 1) || (j < seq2.length - 1))
579    {
580  0 i++;
581  0 j++;
582    }
583  0 seq1end = i + 1;
584  0 seq2end = j + 1;
585   
586  0 aseq1 = new int[seq1.length + seq2.length];
587  0 aseq2 = new int[seq1.length + seq2.length];
588   
589  0 StringBuilder sb1 = new StringBuilder(aseq1.length);
590  0 StringBuilder sb2 = new StringBuilder(aseq2.length);
591   
592  0 count = (seq1.length + seq2.length) - 1;
593   
594    // get trailing gaps
595  0 while ((i >= seq1.length) || (j >= seq2.length))
596    {
597  0 if (i >= seq1.length)
598    {
599  0 aseq1[count] = GAP_INDEX;
600  0 sb1.append("-");
601  0 aseq2[count] = seq2[j];
602  0 sb2.append(s2str.charAt(j));
603    }
604  0 else if (j >= seq2.length)
605    {
606  0 aseq1[count] = seq1[i];
607  0 sb1.append(s1str.charAt(i));
608  0 aseq2[count] = GAP_INDEX;
609  0 sb2.append("-");
610    }
611  0 i--;
612  0 j--;
613    }
614   
615  0 while (i > 0 && j > 0)
616    {
617  0 aseq1[count] = seq1[i];
618  0 sb1.append(s1str.charAt(i));
619  0 aseq2[count] = seq2[j];
620  0 sb2.append(s2str.charAt(j));
621   
622  0 trace = findTrace(i, j);
623   
624  0 if (trace == 0)
625    {
626  0 i--;
627  0 j--;
628    }
629  0 else if (trace == 1)
630    {
631  0 j--;
632  0 aseq1[count] = GAP_INDEX;
633  0 sb1.replace(sb1.length() - 1, sb1.length(), "-");
634    }
635  0 else if (trace == -1)
636    {
637  0 i--;
638  0 aseq2[count] = GAP_INDEX;
639  0 sb2.replace(sb2.length() - 1, sb2.length(), "-");
640    }
641   
642  0 count--;
643    }
644   
645  0 seq1start = i + 1;
646  0 seq2start = j + 1;
647   
648  0 aseq1[count] = seq1[i];
649  0 sb1.append(s1str.charAt(i));
650  0 aseq2[count] = seq2[j];
651  0 sb2.append(s2str.charAt(j));
652   
653    // get initial gaps
654  0 while (j > 0 || i > 0)
655    {
656  0 if (j > 0)
657    {
658  0 j--;
659  0 sb1.append("-");
660  0 sb2.append(s2str.charAt(j));
661    }
662  0 else if (i > 0)
663    {
664  0 i--;
665  0 sb1.append(s1str.charAt(i));
666  0 sb2.append("-");
667    }
668    }
669    /*
670    * we built the character strings backwards, so now
671    * reverse them to convert to sequence strings
672    */
673  0 astr1 = sb1.reverse().toString();
674  0 astr2 = sb2.reverse().toString();
675    }
676   
677    /**
678    * DOCUMENT ME!
679    */
 
680  34 toggle public void printAlignment(PrintStream os)
681    {
682    // TODO: Use original sequence characters rather than re-translated
683    // characters in output
684    // Find the biggest id length for formatting purposes
685  34 String s1id = getAlignedSeq1().getDisplayId(true);
686  34 String s2id = getAlignedSeq2().getDisplayId(true);
687  34 int nameLength = Math.max(s1id.length(), s2id.length());
688  34 if (nameLength > MAX_NAME_LENGTH)
689    {
690  0 int truncateBy = nameLength - MAX_NAME_LENGTH;
691  0 nameLength = MAX_NAME_LENGTH;
692    // JAL-527 - truncate the sequence ids
693  0 if (s1id.length() > nameLength)
694    {
695  0 int slashPos = s1id.lastIndexOf('/');
696  0 s1id = s1id.substring(0, slashPos - truncateBy)
697    + s1id.substring(slashPos);
698    }
699  0 if (s2id.length() > nameLength)
700    {
701  0 int slashPos = s2id.lastIndexOf('/');
702  0 s2id = s2id.substring(0, slashPos - truncateBy)
703    + s2id.substring(slashPos);
704    }
705    }
706  34 int len = 72 - nameLength - 1;
707  34 int nochunks = ((aseq1.length - count) / len)
708  34 + ((aseq1.length - count) % len > 0 ? 1 : 0);
709  34 float pid = 0f;
710   
711  34 output.append("Score = ").append(score[maxi][maxj]).append(NEWLINE);
712  34 output.append("Length of alignment = ")
713    .append(String.valueOf(aseq1.length - count)).append(NEWLINE);
714  34 output.append("Sequence ");
715  34 Format nameFormat = new Format("%" + nameLength + "s");
716  34 output.append(nameFormat.form(s1id));
717  34 output.append(" (Sequence length = ")
718    .append(String.valueOf(s1str.length())).append(")")
719    .append(NEWLINE);
720  34 output.append("Sequence ");
721  34 output.append(nameFormat.form(s2id));
722  34 output.append(" (Sequence length = ")
723    .append(String.valueOf(s2str.length())).append(")")
724    .append(NEWLINE).append(NEWLINE);
725   
726  34 ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
727   
728  121 for (int j = 0; j < nochunks; j++)
729    {
730    // Print the first aligned sequence
731  87 output.append(nameFormat.form(s1id)).append(" ");
732   
733  4959 for (int i = 0; i < len; i++)
734    {
735  4872 if ((i + (j * len)) < astr1.length())
736    {
737  3489 output.append(astr1.charAt(i + (j * len)));
738    }
739    }
740   
741  87 output.append(NEWLINE);
742  87 output.append(nameFormat.form(" ")).append(" ");
743   
744    /*
745    * Print out the match symbols:
746    * | for exact match (ignoring case)
747    * . if PAM250 score is positive
748    * else a space
749    */
750  4959 for (int i = 0; i < len; i++)
751    {
752  4872 if ((i + (j * len)) < astr1.length())
753    {
754  3489 char c1 = astr1.charAt(i + (j * len));
755  3489 char c2 = astr2.charAt(i + (j * len));
756  3489 boolean sameChar = Comparison.isSameResidue(c1, c2, false);
757  3489 if (sameChar && !Comparison.isGap(c1))
758    {
759  3484 pid++;
760  3484 output.append("|");
761    }
762  5 else if (PEP.equals(type))
763    {
764  5 if (pam250.getPairwiseScore(c1, c2) > 0)
765    {
766  2 output.append(".");
767    }
768    else
769    {
770  3 output.append(" ");
771    }
772    }
773    else
774    {
775  0 output.append(" ");
776    }
777    }
778    }
779   
780    // Now print the second aligned sequence
781  87 output = output.append(NEWLINE);
782  87 output = output.append(nameFormat.form(s2id)).append(" ");
783   
784  4959 for (int i = 0; i < len; i++)
785    {
786  4872 if ((i + (j * len)) < astr2.length())
787    {
788  3489 output.append(astr2.charAt(i + (j * len)));
789    }
790    }
791   
792  87 output.append(NEWLINE).append(NEWLINE);
793    }
794   
795  34 pid = pid / (aseq1.length - count) * 100;
796  34 output.append(new Format("Percentage ID = %3.2f\n").form(pid));
797  34 output.append(NEWLINE);
798  34 try
799    {
800  34 os.print(output.toString());
801    } catch (Exception ex)
802    {
803    }
804    }
805   
806    /**
807    * DOCUMENT ME!
808    *
809    * @param i
810    * DOCUMENT ME!
811    * @param j
812    * DOCUMENT ME!
813    *
814    * @return DOCUMENT ME!
815    */
 
816  2635920 toggle public int findTrace(int i, int j)
817    {
818  2635920 int t = 0;
819  2635920 float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i),
820    s2str.charAt(j));
821  2635920 float max = score[i - 1][j - 1] + (pairwiseScore * 10);
822   
823  2635920 if (F[i][j] > max)
824    {
825  879412 max = F[i][j];
826  879412 t = -1;
827    }
828  1756508 else if (F[i][j] == max)
829    {
830  99804 if (prev == -1)
831    {
832  58899 max = F[i][j];
833  58899 t = -1;
834    }
835    }
836   
837  2635920 if (E[i][j] >= max)
838    {
839  959723 max = E[i][j];
840  959723 t = 1;
841    }
842  1676197 else if (E[i][j] == max)
843    {
844  0 if (prev == 1)
845    {
846  0 max = E[i][j];
847  0 t = 1;
848    }
849    }
850   
851  2635920 prev = t;
852   
853  2635920 return t;
854    }
855   
856    /**
857    * DOCUMENT ME!
858    */
 
859  70 toggle public void calcScoreMatrix()
860    {
861  70 int n = seq1.length;
862  70 int m = seq2.length;
863  70 final int GAP_EX_COST = GAP_EXTEND_COST;
864  70 final int GAP_OP_COST = GAP_OPEN_COST;
865    // top left hand element
866  70 score[0][0] = scoreMatrix.getPairwiseScore(s1str.charAt(0),
867    s2str.charAt(0)) * 10;
868  70 E[0][0] = -GAP_EX_COST;
869  70 F[0][0] = 0;
870   
871    // Calculate the top row first
872  11323 for (int j = 1; j < m; j++)
873    {
874    // What should these values be? 0 maybe
875  11253 E[0][j] = max(score[0][j - 1] - GAP_OP_COST,
876    E[0][j - 1] - GAP_EX_COST);
877  11253 F[0][j] = -GAP_EX_COST;
878   
879  11253 float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(0),
880    s2str.charAt(j));
881  11253 score[0][j] = max(pairwiseScore * 10, -GAP_OP_COST, -GAP_EX_COST);
882   
883  11253 traceback[0][j] = 1;
884    }
885   
886    // Now do the left hand column
887  10338 for (int i = 1; i < n; i++)
888    {
889  10268 E[i][0] = -GAP_OP_COST;
890  10268 F[i][0] = max(score[i - 1][0] - GAP_OP_COST,
891    F[i - 1][0] - GAP_EX_COST);
892   
893  10268 float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i),
894    s2str.charAt(0));
895  10268 score[i][0] = max(pairwiseScore * 10, E[i][0], F[i][0]);
896  10268 traceback[i][0] = -1;
897    }
898   
899    // Now do all the other rows
900  10338 for (int i = 1; i < n; i++)
901    {
902  2637666 for (int j = 1; j < m; j++)
903    {
904  2627398 E[i][j] = max(score[i][j - 1] - GAP_OP_COST,
905    E[i][j - 1] - GAP_EX_COST);
906  2627398 F[i][j] = max(score[i - 1][j] - GAP_OP_COST,
907    F[i - 1][j] - GAP_EX_COST);
908   
909  2627398 float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i),
910    s2str.charAt(j));
911  2627398 score[i][j] = max(score[i - 1][j - 1] + (pairwiseScore * 10),
912    E[i][j], F[i][j]);
913  2627398 traceback[i][j] = findTrace(i, j);
914    }
915    }
916    }
917   
918    /**
919    * Returns the given sequence with all of the given gap characters removed.
920    *
921    * @param gapChars
922    * a string of characters to be treated as gaps
923    * @param seq
924    * the input sequence
925    *
926    * @return
927    */
 
928  2551 toggle public static String extractGaps(String gapChars, String seq)
929    {
930  2551 if (gapChars == null || seq == null)
931    {
932  3 return null;
933    }
934  2548 StringTokenizer str = new StringTokenizer(seq, gapChars);
935  2548 StringBuilder newString = new StringBuilder(seq.length());
936   
937  11867 while (str.hasMoreTokens())
938    {
939  9319 newString.append(str.nextToken());
940    }
941   
942  2548 return newString.toString();
943    }
944   
945    /**
946    * DOCUMENT ME!
947    *
948    * @param f1
949    * DOCUMENT ME!
950    * @param f2
951    * DOCUMENT ME!
952    * @param f3
953    * DOCUMENT ME!
954    *
955    * @return DOCUMENT ME!
956    */
 
957  2648919 toggle private static float max(float f1, float f2, float f3)
958    {
959  2648919 float max = f1;
960   
961  2648919 if (f2 > f1)
962    {
963  876442 max = f2;
964    }
965   
966  2648919 if (f3 > max)
967    {
968  872173 max = f3;
969    }
970   
971  2648919 return max;
972    }
973   
974    /**
975    * DOCUMENT ME!
976    *
977    * @param f1
978    * DOCUMENT ME!
979    * @param f2
980    * DOCUMENT ME!
981    *
982    * @return DOCUMENT ME!
983    */
 
984  5276317 toggle private static float max(float f1, float f2)
985    {
986  5276317 float max = f1;
987   
988  5276317 if (f2 > f1)
989    {
990  2827723 max = f2;
991    }
992   
993  5276317 return max;
994    }
995   
996    /**
997    * Converts the character string to an array of integers which are the
998    * corresponding indices to the characters in the score matrix
999    *
1000    * @param s
1001    *
1002    * @return
1003    */
 
1004  146 toggle int[] indexEncode(String s)
1005    {
1006  146 int[] encoded = new int[s.length()];
1007   
1008  21860 for (int i = 0; i < s.length(); i++)
1009    {
1010  21714 char c = s.charAt(i);
1011  21714 encoded[i] = scoreMatrix.getMatrixIndex(c);
1012    }
1013   
1014  146 return encoded;
1015    }
1016   
1017    /**
1018    * DOCUMENT ME!
1019    *
1020    * @param g
1021    * DOCUMENT ME!
1022    * @param mat
1023    * DOCUMENT ME!
1024    * @param n
1025    * DOCUMENT ME!
1026    * @param m
1027    * DOCUMENT ME!
1028    * @param psize
1029    * DOCUMENT ME!
1030    */
 
1031  0 toggle public static void displayMatrix(Graphics g, int[][] mat, int n, int m,
1032    int psize)
1033    {
1034    // TODO method doesn't seem to be referenced anywhere delete??
1035  0 int max = -1000;
1036  0 int min = 1000;
1037   
1038  0 for (int i = 0; i < n; i++)
1039    {
1040  0 for (int j = 0; j < m; j++)
1041    {
1042  0 if (mat[i][j] >= max)
1043    {
1044  0 max = mat[i][j];
1045    }
1046   
1047  0 if (mat[i][j] <= min)
1048    {
1049  0 min = mat[i][j];
1050    }
1051    }
1052    }
1053   
1054  0 jalview.bin.Console.outPrintln(max + " " + min);
1055   
1056  0 for (int i = 0; i < n; i++)
1057    {
1058  0 for (int j = 0; j < m; j++)
1059    {
1060  0 int x = psize * i;
1061  0 int y = psize * j;
1062   
1063    // jalview.bin.Console.outPrintln(mat[i][j]);
1064  0 float score = (float) (mat[i][j] - min) / (float) (max - min);
1065  0 g.setColor(new Color(score, 0, 0));
1066  0 g.fillRect(x, y, psize, psize);
1067   
1068    // jalview.bin.Console.outPrintln(x + " " + y + " " + score);
1069    }
1070    }
1071    }
1072   
1073    /**
1074    * Compute a globally optimal needleman and wunsch alignment between two
1075    * sequences
1076    *
1077    * @param s1
1078    * @param s2
1079    * @param type
1080    * AlignSeq.DNA or AlignSeq.PEP
1081    */
 
1082  68 toggle public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,
1083    String type)
1084    {
1085  68 return doGlobalNWAlignment(s1, s2, type, DEFAULT_OPENCOST,
1086    DEFAULT_EXTENDCOST);
1087    }
1088   
 
1089  68 toggle public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,
1090    String type, int opencost, int extcost)
1091    {
1092   
1093  68 AlignSeq as = new AlignSeq(s1, s2, type, opencost, extcost);
1094   
1095  68 as.calcScoreMatrix();
1096  68 as.traceAlignment();
1097  68 return as;
1098    }
1099   
1100    /**
1101    *
1102    * @return mapping from positions in S1 to corresponding positions in S2
1103    */
 
1104  61 toggle public jalview.datamodel.Mapping getMappingFromS1(boolean allowmismatch)
1105    {
1106  61 ArrayList<Integer> as1 = new ArrayList<Integer>(),
1107    as2 = new ArrayList<Integer>();
1108  61 int pdbpos = s2.getStart() + getSeq2Start() - 2;
1109  61 int alignpos = s1.getStart() + getSeq1Start() - 2;
1110  61 int lp2 = pdbpos - 3, lp1 = alignpos - 3;
1111  61 boolean lastmatch = false;
1112    // and now trace the alignment onto the atom set.
1113  10251 for (int i = 0; i < astr1.length(); i++)
1114    {
1115  10190 char c1 = astr1.charAt(i), c2 = astr2.charAt(i);
1116  10190 if (c1 != '-')
1117    {
1118  10190 alignpos++;
1119    }
1120   
1121  10190 if (c2 != '-')
1122    {
1123  10190 pdbpos++;
1124    }
1125   
1126    // ignore case differences
1127  10190 if (allowmismatch || (c1 == c2) || (Math.abs(c2 - c1) == ('a' - 'A')))
1128    {
1129    // extend mapping interval
1130  10188 if (lp1 + 1 != alignpos || lp2 + 1 != pdbpos)
1131    {
1132  62 as1.add(Integer.valueOf(alignpos));
1133  62 as2.add(Integer.valueOf(pdbpos));
1134    }
1135  10188 lastmatch = true;
1136  10188 lp1 = alignpos;
1137  10188 lp2 = pdbpos;
1138    }
1139    else
1140    {
1141    // extend mapping interval
1142  2 if (lastmatch)
1143    {
1144  1 as1.add(Integer.valueOf(lp1));
1145  1 as2.add(Integer.valueOf(lp2));
1146    }
1147  2 lastmatch = false;
1148    }
1149    }
1150    // construct range pairs
1151   
1152  61 int[] mapseq1 = new int[as1.size() + (lastmatch ? 1 : 0)],
1153  61 mapseq2 = new int[as2.size() + (lastmatch ? 1 : 0)];
1154  61 int i = 0;
1155  61 for (Integer ip : as1)
1156    {
1157  63 mapseq1[i++] = ip;
1158    }
1159  61 ;
1160  61 i = 0;
1161  61 for (Integer ip : as2)
1162    {
1163  63 mapseq2[i++] = ip;
1164    }
1165  61 ;
1166  61 if (lastmatch)
1167    {
1168  61 mapseq1[mapseq1.length - 1] = alignpos;
1169  61 mapseq2[mapseq2.length - 1] = pdbpos;
1170    }
1171  61 MapList map = new MapList(mapseq1, mapseq2, 1, 1);
1172   
1173  61 jalview.datamodel.Mapping mapping = new Mapping(map);
1174  61 mapping.setTo(s2);
1175  61 return mapping;
1176    }
1177   
1178    /**
1179    * matches ochains against al and populates seqs with the best match between
1180    * each ochain and the set in al
1181    *
1182    * @param ochains
1183    * @param al
1184    * @param dnaOrProtein
1185    * @param removeOldAnnots
1186    * when true, old annotation is cleared before new annotation
1187    * transferred
1188    * @return List<List<SequenceI> originals, List<SequenceI> replacement,
1189    * List<AlignSeq> alignment between each>
1190    */
 
1191  5 toggle public static List<List<? extends Object>> replaceMatchingSeqsWith(
1192    List<SequenceI> seqs, List<AlignmentAnnotation> annotations,
1193    List<SequenceI> ochains, AlignmentI al, String dnaOrProtein,
1194    boolean removeOldAnnots)
1195    {
1196  5 List<SequenceI> orig = new ArrayList<SequenceI>(),
1197    repl = new ArrayList<SequenceI>();
1198  5 List<AlignSeq> aligs = new ArrayList<AlignSeq>();
1199  5 if (al != null && al.getHeight() > 0)
1200    {
1201  5 ArrayList<SequenceI> matches = new ArrayList<SequenceI>();
1202  5 ArrayList<AlignSeq> aligns = new ArrayList<AlignSeq>();
1203   
1204  5 for (SequenceI sq : ochains)
1205    {
1206  14 SequenceI bestm = null;
1207  14 AlignSeq bestaseq = null;
1208  14 float bestscore = 0;
1209  14 for (SequenceI msq : al.getSequences())
1210    {
1211  30 AlignSeq aseq = doGlobalNWAlignment(msq, sq, dnaOrProtein);
1212  30 if (bestm == null || aseq.getMaxScore() > bestscore)
1213    {
1214  14 bestscore = aseq.getMaxScore();
1215  14 bestaseq = aseq;
1216  14 bestm = msq;
1217    }
1218    }
1219    // jalview.bin.Console.outPrintln("Best Score for " + (matches.size() +
1220    // 1) + " :"
1221    // + bestscore);
1222  14 matches.add(bestm);
1223  14 aligns.add(bestaseq);
1224  14 al.deleteSequence(bestm);
1225    }
1226  19 for (int p = 0, pSize = seqs.size(); p < pSize; p++)
1227    {
1228  14 SequenceI sq, sp = seqs.get(p);
1229  14 int q;
1230  ? if ((q = ochains.indexOf(sp)) > -1)
1231    {
1232  14 seqs.set(p, sq = matches.get(q));
1233  14 orig.add(sp);
1234  14 repl.add(sq);
1235  14 sq.setName(sp.getName());
1236  14 sq.setDescription(sp.getDescription());
1237  14 Mapping sp2sq;
1238  14 sq.transferAnnotation(sp,
1239    sp2sq = aligns.get(q).getMappingFromS1(false));
1240  14 aligs.add(aligns.get(q));
1241  14 int inspos = -1;
1242  46 for (int ap = 0; ap < annotations.size();)
1243    {
1244  32 if (annotations.get(ap).sequenceRef == sp)
1245    {
1246  4 if (inspos == -1)
1247    {
1248  4 inspos = ap;
1249    }
1250  4 if (removeOldAnnots)
1251    {
1252  0 annotations.remove(ap);
1253    }
1254    else
1255    {
1256  4 AlignmentAnnotation alan = annotations.remove(ap);
1257  4 alan.liftOver(sq, sp2sq);
1258  4 alan.setSequenceRef(sq);
1259  4 sq.addAlignmentAnnotation(alan);
1260    }
1261    }
1262    else
1263    {
1264  28 ap++;
1265    }
1266    }
1267  14 if (sq.getAnnotation() != null && sq.getAnnotation().length > 0)
1268    {
1269  14 annotations.addAll(inspos == -1 ? annotations.size() : inspos,
1270    Arrays.asList(sq.getAnnotation()));
1271    }
1272    }
1273    }
1274    }
1275  5 return Arrays.asList(orig, repl, aligs);
1276    }
1277   
1278    /**
1279    * compute the PID vector used by the redundancy filter.
1280    *
1281    * @param originalSequences
1282    * - sequences in alignment that are to filtered
1283    * @param omitHidden
1284    * - null or strings to be analysed (typically, visible portion of
1285    * each sequence in alignment)
1286    * @param start
1287    * - first column in window for calculation
1288    * @param end
1289    * - last column in window for calculation
1290    * @param ungapped
1291    * - if true then use ungapped sequence to compute PID
1292    * @return vector containing maximum PID for i-th sequence and any sequences
1293    * longer than that seuqence
1294    */
 
1295  0 toggle public static float[] computeRedundancyMatrix(
1296    SequenceI[] originalSequences, String[] omitHidden, int start,
1297    int end, boolean ungapped)
1298    {
1299  0 int height = originalSequences.length;
1300  0 float[] redundancy = new float[height];
1301  0 int[] lngth = new int[height];
1302  0 for (int i = 0; i < height; i++)
1303    {
1304  0 redundancy[i] = 0f;
1305  0 lngth[i] = -1;
1306    }
1307   
1308    // long start = System.currentTimeMillis();
1309   
1310  0 SimilarityParams pidParams = new SimilarityParams(true, true, true,
1311    true);
1312  0 float pid;
1313  0 String seqi, seqj;
1314  0 for (int i = 0; i < height; i++)
1315    {
1316   
1317  0 for (int j = 0; j < i; j++)
1318    {
1319  0 if (i == j)
1320    {
1321  0 continue;
1322    }
1323   
1324  0 if (omitHidden == null)
1325    {
1326  0 seqi = originalSequences[i].getSequenceAsString(start, end);
1327  0 seqj = originalSequences[j].getSequenceAsString(start, end);
1328    }
1329    else
1330    {
1331  0 seqi = omitHidden[i];
1332  0 seqj = omitHidden[j];
1333    }
1334  0 if (lngth[i] == -1)
1335    {
1336  0 String ug = AlignSeq.extractGaps(Comparison.GapChars, seqi);
1337  0 lngth[i] = ug.length();
1338  0 if (ungapped)
1339    {
1340  0 seqi = ug;
1341    }
1342    }
1343  0 if (lngth[j] == -1)
1344    {
1345  0 String ug = AlignSeq.extractGaps(Comparison.GapChars, seqj);
1346  0 lngth[j] = ug.length();
1347  0 if (ungapped)
1348    {
1349  0 seqj = ug;
1350    }
1351    }
1352  0 pid = (float) PIDModel.computePID(seqi, seqj, pidParams);
1353   
1354    // use real sequence length rather than string length
1355  0 if (lngth[j] < lngth[i])
1356    {
1357  0 redundancy[j] = Math.max(pid, redundancy[j]);
1358    }
1359    else
1360    {
1361  0 redundancy[i] = Math.max(pid, redundancy[i]);
1362    }
1363   
1364    }
1365    }
1366  0 return redundancy;
1367    }
1368   
1369    /**
1370    * calculate the mean score of the alignment mean score is equal to the score
1371    * of an alignmenet of two sequences with randomly shuffled AA sequence
1372    * composited of the same AA as the two original sequences
1373    *
1374    */
 
1375  2 toggle public void meanScore()
1376    {
1377  2 int length = indelfreeAstr1.length(); // both have the same length
1378    // create HashMap for counting residues in each sequence
1379  2 HashMap<Character, Integer> seq1ResCount = new HashMap<Character, Integer>();
1380  2 HashMap<Character, Integer> seq2ResCount = new HashMap<Character, Integer>();
1381   
1382    // for both sequences (String indelfreeAstr1 or 2) create a key for the
1383    // residue and add 1 each time its encountered
1384  2 for (char residue : indelfreeAstr1.toCharArray())
1385    {
1386  8 seq1ResCount.putIfAbsent(residue, 0);
1387  8 seq1ResCount.replace(residue, seq1ResCount.get(residue) + 1);
1388    }
1389  2 for (char residue : indelfreeAstr2.toCharArray())
1390    {
1391  8 seq2ResCount.putIfAbsent(residue, 0);
1392  8 seq2ResCount.replace(residue, seq2ResCount.get(residue) + 1);
1393    }
1394   
1395    // meanscore = for each residue pair get the number of appearance and add
1396    // (countA * countB * pairwiseScore(AB))
1397    // divide the meanscore by the sequence length afterwards
1398  2 float _meanscore = 0;
1399  2 for (char resA : seq1ResCount.keySet())
1400    {
1401  8 for (char resB : seq2ResCount.keySet())
1402    {
1403  32 int countA = seq1ResCount.get(resA);
1404  32 int countB = seq2ResCount.get(resB);
1405   
1406  32 float scoreAB = scoreMatrix.getPairwiseScore(resA, resB);
1407   
1408  32 _meanscore += countA * countB * scoreAB;
1409    }
1410    }
1411  2 _meanscore /= length;
1412  2 this.meanScore = _meanscore;
1413    }
1414   
 
1415  0 toggle public float getMeanScore()
1416    {
1417  0 return this.meanScore;
1418    }
1419   
1420    /**
1421    * calculate the hypothetic max score using the self-alignment of the
1422    * sequences
1423    */
 
1424  2 toggle public void hypotheticMaxScore()
1425    {
1426  2 int _hmsA = 0;
1427  2 int _hmsB = 0;
1428  2 for (char residue : indelfreeAstr1.toCharArray())
1429    {
1430  8 _hmsA += scoreMatrix.getPairwiseScore(residue, residue);
1431    }
1432  2 for (char residue : indelfreeAstr2.toCharArray())
1433    {
1434  8 _hmsB += scoreMatrix.getPairwiseScore(residue, residue);
1435    }
1436  2 this.hypotheticMaxScore = (_hmsA < _hmsB) ? _hmsA : _hmsB; // take the lower
1437    // self alignment
1438   
1439    }
1440   
 
1441  0 toggle public int getHypotheticMaxScore()
1442    {
1443  0 return this.hypotheticMaxScore;
1444    }
1445   
1446    /**
1447    * create strings based of astr1 and astr2 but without gaps
1448    */
 
1449  2 toggle public void getIndelfreeAstr()
1450    {
1451  2 int n = astr1.length(); // both have the same length
1452  10 for (int i = 0; i < n; i++)
1453    {
1454  8 if (Character.isLetter(astr1.charAt(i))
1455    && Character.isLetter(astr2.charAt(i))) // if both sequences dont
1456    // have a gap -> add to
1457    // indelfreeAstr
1458    {
1459  8 this.indelfreeAstr1 += astr1.charAt(i);
1460  8 this.indelfreeAstr2 += astr2.charAt(i);
1461    }
1462    }
1463    }
1464   
1465    /**
1466    * calculates the overall score of the alignment preprescore = sum of all
1467    * scores - all penalties if preprescore < 1 ~ alignmentScore = Float.NaN >
1468    * alignmentScore = ((preprescore - meanScore) / (hypotheticMaxScore -
1469    * meanScore)) * coverage
1470    */
 
1471  2 toggle public void scoreAlignment()
1472    {
1473   
1474  2 getIndelfreeAstr();
1475  2 meanScore();
1476  2 hypotheticMaxScore();
1477    // cannot calculate score because denominator would be zero
1478  2 if (this.hypotheticMaxScore == this.meanScore)
1479    {
1480  0 this.alignmentScore = Float.NaN;
1481  0 return;
1482    }
1483  2 int n = indelfreeAstr1.length();
1484   
1485  2 float score = 0;
1486  2 boolean aGapOpen = false;
1487  2 boolean bGapOpen = false;
1488  10 for (int i = 0; i < n; i++)
1489    {
1490  8 char char1 = indelfreeAstr1.charAt(i);
1491  8 char char2 = indelfreeAstr2.charAt(i);
1492  8 boolean aIsLetter = Character.isLetter(char1);
1493  8 boolean bIsLetter = Character.isLetter(char2);
1494  8 if (aIsLetter && bIsLetter) // if pair -> get score
1495    {
1496  8 score += scoreMatrix.getPairwiseScore(char1, char2);
1497    }
1498  0 else if (!aIsLetter && !bIsLetter)
1499    { // both are gap -> skip
1500    }
1501  0 else if ((!aIsLetter && aGapOpen) || (!bIsLetter && bGapOpen))
1502    { // one side gapopen -> score - gap_extend
1503  0 score -= GAP_EXTEND_COST;
1504    }
1505    else
1506    { // no gap open -> score - gap_open
1507  0 score -= GAP_OPEN_COST;
1508    }
1509    // adjust GapOpen status in both sequences
1510  8 aGapOpen = (!aIsLetter) ? true : false;
1511  8 bGapOpen = (!bIsLetter) ? true : false;
1512    }
1513   
1514  2 float preprescore = score; // if this score < 1 --> alignment score =
1515    // Float.NaN
1516  2 score = (score - this.meanScore)
1517    / (this.hypotheticMaxScore - this.meanScore);
1518  2 int[] _max = MiscMath
1519    .findMax(new int[]
1520    { astr1.replace("-", "").length(),
1521    astr2.replace("-", "").length() }); // {index of max, max}
1522  2 float coverage = (float) n / (float) _max[1]; // indelfreeAstr length /
1523    // longest sequence length
1524  2 float prescore = score; // only debug
1525  2 score *= coverage;
1526   
1527    // System.out.println(String.format("prepre-score: %f, pre-score: %f,
1528    // longlength: %d\nscore: %1.16f, mean: %f, max: %d", preprescore, prescore,
1529    // _max[1], score, this.meanScore, this.hypotheticMaxScore));
1530  2 float minScore = 0f;
1531  2 this.alignmentScore = (score <= minScore) ? Float.NaN : score;
1532    }
1533   
 
1534  0 toggle public void setScoreMatrix(ScoreMatrix sm)
1535    {
1536  0 if (sm != null)
1537    {
1538  0 scoreMatrix = sm;
1539    }
1540    }
1541    }