Clover icon

Coverage Report

  1. Project Clover database Tue Nov 4 2025 11:21:43 GMT
  2. Package jalview.analysis

File AlignSeq.java

 

Coverage histogram

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

Code metrics

222
516
46
1
1,555
1,026
180
0.35
11.22
46
3.91

Classes

Class Line # Actions
AlignSeq 54 516 180
0.653061265.3%
 

Contributing tests

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