source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java @ 1620

Last change on this file since 1620 was 1620, checked in by rkrimmel, 10 years ago

More intelligent match finding and creation

File size: 2.5 KB
Line 
1package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.logging.Level;
6
7import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm;
8import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory;
9import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence;
10import de.ugoe.cs.util.console.Console;
11
12public class PairwiseAlignmentGenerator {
13
14        public static PairwiseAlignmentStorage generate(
15                        ArrayList<NumberSequence> numberseqs,
16                        ObjectDistanceSubstitionMatrix submat,
17                        int threshold) {
18                PairwiseAlignmentStorage alignments = new PairwiseAlignmentStorage(
19                                numberseqs.size(), numberseqs.size());
20                int smithWatermanThreshold = threshold;
21
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);
26
27                                if (i != j) {
28                                        Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j);
29                               
30                                        AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create();
31                                        aa.align(ns1, ns2, submat,
32                                                        smithWatermanThreshold);
33                                        alignments.set(i, j, aa);
34
35                                        AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory
36                                                        .create();
37                                        sameSequence1.align(ns1, ns1,
38                                                        submat, smithWatermanThreshold);
39                                        AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory
40                                                        .create();
41                                        sameSequence2.align(ns2, ns2,
42                                                        submat, smithWatermanThreshold);
43                                        AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory
44                                                        .create();
45                                        randomSequence.align(ns1.shuffle(), ns2
46                                                        .shuffle(), submat,
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        }
77}
Note: See TracBrowser for help on using the repository browser.