X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPairwiseAlignPanel.java;h=087d7f686ecef64d20b08c864e5f3129cdb48ea2;hb=a3fac343a7a385f8ec33a739ada884ebd0e170d8;hp=1cca215bc638a7021bc4711a7740ee2b519c7a18;hpb=254e54378f7545b2fdba83794625ebda03cb52d2;p=jalview.git diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 1cca215..087d7f6 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -28,9 +28,12 @@ import jalview.datamodel.SequenceI; import jalview.jbgui.GPairwiseAlignPanel; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.math.MiscMath; +import java.beans.PropertyChangeListener; import java.awt.event.ActionEvent; import java.util.Vector; +import javax.swing.event.SwingPropertyChangeSupport; /** * DOCUMENT ME! @@ -47,43 +50,87 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel private float[][] alignmentScores; // scores used by PaSiMap + private int GAP_OPEN_COST; + + private int GAP_EXTEND_COST; + AlignmentViewport av; Vector sequences; + private String alignmentOutput; + + private boolean suppressTextbox; + + private boolean discardAlignments; + + private boolean endGaps; + + // for listening + public static final String TOTAL = "total"; + + public static final String PROGRESS = "progress"; + + private int total; + + private int progress; + /** * Creates a new PairwiseAlignPanel object. * * @param viewport * DOCUMENT ME! + * @param endGaps ~ toggle gaps and the beginning and end of sequences */ public PairwiseAlignPanel(AlignmentViewport viewport) { + this(viewport, false, 120, 20, true); // default penalties used in AlignSeq + } + public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost) + { + this(viewport, endGaps, gapOpenCost, gapExtendCost, true); + } + public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost, boolean run) + { super(); this.av = viewport; + this.GAP_OPEN_COST = gapOpenCost; + this.GAP_EXTEND_COST = gapExtendCost; + this.endGaps = endGaps; + this.total = MiscMath.combinations(av.getAlignment().getHeight(), 2); + + if (run) + calculate(); +System.out.println("Creating pap"); + } + + public void calculate() + { + + SequenceGroup selectionGroup = av.getSelectionGroup(); + StringBuilder sb = new StringBuilder(1024); sequences = new Vector(); - SequenceGroup selectionGroup = viewport.getSelectionGroup(); boolean isSelection = selectionGroup != null && selectionGroup.getSize() > 0; - AlignmentView view = viewport.getAlignmentView(isSelection); - // String[] seqStrings = viewport.getViewAsString(true); + AlignmentView view = av.getAlignmentView(isSelection); + // String[] seqStrings = av.getViewAsString(true); String[] seqStrings = view - .getSequenceStrings(viewport.getGapCharacter()); + .getSequenceStrings(av.getGapCharacter()); SequenceI[] seqs; if (isSelection) { seqs = (SequenceI[]) view - .getAlignmentAndHiddenColumns(viewport.getGapCharacter())[0]; + .getAlignmentAndHiddenColumns(av.getGapCharacter())[0]; } else { seqs = av.getAlignment().getSequencesArray(); } - String type = (viewport.getAlignment().isNucleotide()) ? AlignSeq.DNA + String type = (av.getAlignment().isNucleotide()) ? AlignSeq.DNA : AlignSeq.PEP; float[][] scores = new float[seqs.length][seqs.length]; @@ -92,14 +139,20 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel int count = seqs.length; boolean first = true; + progress = 0; + firePropertyChange(TOTAL, 0, total); + + suppressTextbox = count<10; + discardAlignments = count<15; + for (int i = 1; i < count; i++) { // fill diagonal alignmentScores with Float.NaN - alignmentScores[i-1][i-1] = Float.NaN; + alignmentScores[i - 1][i - 1] = Float.NaN; for (int j = 0; j < i; j++) { AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], - seqStrings[j], type); + seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST); if (as.s1str.length() == 0 || as.s2str.length() == 0) { @@ -107,27 +160,43 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel } as.calcScoreMatrix(); - as.traceAlignment(); + if (endGaps) + { + as.traceAlignmentWithEndGaps(); + } else { + as.traceAlignment(); + } as.scoreAlignment(); if (!first) { System.out.println(DASHES); textarea.append(DASHES); + sb.append(DASHES); } first = false; - as.printAlignment(System.out); + if (discardAlignments) { + as.printAlignment(System.out); + } scores[i][j] = as.getMaxScore() / as.getASeq1().length; alignmentScores[i][j] = as.getAlignmentScore(); - //&! totscore = totscore + scores[i][j]; - textarea.append(as.getOutput()); - sequences.add(as.getAlignedSeq1()); - sequences.add(as.getAlignedSeq2()); + if (suppressTextbox) + { + textarea.append(as.getOutput()); + sb.append(as.getOutput()); + } + if (discardAlignments) + { + sequences.add(as.getAlignedSeq1()); + sequences.add(as.getAlignedSeq2()); + } + + firePropertyChange(PROGRESS, progress, ++progress); } } - alignmentScores[count-1][count-1] = Float.NaN; + alignmentScores[count - 1][count - 1] = Float.NaN; this.scores = scores; this.alignmentScores = alignmentScores; @@ -136,6 +205,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel { printScoreMatrix(seqs, scores, totscore); } + + alignmentOutput = sb.toString(); } public float[][] getScores() @@ -148,6 +219,11 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel return this.alignmentScores; } + public String getAlignmentOutput() + { + return this.alignmentOutput; + } + /** * Prints a matrix of seqi-seqj pairwise alignment scores to sysout * @@ -216,4 +292,14 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel MessageManager.getString("label.pairwise_aligned_sequences"), AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); } + + public long getTotal() + { + return total; + } + + public long getProgress() + { + return progress; + } }