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