From 066a8f6082d220728f486c753f2260171e4861a0 Mon Sep 17 00:00:00 2001
From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04>
Date: Thu, 23 Dec 2004 10:19:05 +0000
Subject: [PATCH] use char[] for getting at seq stop codons

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@2156 ee4ac58c-ac51-4696-9907-e4b3aa274f04
---
 .../artemis/components/FeatureDisplay.java    | 31 +++++++++----------
 uk/ac/sanger/artemis/io/BioJavaSequence.java  |  9 ++++++
 uk/ac/sanger/artemis/io/CorbaSequence.java    | 13 ++++++--
 uk/ac/sanger/artemis/io/Sequence.java         |  6 ++--
 uk/ac/sanger/artemis/io/StreamSequence.java   | 12 +++++--
 uk/ac/sanger/artemis/sequence/Bases.java      | 10 ++++--
 6 files changed, 55 insertions(+), 26 deletions(-)

diff --git a/uk/ac/sanger/artemis/components/FeatureDisplay.java b/uk/ac/sanger/artemis/components/FeatureDisplay.java
index 195804790..fb681cc78 100644
--- a/uk/ac/sanger/artemis/components/FeatureDisplay.java
+++ b/uk/ac/sanger/artemis/components/FeatureDisplay.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.17 2004-12-22 13:28:31 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.18 2004-12-23 10:19:05 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.components;
@@ -45,7 +45,7 @@ import javax.swing.JComponent;
  *  This component is used for displaying an Entry.
  *
  *  @author Kim Rutherford
- *  @version $Id: FeatureDisplay.java,v 1.17 2004-12-22 13:28:31 tjc Exp $
+ *  @version $Id: FeatureDisplay.java,v 1.18 2004-12-23 10:19:05 tjc Exp $
  **/
 
 public class FeatureDisplay extends EntryGroupPanel
@@ -2128,6 +2128,11 @@ public class FeatureDisplay extends EntryGroupPanel
     // used to remember the position of the previously drawn codon
     int last_x_position = -1;
 
+    if(height_percent < 100)
+      g.setColor(start_codon_colour);
+    else
+      g.setColor(Color.black);
+
     for(int i = 0 ; i < codon_positions.length ; ++i) 
     {
       final int codon_base_start = codon_positions[i];
@@ -2150,12 +2155,8 @@ public class FeatureDisplay extends EntryGroupPanel
       // draw only if we haven't drawn on the position already
       if(last_x_position == -1 || draw_x_position != last_x_position) 
       {
-        if(height_percent < 100) 
-          drawOneCodonMark(g, draw_x_position, draw_y_position,
-                            direction, mark_height, start_codon_colour);
-        else 
-          drawOneCodonMark(g, draw_x_position, draw_y_position,
-                            direction, mark_height, Color.black);
+        drawOneCodonMark(g, draw_x_position, draw_y_position,
+                         direction, mark_height);
 
         last_x_position = draw_x_position;
       }
@@ -2195,32 +2196,28 @@ public class FeatureDisplay extends EntryGroupPanel
    *  @param direction If this is FORWARD the line is draw from the y position
    *    to the right, otherwise it is drawn to the left.
    *  @param height The height in pixels of the codon mark.
-   *  @param colour The colour to use when drawing the mark.
    **/
   private void drawOneCodonMark(final Graphics g,
                                  final int x_pos, final int y_pos,
                                  final int direction,
-                                 final int height,
-                                 final Color colour) 
+                                 final int height)
   {
-    g.setColor(colour);
-
     if(getScaleFactor() == 1) 
     {
       // draw a line three pixels/bases wide
       if(direction == FORWARD) 
       {
         g.drawLine(x_pos + 1, y_pos,
-                    x_pos + 1, y_pos + height - 1);
+                   x_pos + 1, y_pos + height - 1);
         g.drawLine(x_pos + 2, y_pos,
-                    x_pos + 2, y_pos + height - 1);
+                   x_pos + 2, y_pos + height - 1);
       } 
       else
       {
         g.drawLine(x_pos - 1, y_pos,
-                    x_pos - 1, y_pos + height - 1);
+                   x_pos - 1, y_pos + height - 1);
         g.drawLine(x_pos - 2, y_pos,
-                    x_pos - 2, y_pos + height - 1);
+                   x_pos - 2, y_pos + height - 1);
       }
     }
     g.drawLine(x_pos, y_pos, x_pos, y_pos + height - 1);
diff --git a/uk/ac/sanger/artemis/io/BioJavaSequence.java b/uk/ac/sanger/artemis/io/BioJavaSequence.java
index 26c61d2cc..2ef57069a 100644
--- a/uk/ac/sanger/artemis/io/BioJavaSequence.java
+++ b/uk/ac/sanger/artemis/io/BioJavaSequence.java
@@ -99,6 +99,15 @@ public class BioJavaSequence implements Sequence
 	return subSeq;
     }
 
