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

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

Small fixes to the new method

File size: 3.0 KB
Line 
1package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
2
3import java.util.ArrayList;
4import java.util.Iterator;
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;
9
10public class PairwiseAlignmentGenerator {
11
12
13        public static PairwiseAlignmentStorage generate(ArrayList<NumberSequence> numberseqs,ObjectDistanceSubstitionMatrix submat) {
14                PairwiseAlignmentStorage alignments = new PairwiseAlignmentStorage(numberseqs.size(),numberseqs.size());
15               
16                for (int i = 0; i < numberseqs.size(); i++) {
17                        NumberSequence ns1 = numberseqs.get(i);
18                        for (int j = 0; j < numberseqs.size(); j++) {
19                                NumberSequence ns2 = numberseqs.get(j);
20
21                                if (i != j) {
22                                        int smithWatermanThreshold = 10;
23
24                                        alignments.set(i, j,AlignmentAlgorithmFactory.create(
25                                                        ns1.getSequence(), ns2.getSequence(), submat,
26                                                        smithWatermanThreshold));
27                                       
28                                        AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create(
29                                                        ns1.getSequence(), ns1.getSequence(), submat,
30                                                        smithWatermanThreshold);
31                                        AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create(
32                                                        ns2.getSequence(), ns2.getSequence(), submat,
33                                                        smithWatermanThreshold);
34                                        AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create(
35                                                        ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold);
36                                       
37                                        // Score of the aligmnment
38                                        double score = alignments.get(i,j).getAlignmentScore();
39                                        if(score > 0) {
40                                                System.out.println();
41                                                //alignments.get(i, j).printAlignment();
42                                                ArrayList<ArrayList<NumberSequence>> matches = alignments.get(i, j).getMatches();
43                                                int count = 0;
44                                                for(Iterator<ArrayList<NumberSequence>> it = matches.iterator();it.hasNext();) {
45                                                        System.out.println("Match number" + count);
46                                                        ArrayList<NumberSequence> tmp = it.next();
47                                                        tmp.get(0).printSequence();
48                                                        tmp.get(1).printSequence();
49                                                        System.out.println();
50                                                        count++;
51                                                }
52                                                System.out.println();
53                                        }
54                                        // Scores of the sequence being aligned to itself (maximum 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                                       
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                return alignments;     
77    }
78}
Note: See TracBrowser for help on using the repository browser.