Changeset 1585 for branches/ralph/src/main
- Timestamp:
- 06/29/14 11:11:30 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1581 r1585 2 2 3 3 import java.util.ArrayList; 4 import java.util.List;5 4 import java.util.logging.Level; 6 5 … … 33 32 34 33 35 private List<NumberSequence> alignment;34 private ArrayList<NumberSequence> alignment; 36 35 37 36 private float scoreThreshold; … … 329 328 330 329 331 public List<NumberSequence> getAlignment() {330 public ArrayList<NumberSequence> getAlignment() { 332 331 return alignment; 333 332 } 334 333 335 public void setAlignment( List<NumberSequence> alignment) {334 public void setAlignment(ArrayList<NumberSequence> alignment) { 336 335 this.alignment = alignment; 337 336 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/BinaryAlignmentStorage.java
r1584 r1585 9 9 UPGMAMatrix sequenceDistances; 10 10 11 public BinaryAlignmentStorage(int size ) {12 alignments = new SmithWatermanRepeated[size ][size];13 sequenceDistances = new UPGMAMatrix( size);11 public BinaryAlignmentStorage(int sizex, int sizey) { 12 alignments = new SmithWatermanRepeated[sizex+1][sizey+1]; 13 sequenceDistances = new UPGMAMatrix(Math.max(sizex,sizey)); 14 14 sequenceDistances.initialize(Double.POSITIVE_INFINITY); 15 15 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java
r1578 r1585 29 29 idmapping = new HashMap<Integer, Integer>(); 30 30 matrix = new TriangleMatrix(uniqueTasks.size()+1); 31 gapPenalty = - 5;31 gapPenalty = -3; 32 32 33 33 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/FengDoolittleNode.java
r1583 r1585 344 344 * @param n2 number of second child 345 345 */ 346 public voidjoinChildren( int n1, int n2) {346 public Node joinChildren( int n1, int n2) { 347 347 348 348 if (n1 == n2) { … … 376 376 //System.out.println("Merging " + child1.getIdentifier() + " with " + child2.getIdentifier()); 377 377 378 if(newNode instanceof FengDoolittleNode) { 379 newNode.setSequences(((FengDoolittleNode) newNode).alignSequences()); 380 } 381 378 return newNode; 382 379 } 383 380 … … 397 394 398 395 399 private ArrayList<NumberSequence> alignSequences() {400 ArrayList<NumberSequence> alignment = new ArrayList<NumberSequence>();401 if(this.getChildCount()<3) {402 403 Node node1 = getChild(0);404 Node node2 = getChild(1);405 406 int seqCount1 = node1.getSequences().size();407 int seqCount2 = node2.getSequences().size();408 409 //Align 2 sequences410 if(seqCount1 == 1 && seqCount2 == 1) {411 }412 //Align a sequence to a group413 else if( seqCount1 > 1 && seqCount2 == 1) {414 415 }416 //Align a sequence to a group417 else if(seqCount1 == 1 && seqCount2 > 1) {418 419 }420 //Align 2 groups421 else if((seqCount1 > 1) && (seqCount2 > 1)){422 423 }424 else {425 Console.traceln(Level.INFO,"No sequences to align while merging two nodes.");426 }427 }428 else {429 Console.traceln(Level.WARNING,"More than 2 children! This should never happen, it's a binary tree.");430 }431 return alignment;432 }433 434 396 public void setSequences(ArrayList<NumberSequence> alignSequences) { 435 397 this.sequences = alignSequences; 436 398 } 437 399 400 401 438 402 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/Node.java
r1583 r1585 134 134 ArrayList<NumberSequence> getSequences(); 135 135 136 voidjoinChildren( int n1, int n2);136 Node joinChildren( int n1, int n2); 137 137 138 138 void addSequence(NumberSequence numberSequence); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java
r1584 r1585 15 15 16 16 import java.util.ArrayList; 17 import java.util.Iterator; 18 import java.util.logging.Level; 17 19 18 20 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 21 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated; 19 22 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.BinaryAlignmentStorage; 23 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 20 24 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.UPGMAMatrix; 21 25 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc.Identifier; 26 import de.ugoe.cs.util.console.Console; 22 27 23 28 … … 42 47 * @param m distance matrix 43 48 */ 44 public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, BinaryAlignmentStorage alignments )49 public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, BinaryAlignmentStorage alignments, ObjectDistanceSubstitionMatrix submat) 45 50 { 46 51 if (alignments.getDistanceMatrix().size() < 2) … … 51 56 this.numberseqs = numberseqs; 52 57 this.alignments = alignments; 58 this.submat = submat; 53 59 init(alignments.getDistanceMatrix()); 54 60 … … 76 82 private ArrayList<NumberSequence> numberseqs; 77 83 private BinaryAlignmentStorage alignments; 84 private ObjectDistanceSubstitionMatrix submat; 78 85 private int numClusters; 79 86 private int besti, abi; … … 107 114 Node tmp = NodeFactory.createNode(); 108 115 tmp.setIdentifier(new Identifier(Integer.toString(i))); 116 tmp.setNumber(i); 109 117 tmp.addSequence(numberseqs.get(i)); 110 118 getRoot().addChild(tmp); … … 181 189 182 190 // Index besti now represent the new cluster 183 getRoot().joinChildren(besti, bestj); 191 Node newNode = getRoot().joinChildren(besti, bestj); 192 193 if(newNode instanceof FengDoolittleNode) { 194 newNode.setSequences(alignSequences(newNode)); 195 } 184 196 185 197 // Update alias … … 190 202 191 203 numClusters--; 204 } 205 206 207 public ArrayList<NumberSequence> alignSequences(Node parent) { 208 ArrayList<NumberSequence> alignment = new ArrayList<NumberSequence>(); 209 if(parent.getChildCount()<3) { 210 211 Node node1 = parent.getChild(0); 212 Node node2 = parent.getChild(1); 213 214 int seqCount1 = node1.getSequences().size(); 215 int seqCount2 = node2.getSequences().size(); 216 Console.traceln(Level.INFO,"Merging node " + node1.getIdentifier() + " with " + node2.getIdentifier()); 217 //Console.println("SeqCount1: " + seqCount1 + " seqCount2 " + seqCount2); 218 //Align 2 sequences 219 if(seqCount1 == 1 && seqCount2 == 1) { 220 alignment = (alignments.get(node1.getNumber(), node2.getNumber())).getAlignment(); 221 } 222 //Align a sequence to a group 223 else if( seqCount1 > 1 && seqCount2 == 1) { 224 alignment.addAll(node1.getSequences()); 225 226 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2); 227 double maxScore = 0.0; 228 int maxIndex = 0; 229 for(int i=0;i<seqCount1;i++) { 230 tempStorage.set(i, 1, new SmithWatermanRepeated(node1.getSequence(i).getSequence(), node2.getSequence(0).getSequence() , submat, 5)); 231 if(maxScore < tempStorage.get(i, 1).getAlignmentScore()) { 232 maxScore = tempStorage.get(i, 1).getAlignmentScore(); 233 maxIndex = i; 234 } 235 } 236 alignment.add(tempStorage.get(maxIndex, 1).getAlignment().get(1)); 237 } 238 //Align a sequence to a group 239 else if(seqCount1 == 1 && seqCount2 > 1) { 240 alignment.addAll(node2.getSequences()); 241 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2); 242 double maxScore = 0.0; 243 int maxIndex = 0; 244 for(int i=0;i<seqCount2;i++) { 245 tempStorage.set(1, i, new SmithWatermanRepeated(node2.getSequence(i).getSequence(), node1.getSequence(0).getSequence() , submat, 5)); 246 if(maxScore < tempStorage.get(1, i).getAlignmentScore()) { 247 maxScore = tempStorage.get(1, i).getAlignmentScore(); 248 maxIndex = i; 249 } 250 } 251 alignment.add(tempStorage.get(1,maxIndex).getAlignment().get(1)); 252 } 253 //Align 2 groups 254 else if((seqCount1 > 1) && (seqCount2 > 1)){ 255 BinaryAlignmentStorage tempStorage1 = new BinaryAlignmentStorage(seqCount2,1); 256 BinaryAlignmentStorage tempStorage2 = new BinaryAlignmentStorage(seqCount1,1); 257 double maxScore1 = 0.0; 258 double maxScore2 = 0.0; 259 int maxIndex1 = 0; 260 int maxIndex2 = 0; 261 for(int i=0;i<seqCount1;i++) { 262 for(int j=0;j<seqCount2;j++) { 263 tempStorage1.set(j, 0, new SmithWatermanRepeated(node1.getSequence(i).getSequence(), node2.getSequence(j).getSequence() , submat, 5)); 264 if(maxScore1 < tempStorage1.get(j, 0).getAlignmentScore()) { 265 maxScore1 = tempStorage1.get(j, 0).getAlignmentScore(); 266 maxIndex1 = j; 267 } 268 } 269 alignment.add(tempStorage1.get(maxIndex1,0).getAlignment().get(0)); 270 } 271 for(int i=0; i<seqCount2;i++) { 272 for (int j=0;j<seqCount1;j++) { 273 tempStorage2.set(j, 0, new SmithWatermanRepeated(node2.getSequence(i).getSequence(),node1.getSequence(j).getSequence(),submat,5)); 274 if(maxScore2 < tempStorage2.get(j, 0).getAlignmentScore()) { 275 maxScore2 = tempStorage2.get(j, 0).getAlignmentScore(); 276 maxIndex2 = j; 277 } 278 } 279 alignment.add(tempStorage2.get(maxIndex2,0).getAlignment().get(0)); 280 } 281 282 } 283 else { 284 Console.traceln(Level.WARNING,"No sequences to align while merging " + node1.getIdentifier() + " with " + node2.getIdentifier()); 285 } 286 } 287 else { 288 Console.traceln(Level.WARNING,"More than 2 children! This should never happen, it's a binary tree."); 289 } 290 return alignment; 192 291 } 193 292 … … 217 316 } 218 317 } 318 319 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1584 r1585 159 159 160 160 161 BinaryAlignmentStorage alignments = new BinaryAlignmentStorage(numberseqs.size() );161 BinaryAlignmentStorage alignments = new BinaryAlignmentStorage(numberseqs.size(),numberseqs.size()); 162 162 163 163 … … 207 207 } 208 208 //System.out.println(sequenceDistances.toString()); 209 UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments); 210 209 UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat); 210 211 for (Iterator<NumberSequence> it = guidetree.getRoot().getChild(0).getSequences().iterator(); it.hasNext();) { 212 NumberSequence tmp = it.next(); 213 tmp.printSequence(); 214 } 211 215 212 216 /*
Note: See TracChangeset
for help on using the changeset viewer.