[1589] | 1 | package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; |
---|
| 2 | |
---|
| 3 | import java.util.ArrayList; |
---|
[1592] | 4 | import java.util.Iterator; |
---|
[1589] | 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 | |
---|
| 24 | alignments.set(i, j,AlignmentAlgorithmFactory.create( |
---|
| 25 | ns1.getSequence(), ns2.getSequence(), submat, |
---|
| 26 | smithWatermanThreshold)); |
---|
| 27 | |
---|
| 28 | AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create( |
---|
| 29 | ns1.getSequence(), ns1.getSequence(), submat, |
---|
| 30 | smithWatermanThreshold); |
---|
| 31 | AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create( |
---|
| 32 | ns2.getSequence(), ns2.getSequence(), submat, |
---|
| 33 | smithWatermanThreshold); |
---|
| 34 | AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create( |
---|
| 35 | ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold); |
---|
| 36 | |
---|
| 37 | // Score of the aligmnment |
---|
| 38 | double score = alignments.get(i,j).getAlignmentScore(); |
---|
| 39 | if(score > 0) { |
---|
| 40 | System.out.println(); |
---|
[1592] | 41 | //alignments.get(i, j).printAlignment(); |
---|
| 42 | ArrayList<ArrayList<NumberSequence>> matches = alignments.get(i, j).getMatches(); |
---|
| 43 | for(Iterator<ArrayList<NumberSequence>> it = matches.iterator();it.hasNext();) { |
---|
| 44 | ArrayList<NumberSequence> tmp = it.next(); |
---|
| 45 | tmp.get(0).printSequence(); |
---|
| 46 | tmp.get(1).printSequence(); |
---|
| 47 | } |
---|
[1589] | 48 | System.out.println(); |
---|
| 49 | } |
---|
| 50 | // Scores of the sequence being aligned to itself (maximum score) |
---|
| 51 | double sSelf1 = sameSequence1.getAlignmentScore(); |
---|
| 52 | double sSelf2 = sameSequence2.getAlignmentScore(); |
---|
| 53 | // Score of sequences shuffled before aligned |
---|
| 54 | double sRand = randomSequence.getAlignmentScore(); |
---|
| 55 | |
---|
| 56 | double sMax = (sSelf1 + sSelf2) / 2; |
---|
| 57 | double sEff = (score - sRand)/ (sMax - sRand); |
---|
| 58 | if(sEff < 0) { |
---|
| 59 | sEff = 0; |
---|
| 60 | } |
---|
| 61 | double distance = -Math.log(sEff); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | if(!Double.isInfinite(distance) && !Double.isNaN(distance)) { |
---|
| 65 | if(distance < alignments.getDistance(i, j)) { |
---|
| 66 | alignments.setDistance(i,j,distance ); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | return alignments; |
---|
| 73 | } |
---|
| 74 | } |
---|