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!
private static final String DASHES = "---------------------\n";
+ private float[][] scores;
+
+ private float[][] alignmentScores; // scores used by PaSiMap
+
+ private int GAP_OPEN_COST;
+
+ private int GAP_EXTEND_COST;
+
AlignmentViewport av;
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.
*
* @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<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];
+ float[][] alignmentScores = new float[seqs.length][seqs.length];
double totscore = 0D;
int count = seqs.length;
+ suppressTextbox = count<10;
+ discardAlignments = count<15;
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;
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)
{
}
as.calcScoreMatrix();
- as.traceAlignment();
+ if (endGaps)
+ {
+ as.traceAlignmentWithEndGaps();
+ }
+ else
+ {
+ as.traceAlignment();
+ }
+ as.scoreAlignment();
if (!first)
{
- System.out.println(DASHES);
+ jalview.bin.Console.outPrintln(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;
+
+ this.scores = scores;
+ this.alignmentScores = alignmentScores;
if (count > 2)
{
printScoreMatrix(seqs, scores, totscore);
}
+
+ alignmentOutput = sb.toString();
+ }
+
+ public float[][] getScores()
+ {
+ return this.scores;
+ }
+
+ public float[][] getAlignmentScores()
+ {
+ return this.alignmentScores;
+ }
+
+ public String getAlignmentOutput()
+ {
+ return this.alignmentOutput;
}
/**
for (int i = 0; i < seqs.length; i++)
{
- System.out.println(
+ jalview.bin.Console.outPrintln(
String.format("%3d %s", i + 1, seqs[i].getDisplayId(true)));
}
{
System.out.print(String.format("%7d", i + 1));
}
- System.out.println();
+ jalview.bin.Console.outPrintln();
for (int i = 0; i < seqs.length; i++)
{
*/
System.out.print(String.format("%7.3f", scores[i][j] / totscore));
}
- System.out.println();
+ jalview.bin.Console.outPrintln();
}
- System.out.println("\n");
+ jalview.bin.Console.outPrintln("\n");
}
/**
MessageManager.getString("label.pairwise_aligned_sequences"),
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
}
+
+ public long getTotal()
+ {
+ return total;
+ }
+
+ public long getProgress()
+ {
+ return progress;
+ }
}