-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 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.datamodel;\r
-\r
-import java.util.*;\r
-\r
-\r
-/**\r
- * <p>Title: </p>\r
- *\r
- * <p>Description: </p>\r
- *\r
- * <p>Copyright: Copyright (c) 2004</p>\r
- *\r
- * <p>Company: Dundee University</p>\r
- *\r
- * @author not attributable\r
- * @version 1.0\r
- */\r
-public class AlignmentOrder\r
-{\r
- // JBPNote : this method would return a vector containing all sequences in seqset\r
- // with those also contained in order at the beginning of the vector in the order\r
- // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method\r
- // should be here for completeness.\r
-\r
- /* public Vector getOrder(AlignmentI seqset)\r
- {\r
- Vector perm = new Vector(seqset.getHeight());\r
- for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)\r
- perm.setElement(i,...).\r
- return Order;\r
- }\r
- */\r
-\r
- /** DOCUMENT ME!! */\r
- public static final int FILE = 0;\r
-\r
- /** DOCUMENT ME!! */\r
- public static final int MSA = 1;\r
-\r
- /** DOCUMENT ME!! */\r
- public static final int USER = 2;\r
- private int Type = 0;\r
- private String Name;\r
- private Vector Order = null;\r
-\r
- /**\r
- * Creates a new AlignmentOrder object.\r
- */\r
- public AlignmentOrder()\r
- {\r
- }\r
-\r
- /**\r
- * AlignmentOrder\r
- *\r
- * @param anOrder Vector\r
- */\r
- public AlignmentOrder(Vector anOrder)\r
- {\r
- Order = anOrder;\r
- }\r
-\r
- /**\r
- * AlignmentOrder\r
- *\r
- * @param orderFrom AlignmentI\r
- */\r
- public AlignmentOrder(AlignmentI orderFrom)\r
- {\r
- Order = new Vector();\r
-\r
- for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)\r
- {\r
- Order.addElement(orderFrom.getSequenceAt(i));\r
- }\r
- }\r
-\r
- /**\r
- * Creates a new AlignmentOrder object.\r
- *\r
- * @param orderFrom DOCUMENT ME!\r
- */\r
- public AlignmentOrder(SequenceI[] orderFrom)\r
- {\r
- Order = new Vector();\r
-\r
- for (int i = 0, ns = orderFrom.length; i < ns; i++)\r
- {\r
- Order.addElement(orderFrom[i]);\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param Type DOCUMENT ME!\r
- */\r
- public void setType(int Type)\r
- {\r
- this.Type = Type;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getType()\r
- {\r
- return Type;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param Name DOCUMENT ME!\r
- */\r
- public void setName(String Name)\r
- {\r
- this.Name = Name;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getName()\r
- {\r
- return Name;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param Order DOCUMENT ME!\r
- */\r
- public void setOrder(Vector Order)\r
- {\r
- this.Order = Order;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector getOrder()\r
- {\r
- return Order;\r
- }\r
- /**\r
- * replaces oldref with newref in the alignment order.\r
- * @param oldref\r
- * @param newref\r
- * @return\r
- */\r
- public boolean updateSequence(SequenceI oldref, SequenceI newref) {\r
- int found=Order.indexOf(oldref);\r
- if (found>-1) {\r
- Order.setElementAt(newref, found);\r
- }\r
- return found>-1;\r
- }\r
- /**\r
- * AlignmentOrder\r
- *\r
- * @param orderThis AlignmentI\r
- * @param byThat AlignmentI\r
- */\r
-\r
- /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)\r
- {\r
- // Vector is an ordering of this alignment using the order of sequence objects in byThat,\r
- // where ids and unaligned sequences must match\r
-\r
- } */\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import java.util.*;
+
+
+/**
+ * <p>Title: </p>
+ *
+ * <p>Description: </p>
+ *
+ * <p>Copyright: Copyright (c) 2004</p>
+ *
+ * <p>Company: Dundee University</p>
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class AlignmentOrder
+{
+ // JBPNote : this method would return a vector containing all sequences in seqset
+ // with those also contained in order at the beginning of the vector in the order
+ // given by order. AlignmentSorter.vectorSubsetToArray already does this, but that method
+ // should be here for completeness.
+
+ /* public Vector getOrder(AlignmentI seqset)
+ {
+ Vector perm = new Vector(seqset.getHeight());
+ for (i=0, o = 0, n=seqset.getHeight(), p = Order.size(); i<n; i++)
+ perm.setElement(i,...).
+ return Order;
+ }
+ */
+
+ /** DOCUMENT ME!! */
+ public static final int FILE = 0;
+
+ /** DOCUMENT ME!! */
+ public static final int MSA = 1;
+
+ /** DOCUMENT ME!! */
+ public static final int USER = 2;
+ private int Type = 0;
+ private String Name;
+ private Vector Order = null;
+
+ /**
+ * Creates a new AlignmentOrder object.
+ */
+ public AlignmentOrder()
+ {
+ }
+
+ /**
+ * AlignmentOrder
+ *
+ * @param anOrder Vector
+ */
+ public AlignmentOrder(Vector anOrder)
+ {
+ Order = anOrder;
+ }
+
+ /**
+ * AlignmentOrder
+ *
+ * @param orderFrom AlignmentI
+ */
+ public AlignmentOrder(AlignmentI orderFrom)
+ {
+ Order = new Vector();
+
+ for (int i = 0, ns = orderFrom.getHeight(); i < ns; i++)
+ {
+ Order.addElement(orderFrom.getSequenceAt(i));
+ }
+ }
+
+ /**
+ * Creates a new AlignmentOrder object.
+ *
+ * @param orderFrom DOCUMENT ME!
+ */
+ public AlignmentOrder(SequenceI[] orderFrom)
+ {
+ Order = new Vector();
+
+ for (int i = 0, ns = orderFrom.length; i < ns; i++)
+ {
+ Order.addElement(orderFrom[i]);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param Type DOCUMENT ME!
+ */
+ public void setType(int Type)
+ {
+ this.Type = Type;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getType()
+ {
+ return Type;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param Name DOCUMENT ME!
+ */
+ public void setName(String Name)
+ {
+ this.Name = Name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getName()
+ {
+ return Name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param Order DOCUMENT ME!
+ */
+ public void setOrder(Vector Order)
+ {
+ this.Order = Order;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getOrder()
+ {
+ return Order;
+ }
+ /**
+ * replaces oldref with newref in the alignment order.
+ * @param oldref
+ * @param newref
+ * @return
+ */
+ public boolean updateSequence(SequenceI oldref, SequenceI newref) {
+ int found=Order.indexOf(oldref);
+ if (found>-1) {
+ Order.setElementAt(newref, found);
+ }
+ return found>-1;
+ }
+ /**
+ * Exact equivalence of two AlignmentOrders
+ * @param o
+ * @return true if o orders the same sequenceI objects in the same way
+ */
+ public boolean equals(AlignmentOrder o) {
+ return equals(o, true);
+ }
+ /**
+ * Exact equivalence of two AlignmentOrders
+ * // TODO: Weak SequenceI equivalence - will throw Error at moment
+ * @param o
+ * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
+ * @return true if o orders equivalent sequenceI objects in the same way
+ */
+ public boolean equals(AlignmentOrder o, boolean identity) {
+ if (o!=this) {
+ if (o==null)
+ return false;
+ if (Order!=null && o.Order!=null && Order.size()==o.Order.size()) {
+ if (!identity) {
+ throw new Error("Weak sequenceI equivalence not yet implemented.");
+ } else {
+ for (int i=0,j=o.Order.size(); i<j; i++) {
+ if (Order.get(i)!=o.Order.get(i))
+ return false;
+ }
+ }
+ } else
+ return false;
+ }
+ return true;
+ }
+ /**
+ * Consistency test for alignmentOrders
+ * @param o
+ * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
+ */
+ public boolean isConsistent(AlignmentOrder o) {
+ return isConsistent(o, true);
+ }
+ /**
+ * Consistency test for alignmentOrders
+ * @param o
+ * // TODO: Weak SequenceI equivalence - will throw Error at moment
+ * @param identity - false - use weak equivalence (refers to same or different parts of same sequence)
+ * @return true if o contains or is contained by this and the common SequenceI objects are ordered in the same way
+ */
+ public boolean isConsistent(AlignmentOrder o, boolean identity) {
+ if (o!=this) {
+ if (o==null)
+ return false;
+ if (Order!=null && o.Order!=null) {
+ Vector c,s;
+ if (o.Order.size()>Order.size()) {
+ c = o.Order;
+ s = Order;
+ } else {
+ c = Order;
+ s = o.Order;
+ }
+ if (!identity) {
+ throw new Error("Weak sequenceI equivalence not yet implemented.");
+ } else {
+ // test if c contains s and order in s is conserved in c
+ int last=-1;
+ for (int i=0,j=s.size(); i<j; i++) {
+ int pos=c.indexOf(s.get(i)); // JBPNote - optimize by incremental position search
+ if (pos>last) {
+ last=pos;
+ } else
+ return false;
+ }
+ }
+ } else
+ return false;
+ }
+ return true;
+ }
+ /**
+ * AlignmentOrder
+ *
+ * @param orderThis AlignmentI
+ * @param byThat AlignmentI
+ */
+
+ /* public AlignmentOrder(AlignmentI orderThis, AlignmentI byThat)
+ {
+ // Vector is an ordering of this alignment using the order of sequence objects in byThat,
+ // where ids and unaligned sequences must match
+
+ } */
+}
seqs[i].setDatasetSequence(ref);
}
if (segments!=null) {
- int delshift=0; // need to shift the segments to their absolute positions in the sequence cigar frame.
for (int i=0; i<segments.length; i+=3) {
//int start=shifts.shift(segments[i]-1)+1;
//int end=shifts.shift(segments[i]+segments[i+1]-1)-1;
- colsel.hideColumns(delshift+segments[i], delshift+segments[i]+segments[i+2]-1);
- delshift+=segments[i+2];
+ colsel.hideColumns(segments[i+1], segments[i+1]+segments[i+2]-1);
}
}
return seqs;
-/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 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.datamodel;\r
-\r
-import java.awt.*;\r
-\r
-import java.util.*;\r
-\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class Sequence implements SequenceI\r
-{\r
- SequenceI datasetSequence;\r
- String name;\r
- private String sequence;\r
- String description;\r
- int start;\r
- int end;\r
- Color color = Color.white;\r
- Vector pdbIds;\r
- String vamsasId;\r
- DBRefEntry [] dbrefs;\r
-\r
- /** This annotation is displayed below the alignment but the\r
- * positions are tied to the residues of this sequence */\r
- Vector annotation;\r
-\r
- /** DOCUMENT ME!! */\r
- public SequenceFeature [] sequenceFeatures;\r
-\r
- /** This array holds hidden sequences\r
- * of which this sequence is the representitive member of a group\r
- */\r
- SequenceGroup hiddenSequences;\r
-\r
- /**\r
- * Creates a new Sequence object.\r
- *\r
- * @param name DOCUMENT ME!\r
- * @param sequence DOCUMENT ME!\r
- * @param start DOCUMENT ME!\r
- * @param end DOCUMENT ME!\r
- */\r
- public Sequence(String name, String sequence, int start, int end)\r
- {\r
- this.name = name;\r
- this.sequence = sequence;\r
- this.start = start;\r
- this.end = end;\r
-\r
- parseId();\r
-\r
- checkValidRange();\r
- }\r
-\r
- com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(\r
- "[/][0-9]{1,}[-][0-9]{1,}$");\r
- com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(\r
- "[0-9]{1,}$");\r
-\r
- void parseId()\r
- {\r
- // Does sequence have the /start-end signiature?\r
- if(limitrx.search(name))\r
- {\r
- name = limitrx.left();\r
- endrx.search(limitrx.stringMatched());\r
- setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 )));\r
- setEnd( Integer.parseInt( endrx.stringMatched() ));\r
- }\r
- }\r
-\r
- void checkValidRange()\r
- {\r
- if (end < 1)\r
- {\r
- int endRes = 0;\r
- char ch;\r
- for (int j = 0; j < sequence.length(); j++)\r
- {\r
- ch = sequence.charAt(j);\r
- if (!jalview.util.Comparison.isGap( (ch)))\r
- {\r
- endRes++;\r
- }\r
- }\r
- if (endRes > 0)\r
- {\r
- endRes += start - 1;\r
- }\r
-\r
- this.end = endRes;\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Creates a new Sequence object.\r
- *\r
- * @param name DOCUMENT ME!\r
- * @param sequence DOCUMENT ME!\r
- */\r
- public Sequence(String name, String sequence)\r
- {\r
- this(name, sequence, 1, -1);\r
- }\r
-\r
- /**\r
- * Creates a new Sequence object.\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- public Sequence(SequenceI seq)\r
- {\r
- this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param v DOCUMENT ME!\r
- */\r
- public void setSequenceFeatures(SequenceFeature [] features)\r
- {\r
- sequenceFeatures = features;\r
- }\r
-\r
- public synchronized void addSequenceFeature(SequenceFeature sf)\r
- {\r
- if(sequenceFeatures==null)\r
- {\r
- sequenceFeatures = new SequenceFeature[0];\r
- }\r
-\r
- for(int i=0; i<sequenceFeatures.length; i++)\r
- {\r
- if(sequenceFeatures[i].equals(sf))\r
- {\r
- return;\r
- }\r
- }\r
-\r
- SequenceFeature [] temp = new SequenceFeature[sequenceFeatures.length+1];\r
- System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);\r
- temp[sequenceFeatures.length] = sf;\r
-\r
- sequenceFeatures = temp;\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public SequenceFeature [] getSequenceFeatures()\r
- {\r
- return sequenceFeatures;\r
- }\r
-\r
- public void addPDBId(PDBEntry entry)\r
- {\r
- if(pdbIds == null)\r
- pdbIds = new Vector();\r
-\r
- pdbIds.addElement(entry);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param id DOCUMENT ME!\r
- */\r
- public void setPDBId(Vector id)\r
- {\r
- pdbIds = id;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector getPDBId()\r
- {\r
- return pdbIds;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getDisplayId(boolean jvsuffix)\r
- {\r
- StringBuffer result = new StringBuffer(name);\r
- if (jvsuffix)\r
- {\r
- result.append("/" + start + "-" + end);\r
- }\r
-\r
- return result.toString();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param name DOCUMENT ME!\r
- */\r
- public void setName(String name)\r
- {\r
- this.name = name;\r
- this.parseId();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getName()\r
- {\r
- return this.name;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param start DOCUMENT ME!\r
- */\r
- public void setStart(int start)\r
- {\r
- this.start = start;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getStart()\r
- {\r
- return this.start;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param end DOCUMENT ME!\r
- */\r
- public void setEnd(int end)\r
- {\r
- this.end = end;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getEnd()\r
- {\r
- return this.end;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getLength()\r
- {\r
- return this.sequence.length();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- public void setSequence(String seq)\r
- {\r
- this.sequence = seq;\r
- checkValidRange();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getSequence()\r
- {\r
- return this.sequence;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param start DOCUMENT ME!\r
- * @param end DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getSequence(int start, int end)\r
- {\r
- // JBPNote - left to user to pad the result here (TODO:Decide on this policy)\r
- if (start >= sequence.length())\r
- {\r
- return "";\r
- }\r
-\r
- if (end >= sequence.length())\r
- {\r
- end = sequence.length();\r
- }\r
-\r
- return this.sequence.substring(start, end);\r
- }\r
- /**\r
- * make a new Sequence object from start to end (including gaps) over this seqeunce\r
- * @param start int\r
- * @param end int\r
- * @return SequenceI\r
- */\r
- public SequenceI getSubSequence(int start, int end) {\r
- if (start<0)\r
- start = 0;\r
- String seq = getSequence(start, end);\r
- if (seq=="")\r
- return null;\r
- start = findPosition(start);\r
- end=findPosition(end);\r
- // JBPNote - this is an incomplete copy.\r
- SequenceI nseq = new Sequence(this.getName(), seq, start, end);\r
- nseq.setDatasetSequence(getDatasetSequence());\r
- return nseq;\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public char getCharAt(int i)\r
- {\r
- if (i < sequence.length())\r
- {\r
- return sequence.charAt(i);\r
- }\r
- else\r
- {\r
- return ' ';\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param desc DOCUMENT ME!\r
- */\r
- public void setDescription(String desc)\r
- {\r
- this.description = desc;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getDescription()\r
- {\r
- return this.description;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param pos DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int findIndex(int pos)\r
- {\r
- // returns the alignment position for a residue\r
- int j = start;\r
- int i = 0;\r
-\r
- while ((i < sequence.length()) && (j <= end) && (j <= pos))\r
- {\r
- if (!jalview.util.Comparison.isGap(sequence.charAt(i)))\r
- {\r
- j++;\r
- }\r
-\r
- i++;\r
- }\r
-\r
- if ((j == end) && (j < pos))\r
- {\r
- return end + 1;\r
- }\r
- else\r
- {\r
- return i;\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int findPosition(int i)\r
- {\r
- // Returns the sequence position for an alignment position\r
- int j = 0;\r
- int pos = start;\r
-\r
- while ((j < i) && (j < sequence.length()))\r
- {\r
- if (!jalview.util.Comparison.isGap((sequence.charAt(j))))\r
- {\r
- pos++;\r
- }\r
-\r
- j++;\r
- }\r
-\r
- return pos;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int[] gapMap()\r
- {\r
- // Returns an int array giving the position of each residue in the sequence in the alignment\r
- String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequence);\r
- int[] map = new int[seq.length()];\r
- int j = 0;\r
- int p = 0;\r
-\r
- while (j < sequence.length())\r
- {\r
- if (!jalview.util.Comparison.isGap(sequence.charAt(j)))\r
- {\r
- map[p++] = j;\r
- }\r
-\r
- j++;\r
- }\r
-\r
- return map;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- */\r
- public void deleteCharAt(int i)\r
- {\r
- if (i >= sequence.length())\r
- {\r
- return;\r
- }\r
-\r
- sequence = sequence.substring(0, i) + sequence.substring(i + 1);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- * @param j DOCUMENT ME!\r
- */\r
- public void deleteChars(int i, int j)\r
- {\r
- if (i >= sequence.length())\r
- {\r
- return;\r
- }\r
-\r
- if (j >= sequence.length())\r
- {\r
- sequence = sequence.substring(0, i);\r
- }\r
- else\r
- {\r
- sequence = sequence.substring(0, i) + sequence.substring(j);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- * @param c DOCUMENT ME!\r
- * @param chop DOCUMENT ME!\r
- */\r
- public void insertCharAt(int i, char c)\r
- {\r
- String tmp = new String(sequence);\r
-\r
- if (i < sequence.length())\r
- {\r
- sequence = tmp.substring(0, i) + String.valueOf(c) +\r
- tmp.substring(i);\r
- }\r
- else\r
- {\r
- // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!\r
- char[] ch = new char[(1 + i) - sequence.length()];\r
-\r
- for (int j = 0, k = ch.length; j < k; j++)\r
- ch[j] = c;\r
-\r
- sequence = tmp + String.valueOf(ch);\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param c DOCUMENT ME!\r
- */\r
- public void setColor(Color c)\r
- {\r
- this.color = c;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Color getColor()\r
- {\r
- return color;\r
- }\r
-\r
- public String getVamsasId()\r
- {\r
- return vamsasId;\r
- }\r
-\r
- public void setVamsasId(String id)\r
- {\r
- vamsasId = id;\r
- }\r
-\r
- public void setDBRef(DBRefEntry [] dbref)\r
- {\r
- dbrefs = dbref;\r
- }\r
-\r
- public DBRefEntry [] getDBRef()\r
- {\r
- return dbrefs;\r
- }\r
-\r
- public void addDBRef(DBRefEntry entry)\r
- {\r
- if(dbrefs == null)\r
- dbrefs = new DBRefEntry[0];\r
-\r
- DBRefEntry [] temp = new DBRefEntry[dbrefs.length+1];\r
- System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);\r
-\r
- temp[temp.length-1] = entry;\r
-\r
- dbrefs = temp;\r
- }\r
-\r
- public void setDatasetSequence(SequenceI seq)\r
- {\r
- datasetSequence = seq;\r
- }\r
-\r
- public SequenceI getDatasetSequence()\r
- {\r
- return datasetSequence;\r
- }\r
-\r
- public AlignmentAnnotation [] getAnnotation()\r
- {\r
- if(annotation==null)\r
- return null;\r
-\r
- AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()];\r
- for(int r = 0; r<ret.length; r++)\r
- ret[r] = (AlignmentAnnotation)annotation.elementAt(r);\r
-\r
- return ret;\r
- }\r
-\r
- public void addAlignmentAnnotation(AlignmentAnnotation annotation)\r
- {\r
- if(this.annotation==null)\r
- this.annotation = new Vector();\r
-\r
- this.annotation.addElement( annotation );\r
- }\r
-\r
- public SequenceGroup getHiddenSequences()\r
- {\r
- return hiddenSequences;\r
- }\r
-\r
- public void addHiddenSequence(SequenceI seq)\r
- {\r
- if(hiddenSequences==null)\r
- {\r
- hiddenSequences = new SequenceGroup();\r
- }\r
- hiddenSequences.addSequence(seq, false);\r
- }\r
-\r
- public void showHiddenSequence(SequenceI seq)\r
- {\r
- hiddenSequences.deleteSequence(seq, false);\r
- if (hiddenSequences.getSize(false) < 1)\r
- {\r
- hiddenSequences = null;\r
- }\r
- }\r
-\r
- public void changeCase(boolean toUpper, int start, int end)\r
- {\r
- StringBuffer newSeq = new StringBuffer();\r
-\r
- if(end>sequence.length())\r
- end = sequence.length();\r
-\r
- if (start > 0)\r
- {\r
- newSeq.append(sequence.substring(0, start));\r
- }\r
-\r
- if (toUpper)\r
- newSeq.append(sequence.substring(start, end).toUpperCase());\r
- else\r
- newSeq.append(sequence.substring(start, end).toLowerCase());\r
-\r
- if (end < sequence.length())\r
- newSeq.append(sequence.substring(end));\r
-\r
- sequence = newSeq.toString();\r
- }\r
-\r
- public void toggleCase(int start, int end)\r
- {\r
- StringBuffer newSeq = new StringBuffer();\r
-\r
- if(end>sequence.length())\r
- end = sequence.length();\r
-\r
- if (start > 0)\r
- {\r
- newSeq.append(sequence.substring(0, start));\r
- }\r
-\r
- char nextChar;\r
- for(int c=start; c<end; c++)\r
- {\r
- nextChar = sequence.charAt(c);\r
- if(Character.isLetter(nextChar))\r
- {\r
- if(Character.isUpperCase(nextChar))\r
- nextChar = Character.toLowerCase(nextChar);\r
- else\r
- nextChar = Character.toUpperCase(nextChar);\r
- }\r
-\r
-\r
- newSeq.append(nextChar);\r
- }\r
-\r
- if (end < sequence.length())\r
- newSeq.append(sequence.substring(end));\r
-\r
- sequence = newSeq.toString();\r
- }\r
-\r
-}\r
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+package jalview.datamodel;
+
+import java.awt.*;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Sequence implements SequenceI
+{
+ SequenceI datasetSequence;
+ String name;
+ private String sequence;
+ String description;
+ int start;
+ int end;
+ Color color = Color.white;
+ Vector pdbIds;
+ String vamsasId;
+ DBRefEntry [] dbrefs;
+
+ /** This annotation is displayed below the alignment but the
+ * positions are tied to the residues of this sequence */
+ Vector annotation;
+
+ /** DOCUMENT ME!! */
+ public SequenceFeature [] sequenceFeatures;
+
+ /** This array holds hidden sequences
+ * of which this sequence is the representitive member of a group
+ */
+ SequenceGroup hiddenSequences;
+
+ /**
+ * Creates a new Sequence object.
+ *
+ * @param name DOCUMENT ME!
+ * @param sequence DOCUMENT ME!
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ */
+ public Sequence(String name, String sequence, int start, int end)
+ {
+ this.name = name;
+ this.sequence = sequence;
+ this.start = start;
+ this.end = end;
+
+ parseId();
+
+ checkValidRange();
+ }
+
+ com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
+ "[/][0-9]{1,}[-][0-9]{1,}$");
+ com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex(
+ "[0-9]{1,}$");
+
+ void parseId()
+ {
+ // Does sequence have the /start-end signiature?
+ if(limitrx.search(name))
+ {
+ name = limitrx.left();
+ endrx.search(limitrx.stringMatched());
+ setStart( Integer.parseInt( limitrx.stringMatched().substring(1,endrx.matchedFrom()-1 )));
+ setEnd( Integer.parseInt( endrx.stringMatched() ));
+ }
+ }
+
+ void checkValidRange()
+ {
+ if (end < 1)
+ {
+ int endRes = 0;
+ char ch;
+ for (int j = 0; j < sequence.length(); j++)
+ {
+ ch = sequence.charAt(j);
+ if (!jalview.util.Comparison.isGap( (ch)))
+ {
+ endRes++;
+ }
+ }
+ if (endRes > 0)
+ {
+ endRes += start - 1;
+ }
+
+ this.end = endRes;
+ }
+
+ }
+
+ /**
+ * Creates a new Sequence object.
+ *
+ * @param name DOCUMENT ME!
+ * @param sequence DOCUMENT ME!
+ */
+ public Sequence(String name, String sequence)
+ {
+ this(name, sequence, 1, -1);
+ }
+
+ /**
+ * Creates a new Sequence object.
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public Sequence(SequenceI seq)
+ {
+ this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param v DOCUMENT ME!
+ */
+ public void setSequenceFeatures(SequenceFeature [] features)
+ {
+ sequenceFeatures = features;
+ }
+
+ public synchronized void addSequenceFeature(SequenceFeature sf)
+ {
+ if(sequenceFeatures==null)
+ {
+ sequenceFeatures = new SequenceFeature[0];
+ }
+
+ for(int i=0; i<sequenceFeatures.length; i++)
+ {
+ if(sequenceFeatures[i].equals(sf))
+ {
+ return;
+ }
+ }
+
+ SequenceFeature [] temp = new SequenceFeature[sequenceFeatures.length+1];
+ System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
+ temp[sequenceFeatures.length] = sf;
+
+ sequenceFeatures = temp;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceFeature [] getSequenceFeatures()
+ {
+ return sequenceFeatures;
+ }
+
+ public void addPDBId(PDBEntry entry)
+ {
+ if(pdbIds == null)
+ pdbIds = new Vector();
+
+ pdbIds.addElement(entry);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param id DOCUMENT ME!
+ */
+ public void setPDBId(Vector id)
+ {
+ pdbIds = id;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Vector getPDBId()
+ {
+ return pdbIds;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDisplayId(boolean jvsuffix)
+ {
+ StringBuffer result = new StringBuffer(name);
+ if (jvsuffix)
+ {
+ result.append("/" + start + "-" + end);
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ this.parseId();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param start DOCUMENT ME!
+ */
+ public void setStart(int start)
+ {
+ this.start = start;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getStart()
+ {
+ return this.start;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param end DOCUMENT ME!
+ */
+ public void setEnd(int end)
+ {
+ this.end = end;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEnd()
+ {
+ return this.end;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getLength()
+ {
+ return this.sequence.length();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public void setSequence(String seq)
+ {
+ this.sequence = seq;
+ checkValidRange();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getSequence()
+ {
+ return this.sequence;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getSequence(int start, int end)
+ {
+ // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
+ if (start >= sequence.length())
+ {
+ return "";
+ }
+
+ if (end >= sequence.length())
+ {
+ end = sequence.length();
+ }
+
+ return this.sequence.substring(start, end);
+ }
+ /**
+ * make a new Sequence object from start to end (including gaps) over this seqeunce
+ * @param start int
+ * @param end int
+ * @return SequenceI
+ */
+ public SequenceI getSubSequence(int start, int end) {
+ if (start<0)
+ start = 0;
+ String seq = getSequence(start, end);
+ if (seq=="")
+ return null;
+ int nstart = findPosition(start);
+ int nend=findPosition(end-1)-1;
+ // JBPNote - this is an incomplete copy.
+ SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
+ nseq.setDatasetSequence(getDatasetSequence());
+ return nseq;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getCharAt(int i)
+ {
+ if (i < sequence.length())
+ {
+ return sequence.charAt(i);
+ }
+ else
+ {
+ return ' ';
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param desc DOCUMENT ME!
+ */
+ public void setDescription(String desc)
+ {
+ this.description = desc;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param pos DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int findIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = start;
+ int i = 0;
+
+ while ((i < sequence.length()) && (j <= end) && (j <= pos))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.charAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if ((j == end) && (j < pos))
+ {
+ return end + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+ /**
+ * Returns the sequence position for an alignment position
+ *
+ * @param i column index in alignment (from 1)
+ *
+ * @return residue number for residue (left of and) nearest ith column
+ */
+ public int findPosition(int i)
+ {
+ int j = 0;
+ int pos = start;
+ int seqlen=sequence.length();
+ while ((j < i) && (j < seqlen))
+ {
+ if (!jalview.util.Comparison.isGap((sequence.charAt(j))))
+ {
+ pos++;
+ }
+
+ j++;
+ }
+
+ return pos;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int[] gapMap()
+ {
+ // Returns an int array giving the position of each residue in the sequence in the alignment
+ String seq = jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sequence);
+ int[] map = new int[seq.length()];
+ int j = 0;
+ int p = 0;
+
+ while (j < sequence.length())
+ {
+ if (!jalview.util.Comparison.isGap(sequence.charAt(j)))
+ {
+ map[p++] = j;
+ }
+
+ j++;
+ }
+
+ return map;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
+ public void deleteCharAt(int i)
+ {
+ if (i >= sequence.length())
+ {
+ return;
+ }
+
+ sequence = sequence.substring(0, i) + sequence.substring(i + 1);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param j DOCUMENT ME!
+ */
+ public void deleteChars(int i, int j)
+ {
+ if (i >= sequence.length())
+ {
+ return;
+ }
+
+ if (j >= sequence.length())
+ {
+ sequence = sequence.substring(0, i);
+ }
+ else
+ {
+ sequence = sequence.substring(0, i) + sequence.substring(j);
+ }
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ * @param c DOCUMENT ME!
+ * @param chop DOCUMENT ME!
+ */
+ public void insertCharAt(int i, char c)
+ {
+ String tmp = new String(sequence);
+
+ if (i < sequence.length())
+ {
+ sequence = tmp.substring(0, i) + String.valueOf(c) +
+ tmp.substring(i);
+ }
+ else
+ {
+ // JBPNote : padding char at end of sequence. We'll not get away with this when we insert residues, I bet!
+ char[] ch = new char[(1 + i) - sequence.length()];
+
+ for (int j = 0, k = ch.length; j < k; j++)
+ ch[j] = c;
+
+ sequence = tmp + String.valueOf(ch);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
+ public void setColor(Color c)
+ {
+ this.color = c;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Color getColor()
+ {
+ return color;
+ }
+
+ public String getVamsasId()
+ {
+ return vamsasId;
+ }
+
+ public void setVamsasId(String id)
+ {
+ vamsasId = id;
+ }
+
+ public void setDBRef(DBRefEntry [] dbref)
+ {
+ dbrefs = dbref;
+ }
+
+ public DBRefEntry [] getDBRef()
+ {
+ return dbrefs;
+ }
+
+ public void addDBRef(DBRefEntry entry)
+ {
+ if(dbrefs == null)
+ dbrefs = new DBRefEntry[0];
+
+ DBRefEntry [] temp = new DBRefEntry[dbrefs.length+1];
+ System.arraycopy(dbrefs, 0, temp, 0, dbrefs.length);
+
+ temp[temp.length-1] = entry;
+
+ dbrefs = temp;
+ }
+
+ public void setDatasetSequence(SequenceI seq)
+ {
+ datasetSequence = seq;
+ }
+
+ public SequenceI getDatasetSequence()
+ {
+ return datasetSequence;
+ }
+
+ public AlignmentAnnotation [] getAnnotation()
+ {
+ if(annotation==null)
+ return null;
+
+ AlignmentAnnotation [] ret = new AlignmentAnnotation[annotation.size()];
+ for(int r = 0; r<ret.length; r++)
+ ret[r] = (AlignmentAnnotation)annotation.elementAt(r);
+
+ return ret;
+ }
+
+ public void addAlignmentAnnotation(AlignmentAnnotation annotation)
+ {
+ if(this.annotation==null)
+ this.annotation = new Vector();
+
+ this.annotation.addElement( annotation );
+ }
+
+ public SequenceGroup getHiddenSequences()
+ {
+ return hiddenSequences;
+ }
+
+ public void addHiddenSequence(SequenceI seq)
+ {
+ if(hiddenSequences==null)
+ {
+ hiddenSequences = new SequenceGroup();
+ }
+ hiddenSequences.addSequence(seq, false);
+ }
+
+ public void showHiddenSequence(SequenceI seq)
+ {
+ hiddenSequences.deleteSequence(seq, false);
+ if (hiddenSequences.getSize(false) < 1)
+ {
+ hiddenSequences = null;
+ }
+ }
+
+ public void changeCase(boolean toUpper, int start, int end)
+ {
+ StringBuffer newSeq = new StringBuffer();
+
+ if(end>sequence.length())
+ end = sequence.length();
+
+ if (start > 0)
+ {
+ newSeq.append(sequence.substring(0, start));
+ }
+
+ if (toUpper)
+ newSeq.append(sequence.substring(start, end).toUpperCase());
+ else
+ newSeq.append(sequence.substring(start, end).toLowerCase());
+
+ if (end < sequence.length())
+ newSeq.append(sequence.substring(end));
+
+ sequence = newSeq.toString();
+ }
+
+ public void toggleCase(int start, int end)
+ {
+ StringBuffer newSeq = new StringBuffer();
+
+ if(end>sequence.length())
+ end = sequence.length();
+
+ if (start > 0)
+ {
+ newSeq.append(sequence.substring(0, start));
+ }
+
+ char nextChar;
+ for(int c=start; c<end; c++)
+ {
+ nextChar = sequence.charAt(c);
+ if(Character.isLetter(nextChar))
+ {
+ if(Character.isUpperCase(nextChar))
+ nextChar = Character.toLowerCase(nextChar);
+ else
+ nextChar = Character.toUpperCase(nextChar);
+ }
+
+
+ newSeq.append(nextChar);
+ }
+
+ if (end < sequence.length())
+ newSeq.append(sequence.substring(end));
+
+ sequence = newSeq.toString();
+ }
+
+}
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 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 java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.awt.image.*;\r
-import javax.swing.*;\r
-\r
-import jalview.jbgui.*;\r
-\r
-\r
-/**\r
- * Base class for web service client thread and gui\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class WebserviceInfo extends GWebserviceInfo\r
-{\r
-\r
- /** Job is Queued */\r
- public static final int STATE_QUEUING = 0;\r
-\r
- /** Job is Running */\r
- public static final int STATE_RUNNING = 1;\r
-\r
- /** Job has finished with no errors */\r
- public static final int STATE_STOPPED_OK = 2;\r
-\r
- /** Job has been cancelled with no errors */\r
- public static final int STATE_CANCELLED_OK = 3;\r
-\r
- /** job has stopped because of some error */\r
- public static final int STATE_STOPPED_ERROR = 4;\r
-\r
- /** job has failed because of some unavoidable service interruption */\r
- public static final int STATE_STOPPED_SERVERERROR = 5;\r
- int currentStatus = STATE_QUEUING;\r
- Image image;\r
- int angle = 0;\r
- String title = "";\r
- jalview.ws.WSClientI thisService;\r
- boolean serviceIsCancellable;\r
- JInternalFrame frame;\r
- JTabbedPane subjobs=null;\r
- java.util.Vector jobPanes = null;\r
- // tabbed or not\r
- public synchronized int addJobPane() {\r
- JScrollPane jobpane = new JScrollPane();\r
- JTextArea progressText = new JTextArea();\r
- progressText.setFont(new java.awt.Font("Verdana", 0, 10));\r
- progressText.setBorder(null);\r
- progressText.setEditable(false);\r
- progressText.setText("WS Job");\r
- progressText.setLineWrap(true);\r
- progressText.setWrapStyleWord(true);\r
- jobpane.setName("JobPane");\r
- jobpane.getViewport().add(progressText, null);\r
- jobpane.setBorder(null);\r
- if (jobPanes==null) {\r
- jobPanes = new Vector();\r
- }\r
- int newpane = jobPanes.size();\r
- jobPanes.add(jobpane);\r
-\r
- if (newpane==0) {\r
- this.add(jobpane, BorderLayout.CENTER);\r
- } else {\r
- if (newpane==1) {\r
- // revert to a tabbed pane.\r
- JScrollPane firstpane;\r
- this.remove(firstpane=(JScrollPane) jobPanes.get(0));\r
- subjobs=new JTabbedPane();\r
- this.add(subjobs, BorderLayout.CENTER);\r
- subjobs.add(firstpane);\r
- subjobs.setTitleAt(0, firstpane.getName());\r
- }\r
- subjobs.add(jobpane);\r
- }\r
- return newpane; // index for accessor methods below\r
- }\r
- /**\r
- * Creates a new WebserviceInfo object.\r
- *\r
- * @param title short name and job type\r
- * @param info reference or other human readable description\r
- */\r
- public WebserviceInfo(String title, String info)\r
- {\r
- init(title, info, 520, 500);\r
- }\r
-\r
- /**\r
- * Creates a new WebserviceInfo object.\r
- *\r
- * @param title DOCUMENT ME!\r
- * @param info DOCUMENT ME!\r
- * @param width DOCUMENT ME!\r
- * @param height DOCUMENT ME!\r
- */\r
- public WebserviceInfo(String title, String info, int width, int height)\r
- {\r
- init(title, info, width, height);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public jalview.ws.WSClientI getthisService()\r
- {\r
- return thisService;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param newservice DOCUMENT ME!\r
- */\r
- public void setthisService(jalview.ws.WSClientI newservice)\r
- {\r
- thisService = newservice;\r
- serviceIsCancellable = newservice.isCancellable();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param title DOCUMENT ME!\r
- * @param info DOCUMENT ME!\r
- * @param width DOCUMENT ME!\r
- * @param height DOCUMENT ME!\r
- */\r
- void init(String title, String info, int width, int height)\r
- {\r
- frame = new JInternalFrame();\r
- frame.setContentPane(this);\r
- Desktop.addInternalFrame(frame, title, width, height);\r
- frame.setClosable(false);\r
-\r
- this.title = title;\r
- setInfoText(info);\r
-\r
- java.net.URL url = getClass().getResource("/images/logo.gif");\r
- image = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
-\r
- MediaTracker mt = new MediaTracker(this);\r
- mt.addImage(image, 0);\r
-\r
- try\r
- {\r
- mt.waitForID(0);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
-\r
- AnimatedPanel ap = new AnimatedPanel();\r
- titlePanel.add(ap, BorderLayout.CENTER);\r
-\r
- Thread thread = new Thread(ap);\r
- thread.start();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param status integer status from state constants\r
- */\r
- public void setStatus(int status)\r
- {\r
- currentStatus = status;\r
- }\r
- /**\r
- * subjob status indicator\r
- * @param jobpane\r
- * @param status\r
- */\r
- public void setStatus(int jobpane, int status) {\r
- if (jobpane<0 || jobpane>=jobPanes.size()) {\r
- throw new Error("setStatus called for non-existent job pane."+jobpane);\r
- }\r
- switch (status) {\r
- case STATE_QUEUING:\r
- setProgressText(jobpane, "QUEUED");\r
- break;\r
- case STATE_RUNNING:\r
- setProgressText(jobpane, "RUNNING");\r
- break;\r
- case STATE_STOPPED_OK:\r
- setProgressText(jobpane, "FINISHED");\r
- break;\r
- case STATE_CANCELLED_OK:\r
- setProgressText(jobpane, "CANCELLED");\r
- break;\r
- case STATE_STOPPED_ERROR:\r
- setProgressText(jobpane, "BROKEN");\r
- break;\r
- case STATE_STOPPED_SERVERERROR:\r
- setProgressText(jobpane, "ALERT");\r
- break;\r
- default:\r
- setProgressText(jobpane, "UNKNOWN STATE");\r
- }\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getInfoText()\r
- {\r
- return infoText.getText();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param text DOCUMENT ME!\r
- */\r
- public void setInfoText(String text)\r
- {\r
- infoText.setText(text);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param text DOCUMENT ME!\r
- */\r
- public void appendInfoText(String text)\r
- {\r
- infoText.append(text);\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getProgressText(int which)\r
- {\r
- if (jobPanes == null)\r
- addJobPane();\r
- return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().\r
- getComponent(0)).getText();\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param text DOCUMENT ME!\r
- */\r
- public void setProgressText(int which, String text)\r
- {\r
- if (jobPanes == null)\r
- addJobPane();\r
- ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().\r
- getComponent(0)).setText(text);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param text DOCUMENT ME!\r
- */\r
- public void appendProgressText(int which, String text)\r
- {\r
- if (jobPanes == null)\r
- addJobPane();\r
- ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().\r
- getComponent(0)).append(text);\r
- }\r
- /**\r
- * setProgressText(0, text)\r
- */\r
- public void setProgressText(String text)\r
- {\r
- setProgressText(0, text);\r
- }\r
- /**\r
- * appendProgressText(0, text)\r
- */\r
- public void appendProgressText(String text)\r
- {\r
- appendProgressText(0, text);\r
- }\r
- /**\r
- * getProgressText(0)\r
- */\r
- public String getProgressText()\r
- {\r
- return getProgressText(0);\r
- }\r
- /**\r
- * get the tab title for a subjob\r
- * @param which int\r
- * @return String\r
- */\r
- public String getProgressName(int which) {\r
- if (jobPanes==null)\r
- addJobPane();\r
- if (subjobs!=null)\r
- return subjobs.getTitleAt(which);\r
- else\r
- return ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).getName();\r
- }\r
- /**\r
- * set the tab title for a subjob\r
- * @param name String\r
- * @param which int\r
- */\r
- public void setProgressName(String name, int which) {\r
- if (subjobs!=null)\r
- subjobs.setTitleAt(which, name);\r
- else\r
- ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).setName(name);\r
- }\r
-\r
- /**\r
- * Gui action for cancelling the current job, if possible.\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void cancel_actionPerformed(ActionEvent e)\r
- {\r
- if (!serviceIsCancellable)\r
- {\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "This job cannot be cancelled.\nJust close the window.", "Cancel job",\r
- JOptionPane.WARNING_MESSAGE);\r
- }\r
- else\r
- {\r
- frame.setClosable(true);\r
- thisService.cancelJob();\r
- }\r
- }\r
-\r
- public void setResultsReady()\r
- {\r
- frame.setClosable(true);\r
- buttonPanel.remove(cancel);\r
- buttonPanel.add(showResultsNewFrame);\r
- buttonPanel.add(mergeResults);\r
- buttonPanel.setLayout(new GridLayout(2,1,5,5));\r
- buttonPanel.validate();\r
- validate();\r
- }\r
-\r
-\r
- class AnimatedPanel extends JPanel implements Runnable\r
- {\r
- long startTime = 0;\r
- BufferedImage offscreen;\r
-\r
- public void run()\r
- {\r
- startTime = System.currentTimeMillis();\r
- Graphics2D g = null;\r
-\r
- while (currentStatus < STATE_STOPPED_OK)\r
- {\r
- try\r
- {\r
- Thread.sleep(50);\r
-\r
- int units = (int) ( (System.currentTimeMillis() - startTime) /\r
- 10f);\r
- angle += units;\r
- angle %= 360;\r
- startTime = System.currentTimeMillis();\r
-\r
- if (offscreen == null || offscreen.getWidth(this) != getWidth()\r
- || offscreen.getHeight(this) != getHeight())\r
- {\r
- offscreen = new BufferedImage(getWidth(), getHeight(),\r
- BufferedImage.TYPE_INT_ARGB);\r
- g = (Graphics2D) offscreen.getGraphics();\r
- }\r
-\r
- g.setColor(Color.white);\r
- g.fillRect(0, 0, getWidth(), getHeight());\r
-\r
- g.setFont(new Font("Arial", Font.BOLD, 12));\r
- g.setColor(Color.black);\r
-\r
- switch (currentStatus)\r
- {\r
- case STATE_QUEUING:\r
- g.drawString(title.concat(" - queuing"), 60, 30);\r
-\r
- break;\r
-\r
- case STATE_RUNNING:\r
- g.drawString(title.concat(" - running"), 60, 30);\r
-\r
- break;\r
-\r
- case STATE_STOPPED_OK:\r
- g.drawString(title.concat(" - complete"), 60, 30);\r
-\r
- break;\r
-\r
- case STATE_CANCELLED_OK:\r
- g.drawString(title.concat(" - job cancelled!"), 60, 30);\r
-\r
- break;\r
-\r
- case STATE_STOPPED_ERROR:\r
- g.drawString(title.concat(" - job error!"), 60, 30);\r
-\r
- break;\r
-\r
- case STATE_STOPPED_SERVERERROR:\r
- g.drawString(title.concat(" - Server Error! (try later)"),\r
- 60,\r
- 30);\r
-\r
- break;\r
- }\r
-\r
-\r
- if (currentStatus >= STATE_STOPPED_OK)\r
- angle = 0;\r
-\r
- if (image != null)\r
- {\r
- g.rotate(Math.toRadians(angle), 28, 28);\r
- g.drawImage(image, 10, 10, this);\r
- g.rotate( -Math.toRadians(angle), 28, 28);\r
- }\r
-\r
-\r
- repaint();\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
-\r
- cancel.setEnabled(false);\r
- }\r
-\r
- public void paintComponent(Graphics g1)\r
- {\r
- g1.drawImage(offscreen, 0,0,this);\r
- }\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import javax.swing.*;
+
+import jalview.jbgui.*;
+
+
+/**
+ * Base class for web service client thread and gui
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class WebserviceInfo extends GWebserviceInfo
+{
+
+ /** Job is Queued */
+ public static final int STATE_QUEUING = 0;
+
+ /** Job is Running */
+ public static final int STATE_RUNNING = 1;
+
+ /** Job has finished with no errors */
+ public static final int STATE_STOPPED_OK = 2;
+
+ /** Job has been cancelled with no errors */
+ public static final int STATE_CANCELLED_OK = 3;
+
+ /** job has stopped because of some error */
+ public static final int STATE_STOPPED_ERROR = 4;
+
+ /** job has failed because of some unavoidable service interruption */
+ public static final int STATE_STOPPED_SERVERERROR = 5;
+ int currentStatus = STATE_QUEUING;
+ Image image;
+ int angle = 0;
+ String title = "";
+ jalview.ws.WSClientI thisService;
+ boolean serviceIsCancellable;
+ JInternalFrame frame;
+ JTabbedPane subjobs=null;
+ java.util.Vector jobPanes = null;
+ // tabbed or not
+ public synchronized int addJobPane() {
+ JScrollPane jobpane = new JScrollPane();
+ JTextArea progressText = new JTextArea();
+ progressText.setFont(new java.awt.Font("Verdana", 0, 10));
+ progressText.setBorder(null);
+ progressText.setEditable(false);
+ progressText.setText("WS Job");
+ progressText.setLineWrap(true);
+ progressText.setWrapStyleWord(true);
+ jobpane.setName("JobPane");
+ jobpane.getViewport().add(progressText, null);
+ jobpane.setBorder(null);
+ if (jobPanes==null) {
+ jobPanes = new Vector();
+ }
+ int newpane = jobPanes.size();
+ jobPanes.add(jobpane);
+
+ if (newpane==0) {
+ this.add(jobpane, BorderLayout.CENTER);
+ } else {
+ if (newpane==1) {
+ // revert to a tabbed pane.
+ JScrollPane firstpane;
+ this.remove(firstpane=(JScrollPane) jobPanes.get(0));
+ subjobs=new JTabbedPane();
+ this.add(subjobs, BorderLayout.CENTER);
+ subjobs.add(firstpane);
+ subjobs.setTitleAt(0, firstpane.getName());
+ }
+ subjobs.add(jobpane);
+ }
+ return newpane; // index for accessor methods below
+ }
+ /**
+ * Creates a new WebserviceInfo object.
+ *
+ * @param title short name and job type
+ * @param info reference or other human readable description
+ */
+ public WebserviceInfo(String title, String info)
+ {
+ init(title, info, 520, 500);
+ }
+
+ /**
+ * Creates a new WebserviceInfo object.
+ *
+ * @param title DOCUMENT ME!
+ * @param info DOCUMENT ME!
+ * @param width DOCUMENT ME!
+ * @param height DOCUMENT ME!
+ */
+ public WebserviceInfo(String title, String info, int width, int height)
+ {
+ init(title, info, width, height);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public jalview.ws.WSClientI getthisService()
+ {
+ return thisService;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param newservice DOCUMENT ME!
+ */
+ public void setthisService(jalview.ws.WSClientI newservice)
+ {
+ thisService = newservice;
+ serviceIsCancellable = newservice.isCancellable();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param title DOCUMENT ME!
+ * @param info DOCUMENT ME!
+ * @param width DOCUMENT ME!
+ * @param height DOCUMENT ME!
+ */
+ void init(String title, String info, int width, int height)
+ {
+ frame = new JInternalFrame();
+ frame.setContentPane(this);
+ Desktop.addInternalFrame(frame, title, width, height);
+ frame.setClosable(false);
+
+ this.title = title;
+ setInfoText(info);
+
+ java.net.URL url = getClass().getResource("/images/logo.gif");
+ image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
+
+ MediaTracker mt = new MediaTracker(this);
+ mt.addImage(image, 0);
+
+ try
+ {
+ mt.waitForID(0);
+ }
+ catch (Exception ex)
+ {
+ }
+
+ AnimatedPanel ap = new AnimatedPanel();
+ titlePanel.add(ap, BorderLayout.CENTER);
+
+ Thread thread = new Thread(ap);
+ thread.start();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param status integer status from state constants
+ */
+ public void setStatus(int status)
+ {
+ currentStatus = status;
+ }
+ /**
+ * subjob status indicator
+ * @param jobpane
+ * @param status
+ */
+ public void setStatus(int jobpane, int status) {
+ if (jobpane<0 || jobpane>=jobPanes.size()) {
+ throw new Error("setStatus called for non-existent job pane."+jobpane);
+ }
+ switch (status) {
+ case STATE_QUEUING:
+ setProgressName(jobpane+" - QUEUED", jobpane);
+ break;
+ case STATE_RUNNING:
+ setProgressName(jobpane+" - RUNNING", jobpane);
+ break;
+ case STATE_STOPPED_OK:
+ setProgressName(jobpane+" - FINISHED", jobpane);
+ break;
+ case STATE_CANCELLED_OK:
+ setProgressName(jobpane+" - CANCELLED", jobpane);
+ break;
+ case STATE_STOPPED_ERROR:
+ setProgressName(jobpane+" - BROKEN",jobpane);
+ break;
+ case STATE_STOPPED_SERVERERROR:
+ setProgressName(jobpane+" - ALERT", jobpane);
+ break;
+ default:
+ setProgressName(jobpane+" - UNKNOWN STATE", jobpane);
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getInfoText()
+ {
+ return infoText.getText();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param text DOCUMENT ME!
+ */
+ public void setInfoText(String text)
+ {
+ infoText.setText(text);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param text DOCUMENT ME!
+ */
+ public void appendInfoText(String text)
+ {
+ infoText.append(text);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getProgressText(int which)
+ {
+ if (jobPanes == null)
+ addJobPane();
+ return ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
+ getComponent(0)).getText();
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param text DOCUMENT ME!
+ */
+ public void setProgressText(int which, String text)
+ {
+ if (jobPanes == null)
+ addJobPane();
+ ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
+ getComponent(0)).setText(text);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param text DOCUMENT ME!
+ */
+ public void appendProgressText(int which, String text)
+ {
+ if (jobPanes == null)
+ addJobPane();
+ ( (JTextArea) ( (JScrollPane) jobPanes.get(which)).getViewport().
+ getComponent(0)).append(text);
+ }
+ /**
+ * setProgressText(0, text)
+ */
+ public void setProgressText(String text)
+ {
+ setProgressText(0, text);
+ }
+ /**
+ * appendProgressText(0, text)
+ */
+ public void appendProgressText(String text)
+ {
+ appendProgressText(0, text);
+ }
+ /**
+ * getProgressText(0)
+ */
+ public String getProgressText()
+ {
+ return getProgressText(0);
+ }
+ /**
+ * get the tab title for a subjob
+ * @param which int
+ * @return String
+ */
+ public String getProgressName(int which) {
+ if (jobPanes==null)
+ addJobPane();
+ if (subjobs!=null)
+ return subjobs.getTitleAt(which);
+ else
+ return ((JScrollPane) jobPanes.get(which)).getViewport().getComponent(0).getName();
+ }
+ /**
+ * set the tab title for a subjob
+ * @param name String
+ * @param which int
+ */
+ public void setProgressName(String name, int which) {
+ if (subjobs!=null) {
+ subjobs.setTitleAt(which, name);
+ subjobs.revalidate();
+ subjobs.repaint();
+ }
+ JScrollPane c=(JScrollPane) jobPanes.get(which);
+ c.getViewport().getComponent(0).setName(name);
+ c.repaint();
+ }
+
+ /**
+ * Gui action for cancelling the current job, if possible.
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void cancel_actionPerformed(ActionEvent e)
+ {
+ if (!serviceIsCancellable)
+ {
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "This job cannot be cancelled.\nJust close the window.", "Cancel job",
+ JOptionPane.WARNING_MESSAGE);
+ }
+ else
+ {
+ frame.setClosable(true);
+ thisService.cancelJob();
+ }
+ }
+
+ public void setResultsReady()
+ {
+ frame.setClosable(true);
+ buttonPanel.remove(cancel);
+ buttonPanel.add(showResultsNewFrame);
+ buttonPanel.add(mergeResults);
+ buttonPanel.setLayout(new GridLayout(2,1,5,5));
+ buttonPanel.validate();
+ validate();
+ }
+
+
+ class AnimatedPanel extends JPanel implements Runnable
+ {
+ long startTime = 0;
+ BufferedImage offscreen;
+
+ public void run()
+ {
+ startTime = System.currentTimeMillis();
+ Graphics2D g = null;
+
+ while (currentStatus < STATE_STOPPED_OK)
+ {
+ try
+ {
+ Thread.sleep(50);
+
+ int units = (int) ( (System.currentTimeMillis() - startTime) /
+ 10f);
+ angle += units;
+ angle %= 360;
+ startTime = System.currentTimeMillis();
+
+ if (offscreen == null || offscreen.getWidth(this) != getWidth()
+ || offscreen.getHeight(this) != getHeight())
+ {
+ offscreen = new BufferedImage(getWidth(), getHeight(),
+ BufferedImage.TYPE_INT_ARGB);
+ g = (Graphics2D) offscreen.getGraphics();
+ }
+
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getWidth(), getHeight());
+
+ g.setFont(new Font("Arial", Font.BOLD, 12));
+ g.setColor(Color.black);
+
+ switch (currentStatus)
+ {
+ case STATE_QUEUING:
+ g.drawString(title.concat(" - queuing"), 60, 30);
+
+ break;
+
+ case STATE_RUNNING:
+ g.drawString(title.concat(" - running"), 60, 30);
+
+ break;
+
+ case STATE_STOPPED_OK:
+ g.drawString(title.concat(" - complete"), 60, 30);
+
+ break;
+
+ case STATE_CANCELLED_OK:
+ g.drawString(title.concat(" - job cancelled!"), 60, 30);
+
+ break;
+
+ case STATE_STOPPED_ERROR:
+ g.drawString(title.concat(" - job error!"), 60, 30);
+
+ break;
+
+ case STATE_STOPPED_SERVERERROR:
+ g.drawString(title.concat(" - Server Error! (try later)"),
+ 60,
+ 30);
+
+ break;
+ }
+
+
+ if (currentStatus >= STATE_STOPPED_OK)
+ angle = 0;
+
+ if (image != null)
+ {
+ g.rotate(Math.toRadians(angle), 28, 28);
+ g.drawImage(image, 10, 10, this);
+ g.rotate( -Math.toRadians(angle), 28, 28);
+ }
+
+
+ repaint();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ cancel.setEnabled(false);
+ }
+
+ public void paintComponent(Graphics g1)
+ {
+ g1.drawImage(offscreen, 0,0,this);
+ }
+ }
+}
this.seqs = new vamsas.objects.simple.SequenceSet();
this.seqs.setSeqs(seqarray);
}
+ /**
+ *
+ * @return true if getAlignment will return a valid alignment result.
+ */
+ public boolean hasResults() {
+ if (subjobComplete && result!=null && jobs[0].result.isFinished())
+ return true;
+ return false;
+ }
public Object[] getAlignment() {
- if (result!=null) {
+ if (result!=null && result.isFinished()) {
SequenceI[] alseqs=null;
char alseq_gapchar='-';
int alseq_l=0;
nwidth+=width;
}
} else {
- if (jobs[0].subjobComplete && jobs[0].result!=null) {
+ if (jobs[0].hasResults()) {
Object[] alg = jobs[0].getAlignment();
alignment = (SequenceI[]) alg[0];
alorders.add(alg[1]);
af.addSortByOrderMenuItem(WebServiceName + " Ordering",
(AlignmentOrder) alorders.get(0));
} else {
+ // construct a non-redundant ordering set
+ Vector names=new Vector();
+ for (int i=0,l=alorders.size(); i<l; i++) {
+ String orderName = new String("Region "+i);
+ int j=i+1;
+ int r=l;
+ while (j<l) {
+ if (((AlignmentOrder) alorders.get(i)).equals(((AlignmentOrder) alorders.get(j)))) {
+ alorders.remove(j); l--;
+ orderName+=","+j;
+ } else
+ j++;
+ }
+
+ if (i==0 && j==1)
+ names.add(new String(""));
+ else
+ names.add(orderName);
+ }
for (int i=0,l=alorders.size(); i<l; i++) {
- af.addSortByOrderMenuItem(WebServiceName + " Region "+i+" Ordering",
+ af.addSortByOrderMenuItem(WebServiceName + ((String) names.get(i))+" Ordering",
(AlignmentOrder) alorders.get(i));
}
}