99import org .biojava .nbio .core .sequence .MultipleSequenceAlignment ;
1010import org .biojava .nbio .core .sequence .template .Compound ;
1111import org .biojava .nbio .core .sequence .template .Sequence ;
12+ import org .biojava .nbio .core .util .ConcurrencyTools ;
1213import org .forester .evoinference .distance .PairwiseDistanceCalculator ;
1314import org .forester .evoinference .matrix .distance .BasicSymmetricalDistanceMatrix ;
1415import org .forester .evoinference .matrix .distance .DistanceMatrix ;
@@ -33,7 +34,8 @@ public class DistanceMatrixCalculator {
3334 .getLogger (DistanceMatrixCalculator .class );
3435
3536 /** Prevent instantiation */
36- private DistanceMatrixCalculator () {}
37+ private DistanceMatrixCalculator () {
38+ }
3739
3840 /**
3941 * The fractional dissimilarity (D) is defined as the percentage of sites
@@ -170,7 +172,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix percent
170172 / totalloopcount );
171173 distance .setIdentifier (i , msa .getAlignedSequence (i + 1 )
172174 .getAccession ().getID ());
173-
175+
174176 for (int j = i ; j < n ; j ++) {
175177 loopcount ++;
176178 if (j == i ) {
@@ -203,7 +205,7 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix percent
203205 * 1], where 0 means that the sequences are identical and 1 that the
204206 * sequences are completely different (similarity score of 0). Note that a
205207 * value higher than one can be obtained, if the similarity score of the
206- * alignment is negative (rare case ).
208+ * alignment is negative (big evolutionary distance ).
207209 * <p>
208210 * Gaps do not have a contribution to the similarity score calculation (gap
209211 * penalty = 0)
@@ -225,16 +227,18 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix fractio
225227 msa .getAlignedSequences (),
226228 PairwiseSequenceScorerType .GLOBAL_SIMILARITIES ,
227229 new SimpleGapPenalty (0 , 0 ), M );
230+
231+ ConcurrencyTools .shutdown ();
228232
229233 // The maximum score that can be obtained for this alignment
230234 int maxScore = M .getMaxValue () * msa .getLength ();
231235
232236 // Convert and copy the dissimilarity scores to the matrix
233237 int indx = 0 ;
234238 for (int i = 0 ; i < n ; i ++) {
235- DM .setIdentifier (i , msa .getAlignedSequence (i + 1 )
236- .getAccession (). getID ());
237-
239+ DM .setIdentifier (i , msa .getAlignedSequence (i + 1 ). getAccession ()
240+ .getID ());
241+
238242 for (int j = i ; j < n ; j ++) {
239243 if (i == j )
240244 DM .setValue (i , j , 0.0 );
@@ -281,6 +285,11 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
281285 logger .info ("{}:{}" , "Determing Distances" , 0 );
282286
283287 int n = msa .getSize ();
288+ String [] sequenceString = new String [n ];
289+ for (int i = 0 ; i < n ; i ++) {
290+ sequenceString [i ] = msa .getAlignedSequence (i + 1 )
291+ .getSequenceAsString ();
292+ }
284293 List <C > seqs = msa .getAlignedSequences ();
285294
286295 DistanceMatrix DM = new BasicSymmetricalDistanceMatrix (n );
@@ -299,12 +308,12 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
299308 double score = 0 ;
300309 loopcount ++;
301310 for (int k = 0 ; k < end ; k ++) {
302- D from = seqs .get (i ).getCompoundAt (k );
303- D to = seqs .get (i ).getCompoundAt (k );
304- if (Comparison .isGap (from .getShortName ().charAt (0 ))
305- || Comparison .isGap (to .getShortName ().charAt (0 )))
311+ if (Comparison .isGap (sequenceString [i ].charAt (k ))
312+ || Comparison .isGap (sequenceString [j ].charAt (k )))
306313 continue ;
307- score += M .getValue (from , to );
314+ // TODO bug
315+ score += M .getValue (seqs .get (i ).getCompoundAt (k ),
316+ seqs .get (j ).getCompoundAt (k ));
308317 }
309318 DM .setValue (i , j , score );
310319
@@ -315,9 +324,9 @@ public static <C extends Sequence<D>, D extends Compound> DistanceMatrix dissimi
315324 }
316325
317326 for (int i = 0 ; i < n ; i ++) {
318- DM .setIdentifier (i , msa .getAlignedSequence (i + 1 )
319- .getAccession (). getID ());
320-
327+ DM .setIdentifier (i , msa .getAlignedSequence (i + 1 ). getAccession ()
328+ .getID ());
329+
321330 for (int j = i ; j < n ; j ++) {
322331 if (i == j )
323332 DM .setValue (i , j , 0.0 );
0 commit comments