if (j==i) {\r
distance[i][i] = 0;\r
} else {\r
- distance[i][j] = 100-Comparison.PID(sequence[i], sequence[j]);\r
+ distance[i][j] = 100-Comparison.PID(sequence[i], sequence[j], start, end);\r
distance[j][i] = distance[i][j];\r
}\r
}\r
for (int i = 0; i < noseqs-1; i++) {\r
for (int j = i; j < noseqs; j++) {\r
int score = 0;\r
- for (int k=0; k < sequence[i].getLength(); k++) {\r
+ for (int k=start; k < end; k++) {\r
try{\r
score +=\r
ResidueProperties.getBLOSUM62(sequence[i].getSequence(k,\r
void NewTreePanel(String type, String pwType, String title)
{
- //are the sequences aligned?
- if(!viewport.alignment.isAligned())
- {
- JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
- +"Try using the Pad function in the edit menu,\n"
- +"or one of the multiple sequence alignment web services.",
- "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
- return;
- }
-
+ String ltitle;
final TreePanel tp;
if (viewport.getSelectionGroup() != null &&
viewport.getSelectionGroup().getSize() > 3)
{
+ int s=0;
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ /* Decide if the selection is a column region */
+ while (s<sg.sequences.size()) {
+ if (((SequenceI) sg.sequences.elementAt(s++)).getLength()<sg.getEndRes()) {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The selected region to create a tree may\nonly contain residues or gaps.\n"
+ +"Try using the Pad function in the edit menu,\n"
+ +"or one of the multiple sequence alignment web services.",
+ "Sequences in selection are not aligned", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ }
+ title=title+" on region";
tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
pwType,
- 0, viewport.alignment.getWidth());
+ sg.getStartRes(), sg.getEndRes());
}
else
{
- tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
- type, pwType, 0, viewport.alignment.getWidth());
- }
+
+ //are the sequences aligned?
+ if(!viewport.alignment.isAligned())
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
+ +"Try using the Pad function in the edit menu,\n"
+ +"or one of the multiple sequence alignment web services.",
+ "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+ tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
+ type, pwType, 0, viewport.alignment.getWidth());
+ }
addTreeMenuItem(tp, title);
viewport.setCurrentTree(tp.getTree());
- Desktop.addInternalFrame(tp, title, 600, 500);
+ Desktop.addInternalFrame(tp, title+" from "+this.title, 600, 500);
}
public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
\r
return (float)100*(len-bad)/len;\r
}\r
+\r
+ // Another pid with region specification\r
+\r
+ public static float PID(SequenceI s1 , SequenceI s2, int start, int end)\r
+ {\r
+ int len;\r
+\r
+ if (s1.getSequence().length() > s2.getSequence().length())\r
+ len = s1.getSequence().length();\r
+ else\r
+ len = s2.getSequence().length();\r
+\r
+ if (end<len)\r
+ len=end;\r
+\r
+ if (len<start) {\r
+ start = len - 1; // we just use a single residue for the difference\r
+ }\r
+\r
+ int bad = 0;\r
+\r
+ for (int i = start; i < len; i++)\r
+ {\r
+ char chr1;\r
+ char chr2;\r
+\r
+ if (i < s1.getSequence().length())\r
+ chr1 = s1.getSequence().charAt(i);\r
+ else\r
+ chr1 = '.';\r
+\r
+\r
+ if (i < s2.getSequence().length())\r
+ chr2 = s2.getSequence().charAt(i);\r
+ else\r
+ chr2 = '.';\r
+\r
+\r
+ if (!(jalview.util.Comparison.isGap( chr1 )) && !(jalview.util.Comparison.isGap( chr2 )))\r
+ {\r
+ if (chr1!=chr2)\r
+ bad++;\r
+ }\r
+ }\r
+\r
+ return (float)100*(len-bad)/len;\r
+ }\r
+\r
+\r
public static String GapChars = " .-";\r
public static boolean isGap(char c)\r
{\r