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

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

Generated Model of matches.

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