Ignore:
Timestamp:
07/09/14 12:13:13 (10 years ago)
Author:
rkrimmel
Message:

Refactoring and code cleanup

Location:
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment
Files:
1 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/AlignmentAlgorithmFactory.java

    r1588 r1589  
    99                 
    1010                //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); 
    1313        } 
    1414} 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java

    r1587 r1589  
    22 
    33import java.util.ArrayList; 
     4import java.util.Iterator; 
     5import java.util.LinkedList; 
    46import java.util.logging.Level; 
    57 
     
    216218        } 
    217219 
    218          
    219          
    220220        public void traceback() { 
    221221                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 
    224237                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();) { 
    238239                        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 
    252249                NumberSequence ns1 = new NumberSequence(reversed1.length); 
    253250                NumberSequence ns2 = new NumberSequence(reversed2.length); 
    254251                ns1.setSequence(reversed1); 
    255252                ns2.setSequence(reversed2); 
    256                  
     253 
    257254                alignment.add(ns1); 
    258255                alignment.add(ns2); 
    259256        } 
     257         
     258 
    260259         
    261260        public void printAlignment() { 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentStorage.java

    r1587 r1589  
    11package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 
     2 
     3 
    24 
    35 
    46import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 
    57 
    6 public class BinaryAlignmentStorage { 
     8 
     9public class PairwiseAlignmentStorage { 
    710 
    811    private AlignmentAlgorithm[][] alignments; 
    9     UPGMAMatrix sequenceDistances; 
     12    private UPGMAMatrix sequenceDistances; 
    1013    
    11     public BinaryAlignmentStorage(int sizex, int sizey) { 
     14    public PairwiseAlignmentStorage(int sizex, int sizey) { 
    1215        alignments = new AlignmentAlgorithm[sizex+1][sizey+1]; 
    1316        sequenceDistances = new UPGMAMatrix(Math.max(sizex,sizey)); 
    1417        sequenceDistances.initialize(Double.POSITIVE_INFINITY); 
    1518    } 
     19  
     20     
    1621     
    1722    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  
    1515 
    1616import java.util.ArrayList; 
     17import java.util.Iterator; 
    1718import java.util.logging.Level; 
    1819 
    19 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 
    2020import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 
    2121import 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; 
     22import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage; 
    2423import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 
    2524import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.UPGMAMatrix; 
     
    4847         * @param m distance matrix 
    4948         */ 
    50         public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, BinaryAlignmentStorage alignments, ObjectDistanceSubstitionMatrix submat) 
     49        public UPGMAAligningTree(ArrayList<NumberSequence> numberseqs, PairwiseAlignmentStorage alignments, ObjectDistanceSubstitionMatrix submat) 
    5150        { 
    5251                if (alignments.getDistanceMatrix().size() < 2) 
     
    8281        // 
    8382        private ArrayList<NumberSequence> numberseqs; 
    84         private BinaryAlignmentStorage alignments; 
     83        private PairwiseAlignmentStorage alignments; 
    8584        private ObjectDistanceSubstitionMatrix submat; 
    8685        private int numClusters; 
     
    216215                        int seqCount1 = node1.getSequences().size(); 
    217216                        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 
    227218                         
    228219                        Console.traceln(Level.INFO,"Merging node " + node1.getIdentifier() + " with " + node2.getIdentifier()); 
     
    237228                                alignment.addAll(node1.getSequences()); 
    238229                                 
    239                                 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2); 
     230                                PairwiseAlignmentStorage tempStorage = new PairwiseAlignmentStorage(seqCount1,seqCount2); 
    240231                                double maxScore = 0.0; 
    241232                                int maxIndex = 0; 
     
    254245                        else if(seqCount1 == 1 && seqCount2 > 1) { 
    255246                                alignment.addAll(node2.getSequences()); 
    256                                 BinaryAlignmentStorage tempStorage = new BinaryAlignmentStorage(seqCount1,seqCount2); 
     247                                PairwiseAlignmentStorage tempStorage = new PairwiseAlignmentStorage(seqCount1,seqCount2); 
    257248                                double maxScore = 0.0; 
    258249                                int maxIndex = 0; 
     
    270261                        //Align 2 groups 
    271262                        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); 
    274265                                        double maxScore1 = 0.0; 
    275266                                        double maxScore2 = 0.0; 
     
    334325                        (oc[aj]/ocsum)*jdist; 
    335326        } 
     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        } 
    336335} 
    337336 
Note: See TracChangeset for help on using the changeset viewer.