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!
Vector<SequenceI> 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.
*
*/
public PairwiseAlignPanel(AlignmentViewport viewport)
{
- this(viewport, false, 120, 20); // default penalties used in AlignSeq
+ 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<SequenceI>();
- 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];
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, gapOpenCost, gapExtendCost);
+ seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST);
if (as.s1str.length() == 0 || as.s2str.length() == 0)
{
{
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;
{
printScoreMatrix(seqs, scores, totscore);
}
+
+ alignmentOutput = sb.toString();
}
public float[][] getScores()
return this.alignmentScores;
}
+ public String getAlignmentOutput()
+ {
+ return this.alignmentOutput;
+ }
+
/**
* Prints a matrix of seqi-seqj pairwise alignment scores to sysout
*
MessageManager.getString("label.pairwise_aligned_sequences"),
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
}
+
+ public long getTotal()
+ {
+ return total;
+ }
+
+ public long getProgress()
+ {
+ return progress;
+ }
}