+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
-import jalview.datamodel.*;\r
-import jalview.jbgui.GPairwiseAlignPanel;\r
import jalview.analysis.*;\r
+\r
+import jalview.datamodel.*;\r
+\r
+import jalview.jbgui.*;\r
+\r
import java.awt.event.*;\r
-import javax.swing.*;\r
+\r
import java.util.*;\r
\r
\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
public class PairwiseAlignPanel extends GPairwiseAlignPanel\r
{\r
- Vector sequences = new Vector();\r
+\r
AlignViewport av;\r
+ Vector sequences;\r
\r
+ /**\r
+ * Creates a new PairwiseAlignPanel object.\r
+ *\r
+ * @param av DOCUMENT ME!\r
+ */\r
public PairwiseAlignPanel(AlignViewport av)\r
{\r
- super();\r
- this.av = av;\r
- float scores[][] = new float[av.getAlignment().getHeight()][av.getAlignment().getHeight()];\r
- double totscore = 0;\r
- int count = av.getSelectionGroup().getSize();\r
+ super();\r
+ this.av = av;\r
\r
- int acount = 0;\r
- for (int i = 1; i < count; i++)\r
- {\r
- for (int j = 0; j < i; j++)\r
- {\r
- acount++;\r
- AlignSeq as = new AlignSeq(av.getSelectionGroup().getSequenceAt(i),\r
- av.getSelectionGroup().getSequenceAt(j),"pep");\r
-\r
- as.calcScoreMatrix();\r
- as.traceAlignment();\r
- as.printAlignment();\r
- scores[i][j] = (float)as.getMaxScore()/(float)as.getASeq1().length;\r
- totscore = totscore + scores[i][j];\r
+ sequences = new Vector();\r
\r
- textarea.append(as.getOutput());\r
- sequences.add( new Sequence( as.getS1().getName(), as.getAStr1()) );\r
- sequences.add( new Sequence( as.getS2().getName(), as.getAStr2()) );\r
+ SequenceI [] seqs;\r
+ String [] seqStrings = av.getViewAsString(true);\r
\r
-\r
- }\r
+ if(av.getSelectionGroup()==null)\r
+ {\r
+ seqs = av.alignment.getSequencesArray();\r
}\r
-\r
- if (count > 2)\r
+ else\r
{\r
- for (int i = 0; i < count;i++)\r
- for (int j = 0; j < i; j++)\r
- jalview.util.Format.print(System.out,"%7.3f",scores[i][j]/totscore);\r
+ seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);\r
}\r
- }\r
\r
\r
- protected void viewInEditorButton_actionPerformed(ActionEvent e)\r
- {\r
+ float[][] scores = new float[seqs.length][seqs.length];\r
+ double totscore = 0;\r
+ int count = seqs.length;\r
\r
- Sequence [] seq = new Sequence[sequences.size()];\r
-\r
- for (int i=0;i<sequences.size();i++)\r
- seq[i] = (Sequence) sequences.elementAt(i);\r
+ Sequence seq;\r
\r
+ for (int i = 1; i < count; i++)\r
+ {\r
+ for (int j = 0; j < i; j++)\r
+ {\r
+\r
+ AlignSeq as = new AlignSeq(seqs[i], seqStrings[i],\r
+ seqs[j], seqStrings[j], "pep");\r
+\r
+ if(as.s1str.length()==0 || as.s2str.length()==0)\r
+ {\r
+ continue;\r
+ }\r
+\r
+ as.calcScoreMatrix();\r
+ as.traceAlignment();\r
+\r
+\r
+ as.printAlignment(System.out);\r
+ scores[i][j] = (float) as.getMaxScore() / (float) as.getASeq1().length;\r
+ totscore = totscore + scores[i][j];\r
+\r
+ textarea.append(as.getOutput());\r
+ seq = new Sequence(as.getS1().getName(),\r
+ as.getAStr1(),\r
+ as.getS1().getStart(),\r
+ as.getS1().getEnd()\r
+ );\r
+ sequences.add(seq);\r
+\r
+ seq = new Sequence(as.getS2().getName(),\r
+ as.getAStr2(),\r
+ as.getS2().getStart(),\r
+ as.getS2().getEnd() );\r
+ sequences.add(seq);\r
+ }\r
+ }\r
\r
- AlignFrame af = new AlignFrame(new Alignment(seq));\r
- int newHeight = seq.length * af.viewport.getCharHeight() + 200;\r
- if(newHeight>500)\r
- newHeight=500;\r
+ if (count > 2)\r
+ {\r
+ System.out.println(\r
+ "Pairwise alignment scaled similarity score matrix\n");\r
+\r
+ for (int i = 0; i < count; i++)\r
+ {\r
+ jalview.util.Format.print(System.out, "%s \n",\r
+ ("" + i) + " " +\r
+ seqs[i].getName());\r
+ }\r
+\r
+ System.out.println("\n");\r
+\r
+ for (int i = 0; i < count; i++)\r
+ {\r
+ for (int j = 0; j < i; j++)\r
+ {\r
+ jalview.util.Format.print(System.out, "%7.3f",\r
+ scores[i][j] / totscore);\r
+ }\r
+ }\r
+\r
+ System.out.println("\n");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void viewInEditorButton_actionPerformed(ActionEvent e)\r
+ {\r
+ Sequence[] seq = new Sequence[sequences.size()];\r
\r
- Desktop.addInternalFrame(af, "Pairwise Aligned Sequences", 700,newHeight);\r
+ for (int i = 0; i < sequences.size(); i++)\r
+ {\r
+ seq[i] = (Sequence) sequences.elementAt(i);\r
+ }\r
\r
- }\r
+ AlignFrame af = new AlignFrame(new Alignment(seq),\r
+ AlignFrame.DEFAULT_WIDTH,\r
+ AlignFrame.DEFAULT_HEIGHT);\r
\r
+ Desktop.addInternalFrame(af, "Pairwise Aligned Sequences",\r
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);\r
+ }\r
}\r