+  public char[] getCharSubSequence (int start, int end)
+  {
+    char[] dst = new char[end-start];
+    StringBuffer buff = new StringBuffer(getSubSequence(start,end));
+    buff.getChars(start, end, dst, 0);
+    return dst;
+  }
+
+
     public void setFromString(String seqString)
         throws ReadOnlyException, IllegalSymbolException
     {
diff --git a/uk/ac/sanger/artemis/io/CorbaSequence.java b/uk/ac/sanger/artemis/io/CorbaSequence.java
index ecac29609..de196f82d 100644
--- a/uk/ac/sanger/artemis/io/CorbaSequence.java
+++ b/uk/ac/sanger/artemis/io/CorbaSequence.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/CorbaSequence.java,v 1.1 2004-06-09 09:49:01 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/CorbaSequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  **/
 
 package uk.ac.sanger.artemis.io;
@@ -34,7 +34,7 @@ import java.io.IOException;
  *  object.
  *
  *  @author Kim Rutherford
- *  @version $Id: CorbaSequence.java,v 1.1 2004-06-09 09:49:01 tjc Exp $
+ *  @version $Id: CorbaSequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  **/
 
 public class CorbaSequence implements Sequence {
@@ -73,6 +73,15 @@ public class CorbaSequence implements Sequence {
     }
   }
 
+  public char[] getCharSubSequence (int start, int end)
+  {
+    char[] dst = new char[end-start+1];
+    StringBuffer buff = new StringBuffer(sequence);
+    buff.getChars(start-1, end, dst, 0);
+    return dst;
+  }
+
+
   /**
    *  Set this sequence to hold the bases in the given String - throws
    *  ReadOnlyException for CorbaSequence objects.
diff --git a/uk/ac/sanger/artemis/io/Sequence.java b/uk/ac/sanger/artemis/io/Sequence.java
index 8a5b09572..6699f31a3 100644
--- a/uk/ac/sanger/artemis/io/Sequence.java
+++ b/uk/ac/sanger/artemis/io/Sequence.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/Sequence.java,v 1.1 2004-06-09 09:50:27 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/Sequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.io;
@@ -32,7 +32,7 @@ import org.biojava.bio.symbol.IllegalSymbolException;
  *  Sequence interface
  *
  *  @author Kim Rutherford
- *  @version $Id: Sequence.java,v 1.1 2004-06-09 09:50:27 tjc Exp $
+ *  @version $Id: Sequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  *
  */
 
@@ -45,6 +45,8 @@ public interface Sequence
    **/
   String getSubSequence(int start, int end);
 
+  char[] getCharSubSequence(int start, int end);
+
   /**
    *  Set this sequence to hold the bases in the given String.
    *  @exception ReadOnlyException If this Sequence cannot be changed.
diff --git a/uk/ac/sanger/artemis/io/StreamSequence.java b/uk/ac/sanger/artemis/io/StreamSequence.java
index 3479a8569..3ab163826 100644
--- a/uk/ac/sanger/artemis/io/StreamSequence.java
+++ b/uk/ac/sanger/artemis/io/StreamSequence.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/StreamSequence.java,v 1.1 2004-06-09 09:50:37 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/StreamSequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.io;
@@ -33,7 +33,7 @@ import java.io.Writer;
  *  stream.
  *
  *  @author Kim Rutherford
- *  @version $Id: StreamSequence.java,v 1.1 2004-06-09 09:50:37 tjc Exp $
+ *  @version $Id: StreamSequence.java,v 1.2 2004-12-23 10:19:05 tjc Exp $
  **/
 
 public abstract class StreamSequence
@@ -91,6 +91,14 @@ public abstract class StreamSequence
     }
   }
 
+  public char[] getCharSubSequence (int start, int end) 
+  {
+    char[] dst = new char[end-start+1];
+    StringBuffer buff = new StringBuffer(sequence);
+    buff.getChars(start-1, end, dst, 0); 
+    return dst;
+  }
+
   /**
    *  Set this sequence to hold the bases in the given String.
    **/
diff --git a/uk/ac/sanger/artemis/sequence/Bases.java b/uk/ac/sanger/artemis/sequence/Bases.java
index 4cfbc69b8..5bf37e03a 100644
--- a/uk/ac/sanger/artemis/sequence/Bases.java
+++ b/uk/ac/sanger/artemis/sequence/Bases.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.5 2004-12-22 18:39:17 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.6 2004-12-23 10:19:05 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.sequence;
@@ -45,7 +45,7 @@ import java.util.Iterator;
  *  non-base letter returns '@'.
  *
  *  @author Kim Rutherford
- *  @version $Id: Bases.java,v 1.5 2004-12-22 18:39:17 tjc Exp $ */
+ *  @version $Id: Bases.java,v 1.6 2004-12-23 10:19:05 tjc Exp $ */
 
 public class Bases {
   /**
@@ -510,8 +510,12 @@ public class Bases {
 
     int current_return_array_index = 0;
 
+//  final char sequence_string[] =
+//    getSequence().getSubSequence(1, getLength()).toCharArray();
+
     final char sequence_string[] =
-      getSequence().getSubSequence(1, getLength()).toCharArray();
+      getSequence().getCharSubSequence(1, getLength());
+
     final int sequence_string_length = sequence_string.length;
     final int range_start_index = real_range.getStart () - 1;
     final int range_end_index = real_range.getEnd () - 1;
-- 
GitLab