Changeset 1612 for branches/ralph
- Timestamp:
- 07/14/14 23:27:01 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/AlignmentAlgorithm.java
r1592 r1612 3 3 import java.util.ArrayList; 4 4 5 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.SubstitutionMatrix; 6 5 7 public interface AlignmentAlgorithm { 6 8 9 public abstract void align(int[] input1, int[] input2, SubstitutionMatrix submat,float threshold); 10 7 11 /** 8 12 * Get the alignment score between the two input strings. -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/AlignmentAlgorithmFactory.java
r1589 r1612 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; 2 3 import java.lang.reflect.Constructor; 4 import java.lang.reflect.InvocationTargetException; 2 5 3 6 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.SubstitutionMatrix; … … 5 8 public class AlignmentAlgorithmFactory { 6 9 10 public static void setDefaultAlgorithm(String algorithmname) { 11 //TODO: check for valid algorihm class names here 12 algorithmclass = algorithmname; 13 } 7 14 8 public static AlignmentAlgorithm create(int[] input1, int[] input2, SubstitutionMatrix submat,float threshold) { 9 15 private static String algorithmclass = "de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated"; 16 17 18 19 public static AlignmentAlgorithm create() { 20 Class<?> newclass; 21 Object object = null; 22 try { 23 newclass = Class.forName(algorithmclass); 24 object = newclass.newInstance(); 25 26 } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException e) { 27 // TODO Auto-generated catch block 28 e.printStackTrace(); 29 } 10 30 //return new SmithWaterman(input1,input2,submat,threshold); 11 31 //return new NeedlemanWunsch(input1,input2,submat,threshold); 12 return new SmithWatermanRepeated(input1,input2,submat,threshold); 32 //return new SmithWatermanRepeated(input1,input2,submat,threshold); 33 return (AlignmentAlgorithm) object; 13 34 } 14 35 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NeedlemanWunsch.java
r1592 r1612 39 39 private SubstitutionMatrix submat; 40 40 41 public NeedlemanWunsch(int[] input1, int[] input2, SubstitutionMatrix submat,42 float threshold) {43 this.input1 = input1;44 this.input2 = input2;45 length1 = input1.length;46 length2 = input2.length;47 this.submat = submat;48 49 // System.out.println("Starting SmithWaterman algorithm with a "50 // + submat.getClass() + " Substitution Matrix: " +51 // submat.getClass().getCanonicalName());52 53 matrix = new MatrixEntry[length1 + 1][length2 + 1];54 alignment = new ArrayList<NumberSequence>();55 56 for (int i = 0; i < length1+1; i++) {57 for (int j = 0; j < length2+1; j++) {58 matrix[i][j] = new MatrixEntry();59 }60 }61 62 buildMatrix();63 traceback();64 }65 41 66 42 /** … … 289 265 } 290 266 267 @Override 268 public void align(int[] input1, int[] input2, SubstitutionMatrix submat, 269 float threshold) { 270 this.input1 = input1; 271 this.input2 = input2; 272 length1 = input1.length; 273 length2 = input2.length; 274 this.submat = submat; 275 276 // System.out.println("Starting SmithWaterman algorithm with a " 277 // + submat.getClass() + " Substitution Matrix: " + 278 // submat.getClass().getCanonicalName()); 279 280 matrix = new MatrixEntry[length1 + 1][length2 + 1]; 281 alignment = new ArrayList<NumberSequence>(); 282 283 for (int i = 0; i < length1+1; i++) { 284 for (int j = 0; j < length2+1; j++) { 285 matrix[i][j] = new MatrixEntry(); 286 } 287 } 288 289 buildMatrix(); 290 traceback(); 291 292 } 293 291 294 292 295 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWaterman.java
r1592 r1612 38 38 private SubstitutionMatrix submat; 39 39 40 public SmithWaterman(int[] input1, int[] input2, SubstitutionMatrix submat,41 float threshold) {42 this.input1 = input1;43 this.input2 = input2;44 length1 = input1.length;45 length2 = input2.length;46 this.submat = submat;47 48 // System.out.println("Starting SmithWaterman algorithm with a "49 // + submat.getClass() + " Substitution Matrix: " +50 // submat.getClass().getCanonicalName());51 52 matrix = new MatrixEntry[length1 + 1][length2 + 1];53 alignment = new ArrayList<NumberSequence>();54 55 for (int i = 0; i < length1+1; i++) {56 for (int j = 0; j < length2+1; j++) {57 matrix[i][j] = new MatrixEntry();58 }59 }60 61 buildMatrix();62 traceback();63 }64 40 65 41 /** … … 294 270 } 295 271 272 @Override 273 public void align(int[] input1, int[] input2, SubstitutionMatrix submat, 274 float threshold) { 275 this.input1 = input1; 276 this.input2 = input2; 277 length1 = input1.length; 278 length2 = input2.length; 279 this.submat = submat; 280 281 // System.out.println("Starting SmithWaterman algorithm with a " 282 // + submat.getClass() + " Substitution Matrix: " + 283 // submat.getClass().getCanonicalName()); 284 285 matrix = new MatrixEntry[length1 + 1][length2 + 1]; 286 alignment = new ArrayList<NumberSequence>(); 287 288 for (int i = 0; i < length1+1; i++) { 289 for (int j = 0; j < length2+1; j++) { 290 matrix[i][j] = new MatrixEntry(); 291 } 292 } 293 294 buildMatrix(); 295 traceback(); 296 297 } 298 296 299 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1596 r1612 43 43 private SubstitutionMatrix submat; 44 44 45 public SmithWatermanRepeated(int[] input1, int[] input2, SubstitutionMatrix submat,float threshold) { 46 this.input1 = input1; 47 this.input2 = input2; 48 length1 = input1.length; 49 length2 = input2.length; 50 this.submat = submat; 51 52 //System.out.println("Starting SmithWaterman algorithm with a " 53 // + submat.getClass() + " Substitution Matrix: " + submat.getClass().getCanonicalName()); 54 this.scoreThreshold = threshold; 55 56 matrix = new MatrixEntry[length1+2][length2+1]; 57 alignment = new ArrayList<NumberSequence>(); 58 59 for (int i = 0; i <= length1+1; i++) { 60 for(int j = 0; j< length2; j++) { 61 matrix[i][j] = new MatrixEntry(); 62 } 63 } 64 65 66 buildMatrix(); 67 traceback(); 45 public SmithWatermanRepeated() { 46 68 47 } 69 48 … … 374 353 } 375 354 355 @Override 356 public void align(int[] input1, int[] input2, SubstitutionMatrix submat, 357 float threshold) { 358 this.input1 = input1; 359 this.input2 = input2; 360 length1 = input1.length; 361 length2 = input2.length; 362 this.submat = submat; 363 364 //System.out.println("Starting SmithWaterman algorithm with a " 365 // + submat.getClass() + " Substitution Matrix: " + submat.getClass().getCanonicalName()); 366 this.scoreThreshold = threshold; 367 368 matrix = new MatrixEntry[length1+2][length2+1]; 369 alignment = new ArrayList<NumberSequence>(); 370 371 for (int i = 0; i <= length1+1; i++) { 372 for(int j = 0; j< length2; j++) { 373 matrix[i][j] = new MatrixEntry(); 374 } 375 } 376 377 378 buildMatrix(); 379 traceback(); 380 } 381 376 382 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java
r1595 r1612 21 21 if (i != j) { 22 22 int smithWatermanThreshold = 10; 23 24 alignments.set(i, j,AlignmentAlgorithmFactory.create( 25 ns1.getSequence(), ns2.getSequence(), submat, 26 smithWatermanThreshold)); 23 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 24 aa.align(ns1.getSequence(), ns2.getSequence(), submat, 25 smithWatermanThreshold); 26 alignments.set(i,j,aa); 27 27 28 28 AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create( 29 AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create(); 30 sameSequence1.align( 29 31 ns1.getSequence(), ns1.getSequence(), submat, 30 32 smithWatermanThreshold); 31 AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create( 32 ns2.getSequence(), ns2.getSequence(), submat,33 AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create(); 34 sameSequence2.align(ns2.getSequence(), ns2.getSequence(), submat, 33 35 smithWatermanThreshold); 34 AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create( 35 ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold);36 AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create(); 37 randomSequence.align(ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold); 36 38 37 39 // Score of the aligmnment 38 40 double score = alignments.get(i,j).getAlignmentScore(); 41 /* 39 42 if(score > 0) { 40 43 System.out.println("Alignment: " + i + " " + j); … … 52 55 System.out.println(); 53 56 } 57 */ 54 58 // Scores of the sequence being aligned to itself (maximum score) 55 59 double sSelf1 = sameSequence1.getAlignmentScore(); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java
r1589 r1612 18 18 import java.util.logging.Level; 19 19 20 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 20 21 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 21 22 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; … … 221 222 //Align 2 sequences 222 223 if(seqCount1 == 1 && seqCount2 == 1) { 223 alignment = (alignments.get(node1.getNumber(), node2.getNumber())).getAlignment(); 224 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 225 aa.align(node1.getSequence(0).getSequence(), node2.getSequence(0).getSequence(), submat, 5); 226 alignment = aa.getAlignment(); 224 227 225 228 } … … 231 234 double maxScore = 0.0; 232 235 int maxIndex = 0; 233 for(int i=0;i<seqCount1;i++) { 234 tempStorage.set(i, 1, AlignmentAlgorithmFactory.create(node1.getSequence(i).getSequence(), node2.getSequence(0).getSequence() , submat, 5)); 236 for(int i=0;i<seqCount1;i++){ 237 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 238 aa.align(node1.getSequence(i).getSequence(), node2.getSequence(0).getSequence() , submat, 5); 239 tempStorage.set(i, 1, aa); 240 235 241 if(maxScore < tempStorage.get(i, 1).getAlignmentScore()) { 236 242 maxScore = tempStorage.get(i, 1).getAlignmentScore(); … … 249 255 int maxIndex = 0; 250 256 for(int i=0;i<seqCount2;i++) { 251 tempStorage.set(1, i, AlignmentAlgorithmFactory.create(node2.getSequence(i).getSequence(), node1.getSequence(0).getSequence() , submat, 5)); 257 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 258 aa.align(node2.getSequence(i).getSequence(), node1.getSequence(0).getSequence() , submat, 5); 259 tempStorage.set(1, i, aa); 252 260 if(maxScore < tempStorage.get(1, i).getAlignmentScore()) { 253 261 maxScore = tempStorage.get(1, i).getAlignmentScore(); … … 269 277 for(int i=0;i<seqCount1;i++) { 270 278 for(int j=0;j<seqCount2;j++) { 271 tempStorage1.set(j, 0, AlignmentAlgorithmFactory.create(node1.getSequence(i).getSequence(), node2.getSequence(j).getSequence() , submat, 5)); 279 AlignmentAlgorithm aa =AlignmentAlgorithmFactory.create(); 280 aa.align(node1.getSequence(i).getSequence(), node2.getSequence(j).getSequence() , submat, 5); 281 tempStorage1.set(j, 0, aa); 272 282 if(maxScore1 < tempStorage1.get(j, 0).getAlignmentScore()) { 273 283 maxScore1 = tempStorage1.get(j, 0).getAlignmentScore(); … … 280 290 for(int i=0; i<seqCount2;i++) { 281 291 for (int j=0;j<seqCount1;j++) { 282 tempStorage2.set(j, 0, AlignmentAlgorithmFactory.create(node2.getSequence(i).getSequence(),node1.getSequence(j).getSequence(),submat,5)); 292 AlignmentAlgorithm aa =AlignmentAlgorithmFactory.create(); 293 aa.align(node2.getSequence(i).getSequence(),node1.getSequence(j).getSequence(),submat,5); 294 tempStorage2.set(j, 0, aa); 283 295 if(maxScore2 < tempStorage2.get(j, 0).getAlignmentScore()) { 284 296 maxScore2 = tempStorage2.get(j, 0).getAlignmentScore(); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1595 r1612 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 18 17 import java.util.ArrayList; 19 18 import java.util.HashMap; … … 26 25 import java.util.logging.Level; 27 26 28 27 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 29 28 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 30 29 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator; … … 62 61 * </p> 63 62 * <p> 64 63 * 65 64 * 66 65 * @author Patrick Harms … … 158 157 submat.generate(); 159 158 159 ArrayList<NumberSequence> matchseqs = new ArrayList<NumberSequence>(); 160 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat); 160 161 161 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat); 162 163 162 for (int i=0; i< numberseqs.size();i++) { 163 for(int j=0; j< numberseqs.size();j++) { 164 if(i != j) { 165 ArrayList<ArrayList<NumberSequence>> tmp = alignments.get(i, j).getMatches(); 166 for(Iterator<ArrayList<NumberSequence>> it = tmp.iterator();it.hasNext();) { 167 matchseqs.addAll(it.next()); 168 } 169 } 170 } 171 } 172 AlignmentAlgorithmFactory.setDefaultAlgorithm("de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NeedlemanWunsch"); 173 PairwiseAlignmentStorage matchAlignments = PairwiseAlignmentGenerator.generate(numberseqs, submat); 174 UPGMAAligningTree guidetree = new UPGMAAligningTree(matchseqs,matchAlignments,submat); 164 175 System.out.println(alignments.getDistanceMatrix()); 165 176 //UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat); 166 177 167 178 for(Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator();it.hasNext();) { 179 NumberSequence tmp = (NumberSequence) it.next(); 180 tmp.printSequence(); 181 } 168 182 169 183
Note: See TracChangeset
for help on using the changeset viewer.