X Tutup
Skip to content

Commit fea2b4c

Browse files
committed
Fix bug with the ConcurrencyTools usage
1 parent 58adbd2 commit fea2b4c

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

biojava-phylo/src/main/java/demo/DemoDistanceTree.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.InputStream;
44
import java.util.LinkedHashMap;
55

6+
import org.biojava.nbio.core.alignment.matrices.SubstitutionMatrixHelper;
7+
import org.biojava.nbio.core.alignment.template.SubstitutionMatrix;
68
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
79
import org.biojava.nbio.core.sequence.ProteinSequence;
810
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
@@ -54,8 +56,9 @@ public static void main(String[] args) throws Exception {
5456

5557
long readT = System.currentTimeMillis();
5658

57-
// 1. Calculate the evolutionary distance matrix
58-
DistanceMatrix DM = DistanceMatrixCalculator.kimuraDistance(msa);
59+
// 1. Calculate the evolutionary distance matrix (can take long)
60+
SubstitutionMatrix<AminoAcidCompound> M = SubstitutionMatrixHelper.getBlosum62();
61+
DistanceMatrix DM = DistanceMatrixCalculator.fractionalDissimilarityScore(msa, M);
5962

6063
// 2. Construct a distance tree using the NJ algorithm
6164
Phylogeny phylo = TreeConstructor.distanceTree(

biojava-phylo/src/main/java/org/biojava/nbio/phylo/DistanceMatrixCalculator.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
1010
import org.biojava.nbio.core.sequence.template.Compound;
1111
import org.biojava.nbio.core.sequence.template.Sequence;
12+
import org.biojava.nbio.core.util.ConcurrencyTools;
1213
import org.forester.evoinference.distance.PairwiseDistanceCalculator;
1314
import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
1415
import 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

Comments
 (0)
X Tutup