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