1 | package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.Iterator; |
---|
5 | import java.util.logging.Level; |
---|
6 | |
---|
7 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; |
---|
8 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; |
---|
9 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; |
---|
10 | import de.ugoe.cs.util.console.Console; |
---|
11 | |
---|
12 | public class PairwiseAlignmentGenerator { |
---|
13 | |
---|
14 | public static PairwiseAlignmentStorage generate( |
---|
15 | ArrayList<NumberSequence> numberseqs, |
---|
16 | ObjectDistanceSubstitionMatrix submat) { |
---|
17 | PairwiseAlignmentStorage alignments = new PairwiseAlignmentStorage( |
---|
18 | numberseqs.size(), numberseqs.size()); |
---|
19 | |
---|
20 | for (int i = 0; i < numberseqs.size(); i++) { |
---|
21 | NumberSequence ns1 = numberseqs.get(i); |
---|
22 | for (int j = 0; j < numberseqs.size(); j++) { |
---|
23 | NumberSequence ns2 = numberseqs.get(j); |
---|
24 | |
---|
25 | if (i != j) { |
---|
26 | Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); |
---|
27 | int smithWatermanThreshold = 10; |
---|
28 | AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); |
---|
29 | aa.align(ns1.getSequence(), ns2.getSequence(), submat, |
---|
30 | smithWatermanThreshold); |
---|
31 | alignments.set(i, j, aa); |
---|
32 | |
---|
33 | AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory |
---|
34 | .create(); |
---|
35 | sameSequence1.align(ns1.getSequence(), ns1.getSequence(), |
---|
36 | submat, smithWatermanThreshold); |
---|
37 | AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory |
---|
38 | .create(); |
---|
39 | sameSequence2.align(ns2.getSequence(), ns2.getSequence(), |
---|
40 | submat, smithWatermanThreshold); |
---|
41 | AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory |
---|
42 | .create(); |
---|
43 | randomSequence.align(ns1.shuffle().getSequence(), ns2 |
---|
44 | .shuffle().getSequence(), submat, |
---|
45 | smithWatermanThreshold); |
---|
46 | |
---|
47 | // Score of the aligmnment |
---|
48 | double score = alignments.get(i, j).getAlignmentScore(); |
---|
49 | |
---|
50 | |
---|
51 | // Scores of the sequence being aligned to itself (maximum |
---|
52 | // score) |
---|
53 | double sSelf1 = sameSequence1.getAlignmentScore(); |
---|
54 | double sSelf2 = sameSequence2.getAlignmentScore(); |
---|
55 | // Score of sequences shuffled before aligned |
---|
56 | double sRand = randomSequence.getAlignmentScore(); |
---|
57 | |
---|
58 | double sMax = (sSelf1 + sSelf2) / 2; |
---|
59 | double sEff = (score - sRand) / (sMax - sRand); |
---|
60 | if (sEff < 0) { |
---|
61 | sEff = 0; |
---|
62 | } |
---|
63 | double distance = -Math.log(sEff); |
---|
64 | |
---|
65 | if (!Double.isInfinite(distance) && !Double.isNaN(distance)) { |
---|
66 | if (distance < alignments.getDistance(i, j)) { |
---|
67 | alignments.setDistance(i, j, distance); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | return alignments; |
---|
74 | } |
---|
75 | } |
---|