Changeset 1589 for branches/ralph
- Timestamp:
- 07/09/14 12:13:13 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 1 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/AlignmentAlgorithmFactory.java
r1588 r1589 9 9 10 10 //return new SmithWaterman(input1,input2,submat,threshold); 11 return new NeedlemanWunsch(input1,input2,submat,threshold);12 //return new SmithWatermanRepeated(input1,input2,submat,threshold);11 //return new NeedlemanWunsch(input1,input2,submat,threshold); 12 return new SmithWatermanRepeated(input1,input2,submat,threshold); 13 13 } 14 14 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1587 r1589 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.LinkedList; 4 6 import java.util.logging.Level; 5 7 … … 216 218 } 217 219 218 219 220 220 public void traceback() { 221 221 MatrixEntry tmp = matrix[length1+1][0]; 222 int aligned1[] = new int[length1+1+length2+2]; 223 int aligned2[] = new int[length1+1+length2+2]; 222 LinkedList<Integer> aligned1 = new LinkedList<Integer>(); 223 LinkedList<Integer> aligned2 = new LinkedList<Integer>(); 224 do { 225 226 aligned1.add(new Integer(tmp.getXvalue())); 227 aligned2.add(new Integer(tmp.getYvalue())); 228 229 tmp = tmp.getPrevious(); 230 231 } while (tmp != null); 232 233 // reverse order of the alignment 234 int reversed1[] = new int[aligned1.size()]; 235 int reversed2[] = new int[aligned2.size()]; 236 224 237 int count = 0; 225 do 226 { 227 if(count != 0) 228 { 229 if (length1+1+length2+2 == count) { 230 Console.traceln(Level.WARNING, "Traceback longer than both sequences summed up!"); 231 break; 232 } 233 aligned1[count] = tmp.getXvalue(); 234 aligned2[count] = tmp.getYvalue(); 235 } 236 237 tmp = tmp.getPrevious(); 238 for (Iterator<Integer> it = aligned1.descendingIterator(); it.hasNext();) { 238 239 count++; 239 240 } while(tmp != null); 241 count--; 242 //reverse order of the alignment 243 int reversed1[] = new int[count]; 244 int reversed2[] = new int[count]; 245 246 247 for(int i = count-1; i > 0; i--) { 248 reversed1[reversed1.length-i]= aligned1[i]; 249 reversed2[reversed2.length-i]= aligned2[i]; 250 } 251 240 reversed1[reversed1.length - count] = it.next(); 241 242 } 243 count = 0; 244 for (Iterator<Integer> it = aligned2.descendingIterator(); it.hasNext();) { 245 count++; 246 reversed2[reversed2.length - count] = it.next(); 247 } 248 252 249 NumberSequence ns1 = new NumberSequence(reversed1.length); 253 250 NumberSequence ns2 = new NumberSequence(reversed2.length); 254 251 ns1.setSequence(reversed1); 255 252 ns2.setSequence(reversed2); 256 253 257 254 alignment.add(ns1); 258 255 alignment.add(ns2); 259 256 } 257 258 260 259 261 260 public void printAlignment() { -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentStorage.java
r1587 r1589 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 3 2 4 3 5 4 6 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 5 7 6 public class BinaryAlignmentStorage { 8 9 public class PairwiseAlignmentStorage { 7 10 8 11 private AlignmentAlgorithm[][] alignments; 9 UPGMAMatrix sequenceDistances;12 private UPGMAMatrix sequenceDistances; 10 13 11 public BinaryAlignmentStorage(int sizex, int sizey) {14 public PairwiseAlignmentStorage(int sizex, int sizey) { 12 15 alignments = new AlignmentAlgorithm[sizex+1][sizey+1]; 13 16 sequenceDistances = new UPGMAMatrix(Math.max(sizex,sizey)); 14 17 sequenceDistances.initialize(Double.POSITIVE_INFINITY); 15 18 } 19 20 16 21 17 22 public void set(int i,int j,AlignmentAlgorithm sw) { -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java
r1588 r1589 15 15 16 16 import java.util.ArrayList; 17 import java.util.Iterator; 17 18 import java.util.logging.Level; 18 19 19 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm;20 20 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 21 21 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 22 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated; 23 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.BinaryAlignmentStorage; 22 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage; 24 23 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 25 24 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.UPGMAMatrix; … … 48 47 * @param m distance matrix 49 48 */ 50 public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, BinaryAlignmentStorage alignments, ObjectDistanceSubstitionMatrix submat)49 public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, PairwiseAlignmentStorage alignments, ObjectDistanceSubstitionMatrix submat) 51 50 { 52 51 if (alignments.getDistanceMatrix().size() < 2) … … 82 81 // 83 82 private ArrayList<NumberSequence> numberseqs; 84 private BinaryAlignmentStorage alignments;83 private PairwiseAlignmentStorage alignments; 85 84 private ObjectDistanceSubstitionMatrix submat; 86 85 private int numClusters; … … 216 215 int seqCount1 = node1.getSequences().size(); 217 216 int seqCount2 = node2.getSequences().size(); 218 219 /* 220 for(int i = 0; i < seqCount1; i++) { 221 for(int j = 0; j < seqCount2; j++) { 222 node1.getSequence(i).printSequence(); 223 node2.getSequence(j).printSequence(); 224 } 225 } 226 */ 217 227 218 228 219 Console.traceln(Level.INFO,"Merging node " + node1.getIdentifier() + " with " + node2.getIdentifier()); … … 237 228 alignment.addAll(node1.getSequences()); 238 229 239 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2);230 PairwiseAlignmentStorage tempStorage = new PairwiseAlignmentStorage(seqCount1,seqCount2); 240 231 double maxScore = 0.0; 241 232 int maxIndex = 0; … … 254 245 else if(seqCount1 == 1 && seqCount2 > 1) { 255 246 alignment.addAll(node2.getSequences()); 256 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2);247 PairwiseAlignmentStorage tempStorage = new PairwiseAlignmentStorage(seqCount1,seqCount2); 257 248 double maxScore = 0.0; 258 249 int maxIndex = 0; … … 270 261 //Align 2 groups 271 262 else if((seqCount1 > 1) && (seqCount2 > 1)){ 272 BinaryAlignmentStorage tempStorage1 = new BinaryAlignmentStorage(seqCount2,1);273 BinaryAlignmentStorage tempStorage2 = new BinaryAlignmentStorage(seqCount1,1);263 PairwiseAlignmentStorage tempStorage1 = new PairwiseAlignmentStorage(seqCount2,1); 264 PairwiseAlignmentStorage tempStorage2 = new PairwiseAlignmentStorage(seqCount1,1); 274 265 double maxScore1 = 0.0; 275 266 double maxScore2 = 0.0; … … 334 325 (oc[aj]/ocsum)*jdist; 335 326 } 327 328 329 public void printMultipleAlignment() { 330 for (Iterator<NumberSequence> it = getRoot().getSequences().iterator(); it.hasNext();) { 331 NumberSequence tmp = it.next(); 332 tmp.printSequence(); 333 } 334 } 336 335 } 337 336 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1588 r1589 29 29 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 30 30 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 31 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.BinaryAlignmentStorage; 31 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator; 32 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage; 32 33 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 33 34 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.tree.UPGMAAligningTree; … … 158 159 submat.generate(); 159 160 161 162 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat); 160 163 161 BinaryAlignmentStorage alignments = new BinaryAlignmentStorage(numberseqs.size(),numberseqs.size());162 163 164 for (int i = 0; i < numberseqs.size(); i++) {165 NumberSequence ns1 = numberseqs.get(i);166 for (int j = 0; j < numberseqs.size(); j++) {167 NumberSequence ns2 = numberseqs.get(j);168 169 if (i != j) {170 int smithWatermanThreshold = 10;171 172 alignments.set(i, j,AlignmentAlgorithmFactory.create(173 ns1.getSequence(), ns2.getSequence(), submat,174 smithWatermanThreshold));175 AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create(176 ns1.getSequence(), ns1.getSequence(), submat,177 smithWatermanThreshold);178 AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create(179 ns2.getSequence(), ns2.getSequence(), submat,180 smithWatermanThreshold);181 AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create(182 ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold);183 184 // Score of the aligmnment185 double score = alignments.get(i,j).getAlignmentScore();186 // Scores of the sequence being aligned to itself (maximum score)187 double sSelf1 = sameSequence1.getAlignmentScore();188 double sSelf2 = sameSequence2.getAlignmentScore();189 // Score of sequences shuffled before aligned190 double sRand = randomSequence.getAlignmentScore();191 192 double sMax = (sSelf1 + sSelf2) / 2;193 double sEff = (score - sRand)/ (sMax - sRand);194 if(sEff < 0) {195 sEff = 0;196 }197 double distance = -Math.log(sEff);198 199 200 if(!Double.isInfinite(distance) && !Double.isNaN(distance)) {201 if(distance < alignments.getDistance(i, j)) {202 alignments.setDistance(i,j,distance );203 }204 }205 }206 }207 }208 //alignments.get(20, 47).printDPMatrix();209 //alignments.get(20, 47).printAlignment();210 164 211 165 System.out.println(alignments.getDistanceMatrix()); 212 UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat); 213 System.out.println("Number of sequences in root node: " + guidetree.getRoot().getSequences().size()); 214 for (Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator(); it.hasNext();) { 215 NumberSequence tmp = it.next(); 216 tmp.printSequence(); 217 } 166 //UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat); 167 168 218 169 219 170
Note: See TracChangeset
for help on using the changeset viewer.