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