Changeset 1617
- Timestamp:
- 07/16/14 11:02:17 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java
r1612 r1617 10 10 public class PairwiseAlignmentGenerator { 11 11 12 public static PairwiseAlignmentStorage generate( 13 ArrayList<NumberSequence> numberseqs, 14 ObjectDistanceSubstitionMatrix submat) { 15 PairwiseAlignmentStorage alignments = new PairwiseAlignmentStorage( 16 numberseqs.size(), numberseqs.size()); 12 17 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); 18 for (int i = 0; i < numberseqs.size(); i++) { 19 NumberSequence ns1 = numberseqs.get(i); 20 for (int j = 0; j < numberseqs.size(); j++) { 21 NumberSequence ns2 = numberseqs.get(j); 20 22 21 if (i != j) { 22 int smithWatermanThreshold = 10; 23 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 24 aa.align(ns1.getSequence(), ns2.getSequence(), submat, 25 smithWatermanThreshold); 26 alignments.set(i,j,aa); 27 28 29 AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create(); 30 sameSequence1.align( 31 ns1.getSequence(), ns1.getSequence(), submat, 32 smithWatermanThreshold); 33 AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create(); 34 sameSequence2.align(ns2.getSequence(), ns2.getSequence(), submat, 35 smithWatermanThreshold); 36 AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create(); 37 randomSequence.align(ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold); 38 39 // Score of the aligmnment 40 double score = alignments.get(i,j).getAlignmentScore(); 41 /* 42 if(score > 0) { 43 System.out.println("Alignment: " + i + " " + j); 44 alignments.get(i, j).printAlignment(); 45 ArrayList<ArrayList<NumberSequence>> matches = alignments.get(i, j).getMatches(); 46 int count = 0; 47 for(Iterator<ArrayList<NumberSequence>> it = matches.iterator();it.hasNext();) { 48 System.out.println("Match number " + count); 49 ArrayList<NumberSequence> tmp = it.next(); 50 tmp.get(0).printSequence(); 51 tmp.get(1).printSequence(); 52 System.out.println(); 53 count++; 54 } 55 System.out.println(); 56 } 57 */ 58 // Scores of the sequence being aligned to itself (maximum score) 59 double sSelf1 = sameSequence1.getAlignmentScore(); 60 double sSelf2 = sameSequence2.getAlignmentScore(); 61 // Score of sequences shuffled before aligned 62 double sRand = randomSequence.getAlignmentScore(); 23 if (i != j) { 24 int smithWatermanThreshold = 10; 25 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 26 aa.align(ns1.getSequence(), ns2.getSequence(), submat, 27 smithWatermanThreshold); 28 alignments.set(i, j, aa); 63 29 64 double sMax = (sSelf1 + sSelf2) / 2; 65 double sEff = (score - sRand)/ (sMax - sRand); 66 if(sEff < 0) { 67 sEff = 0; 68 } 69 double distance = -Math.log(sEff); 70 71 72 if(!Double.isInfinite(distance) && !Double.isNaN(distance)) { 73 if(distance < alignments.getDistance(i, j)) { 74 alignments.setDistance(i,j,distance ); 75 } 76 } 77 } 78 } 79 } 80 return alignments; 81 } 30 AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory 31 .create(); 32 sameSequence1.align(ns1.getSequence(), ns1.getSequence(), 33 submat, smithWatermanThreshold); 34 AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory 35 .create(); 36 sameSequence2.align(ns2.getSequence(), ns2.getSequence(), 37 submat, smithWatermanThreshold); 38 AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory 39 .create(); 40 randomSequence.align(ns1.shuffle().getSequence(), ns2 41 .shuffle().getSequence(), submat, 42 smithWatermanThreshold); 43 44 // Score of the aligmnment 45 double score = alignments.get(i, j).getAlignmentScore(); 46 47 48 // Scores of the sequence being aligned to itself (maximum 49 // score) 50 double sSelf1 = sameSequence1.getAlignmentScore(); 51 double sSelf2 = sameSequence2.getAlignmentScore(); 52 // Score of sequences shuffled before aligned 53 double sRand = randomSequence.getAlignmentScore(); 54 55 double sMax = (sSelf1 + sSelf2) / 2; 56 double sEff = (score - sRand) / (sMax - sRand); 57 if (sEff < 0) { 58 sEff = 0; 59 } 60 double distance = -Math.log(sEff); 61 62 if (!Double.isInfinite(distance) && !Double.isNaN(distance)) { 63 if (distance < alignments.getDistance(i, j)) { 64 alignments.setDistance(i, j, distance); 65 } 66 } 67 } 68 } 69 } 70 return alignments; 71 } 82 72 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1615 r1617 164 164 if(i != j) { 165 165 ArrayList<ArrayList<NumberSequence>> tmp = alignments.get(i, j).getMatches(); 166 int count = 0; 166 167 for(Iterator<ArrayList<NumberSequence>> it = tmp.iterator();it.hasNext();) { 167 matchseqs.addAll(it.next()); 168 System.out.println("Match number " + count); 169 ArrayList<NumberSequence> tmp2 = it.next(); 170 tmp2.get(0).printSequence(); 171 tmp2.get(1).printSequence(); 172 System.out.println(); 173 count++; 174 matchseqs.addAll(tmp2); 168 175 } 176 System.out.println(); 169 177 } 170 178 }
Note: See TracChangeset
for help on using the changeset viewer.