source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java @ 1655

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

Commit before making dramatic changes. (Not really)

File size: 2.6 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                                        //TODO: This is old code used for generating pairwise distances between alignments (to build
34                                        // a guide tree
35                                        /*
36                                        AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory
37                                                        .create();
38                                        sameSequence1.align(ns1, ns1,
39                                                        submat, smithWatermanThreshold);
40                                        AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory
41                                                        .create();
42                                        sameSequence2.align(ns2, ns2,
43                                                        submat, smithWatermanThreshold);
44                                        AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory
45                                                        .create();
46                                        randomSequence.align(ns1.shuffle(), ns2
47                                                        .shuffle(), submat,
48                                                        smithWatermanThreshold);
49                                       
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                                        }
73                                        */
74                                }
75                        }
76                }
77                return alignments;
78        }
79}
Note: See TracBrowser for help on using the repository browser.