Changeset 1612


Ignore:
Timestamp:
07/14/14 23:27:01 (10 years ago)
Author:
rkrimmel
Message:

Removed parameters from alignmentalgorihm factory constructor and changed interface by adding a new align() method, which now gets all the data via parameter

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  
    33import java.util.ArrayList; 
    44 
     5import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.SubstitutionMatrix; 
     6 
    57public interface AlignmentAlgorithm { 
    68 
     9        public abstract void align(int[] input1, int[] input2, SubstitutionMatrix submat,float threshold); 
     10         
    711        /** 
    812         * 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  
    11package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; 
     2 
     3import java.lang.reflect.Constructor; 
     4import java.lang.reflect.InvocationTargetException; 
    25 
    36import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.SubstitutionMatrix; 
     
    58public class AlignmentAlgorithmFactory { 
    69         
     10        public static void setDefaultAlgorithm(String algorithmname) { 
     11                //TODO: check for valid algorihm class names here 
     12                algorithmclass = algorithmname; 
     13        } 
    714         
    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                } 
    1030                //return new SmithWaterman(input1,input2,submat,threshold); 
    1131                //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; 
    1334        } 
    1435} 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NeedlemanWunsch.java

    r1592 r1612  
    3939        private SubstitutionMatrix submat; 
    4040 
    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         } 
    6541 
    6642        /** 
     
    289265        } 
    290266 
     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 
    291294 
    292295 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWaterman.java

    r1592 r1612  
    3838        private SubstitutionMatrix submat; 
    3939 
    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         } 
    6440 
    6541        /** 
     
    294270        } 
    295271 
     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 
    296299} 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java

    r1596 r1612  
    4343        private SubstitutionMatrix submat; 
    4444 
    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         
    6847        } 
    6948 
     
    374353        } 
    375354 
     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 
    376382} 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java

    r1595 r1612  
    2121                                if (i != j) { 
    2222                                        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                                 
    2728                                         
    28                                         AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create( 
     29                                        AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create(); 
     30                                                        sameSequence1.align( 
    2931                                                        ns1.getSequence(), ns1.getSequence(), submat, 
    3032                                                        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, 
    3335                                                        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); 
    3638                                         
    3739                                        // Score of the aligmnment 
    3840                                        double score = alignments.get(i,j).getAlignmentScore(); 
     41                                        /* 
    3942                                        if(score > 0) { 
    4043                                                System.out.println("Alignment: " + i + " " + j); 
     
    5255                                                System.out.println(); 
    5356                                        } 
     57                                        */ 
    5458                                        // Scores of the sequence being aligned to itself (maximum score) 
    5559                                        double sSelf1 = sameSequence1.getAlignmentScore(); 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java

    r1589 r1612  
    1818import java.util.logging.Level; 
    1919 
     20import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 
    2021import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 
    2122import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 
     
    221222                        //Align 2 sequences 
    222223                        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(); 
    224227                                 
    225228                        } 
     
    231234                                double maxScore = 0.0; 
    232235                                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                                         
    235241                                        if(maxScore < tempStorage.get(i, 1).getAlignmentScore()) { 
    236242                                                maxScore = tempStorage.get(i, 1).getAlignmentScore(); 
     
    249255                                int maxIndex = 0; 
    250256                                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); 
    252260                                        if(maxScore < tempStorage.get(1, i).getAlignmentScore()) { 
    253261                                                maxScore = tempStorage.get(1, i).getAlignmentScore(); 
     
    269277                                        for(int i=0;i<seqCount1;i++) { 
    270278                                                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); 
    272282                                                        if(maxScore1 < tempStorage1.get(j, 0).getAlignmentScore()) { 
    273283                                                                maxScore1 = tempStorage1.get(j, 0).getAlignmentScore(); 
     
    280290                                        for(int i=0; i<seqCount2;i++) { 
    281291                                                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); 
    283295                                                        if(maxScore2 < tempStorage2.get(j, 0).getAlignmentScore()) { 
    284296                                                                maxScore2 = tempStorage2.get(j, 0).getAlignmentScore(); 
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java

    r1595 r1612  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
    17  
    1817import java.util.ArrayList; 
    1918import java.util.HashMap; 
     
    2625import java.util.logging.Level; 
    2726 
    28  
     27import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 
    2928import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 
    3029import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator; 
     
    6261 * </p> 
    6362 * <p> 
    64  
     63 *  
    6564 *  
    6665 * @author Patrick Harms 
     
    158157                submat.generate(); 
    159158 
     159                ArrayList<NumberSequence> matchseqs = new ArrayList<NumberSequence>(); 
     160                PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat); 
    160161                 
    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); 
    164175                System.out.println(alignments.getDistanceMatrix()); 
    165176                //UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat); 
    166177                 
    167                  
     178                for(Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator();it.hasNext();) { 
     179                        NumberSequence tmp = (NumberSequence) it.next(); 
     180                        tmp.printSequence(); 
     181                } 
    168182                 
    169183         
Note: See TracChangeset for help on using the changeset viewer.