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