package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; import java.util.ArrayList; import java.util.Iterator; import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; public class PairwiseAlignmentGenerator { public static PairwiseAlignmentStorage generate(ArrayList numberseqs,ObjectDistanceSubstitionMatrix submat) { PairwiseAlignmentStorage alignments = new PairwiseAlignmentStorage(numberseqs.size(),numberseqs.size()); for (int i = 0; i < numberseqs.size(); i++) { NumberSequence ns1 = numberseqs.get(i); for (int j = 0; j < numberseqs.size(); j++) { NumberSequence ns2 = numberseqs.get(j); if (i != j) { int smithWatermanThreshold = 10; alignments.set(i, j,AlignmentAlgorithmFactory.create( ns1.getSequence(), ns2.getSequence(), submat, smithWatermanThreshold)); AlignmentAlgorithm sameSequence1 = AlignmentAlgorithmFactory.create( ns1.getSequence(), ns1.getSequence(), submat, smithWatermanThreshold); AlignmentAlgorithm sameSequence2 = AlignmentAlgorithmFactory.create( ns2.getSequence(), ns2.getSequence(), submat, smithWatermanThreshold); AlignmentAlgorithm randomSequence = AlignmentAlgorithmFactory.create( ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold); // Score of the aligmnment double score = alignments.get(i,j).getAlignmentScore(); if(score > 0) { System.out.println("Alignment: " + i + " " + j); alignments.get(i, j).printAlignment(); ArrayList> matches = alignments.get(i, j).getMatches(); int count = 0; for(Iterator> it = matches.iterator();it.hasNext();) { System.out.println("Match number " + count); ArrayList tmp = it.next(); tmp.get(0).printSequence(); tmp.get(1).printSequence(); System.out.println(); count++; } System.out.println(); } // Scores of the sequence being aligned to itself (maximum score) double sSelf1 = sameSequence1.getAlignmentScore(); double sSelf2 = sameSequence2.getAlignmentScore(); // Score of sequences shuffled before aligned double sRand = randomSequence.getAlignmentScore(); double sMax = (sSelf1 + sSelf2) / 2; double sEff = (score - sRand)/ (sMax - sRand); if(sEff < 0) { sEff = 0; } double distance = -Math.log(sEff); if(!Double.isInfinite(distance) && !Double.isNaN(distance)) { if(distance < alignments.getDistance(i, j)) { alignments.setDistance(i,j,distance ); } } } } } return alignments; } }