From 3930aaa1dce6127fdfacf0d8f01c323f2c1dc508 Mon Sep 17 00:00:00 2001
From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04>
Date: Tue, 17 Mar 2009 17:47:42 +0000
Subject: [PATCH] fix/revert for speed when zoomed out and changing the window
 size

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10152 ee4ac58c-ac51-4696-9907-e4b3aa274f04
---
 .../artemis/plot/AGWindowAlgorithm.java       | 14 ++++-----
 .../artemis/plot/GCSDWindowAlgorithm.java     | 31 +++++++------------
 .../artemis/plot/GCWindowAlgorithm.java       | 21 +++++++------
 3 files changed, 29 insertions(+), 37 deletions(-)

diff --git a/uk/ac/sanger/artemis/plot/AGWindowAlgorithm.java b/uk/ac/sanger/artemis/plot/AGWindowAlgorithm.java
index a900194fb..98d6d99a0 100644
--- a/uk/ac/sanger/artemis/plot/AGWindowAlgorithm.java
+++ b/uk/ac/sanger/artemis/plot/AGWindowAlgorithm.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/plot/AGWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/AGWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.plot;
@@ -37,7 +37,7 @@ import uk.ac.sanger.artemis.sequence.*;
  *  constructor.
  *
  *  @author Kim Rutherford
- *  @version $Id: AGWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ *  @version $Id: AGWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  **/
 
 public class AGWindowAlgorithm extends BaseAlgorithm {
@@ -59,18 +59,18 @@ public class AGWindowAlgorithm extends BaseAlgorithm {
    *    this array.
    **/
   public void getValues (int start, int end, final float [] values) {
-    final char[] sequence;
+    final String sequence;
 
     try {
-      sequence = getStrand ().getBases().getSubSequenceC (new Range (start, end), getStrand().getDirection());
+      sequence = getStrand ().getSubSequence (new Range (start, end));
     } catch (OutOfRangeException e) {
       throw new Error ("internal error - unexpected exception: " + e);
     }
 
     float gc_count = 0;
 
-    for (int i = 0 ; i < sequence.length ; ++i) {
-      final char this_char = sequence[i];
+    for (int i = 0 ; i < sequence.length () ; ++i) {
+      final char this_char = sequence.charAt (i);
 //      System.out.println (this_char);
 
       if (this_char == 'g' || this_char == 'a') {
@@ -80,7 +80,7 @@ public class AGWindowAlgorithm extends BaseAlgorithm {
 
 //    System.out.println ("start: " + start + " end: " + end + " returning: " + gc_count/sequence.length ()); 
 
-    values[0] = gc_count/sequence.length * 100;
+    values[0] = gc_count/sequence.length () * 100;
   }
 
   /**
diff --git a/uk/ac/sanger/artemis/plot/GCSDWindowAlgorithm.java b/uk/ac/sanger/artemis/plot/GCSDWindowAlgorithm.java
index 70ae4e9bd..7b08e0d2a 100644
--- a/uk/ac/sanger/artemis/plot/GCSDWindowAlgorithm.java
+++ b/uk/ac/sanger/artemis/plot/GCSDWindowAlgorithm.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/plot/GCSDWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/GCSDWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.plot;
@@ -39,7 +39,7 @@ import uk.ac.sanger.artemis.sequence.*;
  *  to use is set in the constructor.
  *
  *  @author Kim Rutherford
- *  @version $Id: GCSDWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ *  @version $Id: GCSDWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  **/
 
 public class GCSDWindowAlgorithm extends BaseAlgorithm {
@@ -82,18 +82,18 @@ public class GCSDWindowAlgorithm extends BaseAlgorithm {
       }
     }
 
-    final char[] sequence;
+    final String sequence;
 
     try {
-      sequence = getStrand ().getBases().getSubSequenceC (new Range (start, end), getStrand().getDirection());
+      sequence = getStrand ().getSubSequence (new Range (start, end));
     } catch (OutOfRangeException e) {
       throw new Error ("internal error - unexpected exception: " + e);
     }
 
     float gc_count = 0;
 
-    for (int i = 0 ; i < sequence.length  ; ++i) {
-      final char this_char = sequence[i];
+    for (int i = 0 ; i < sequence.length () ; ++i) {
+      final char this_char = sequence.charAt (i);
 //      System.out.println (this_char);
 
       if (this_char == 'g' || this_char == 'c') {
@@ -101,7 +101,7 @@ public class GCSDWindowAlgorithm extends BaseAlgorithm {
       }
     }
 
-    final float gc_content = gc_count/sequence.length * 100;
+    final float gc_content = gc_count/sequence.length () * 100;
 
     final float gc_average =
       getStrand ().getBases ().getAverageGCPercent ();
@@ -122,17 +122,8 @@ public class GCSDWindowAlgorithm extends BaseAlgorithm {
 
     final int sequence_length = getStrand ().getBases ().getLength ();
 
-    //final String bases = getStrand ().getBases ().toString ();
-    char[] bases = null;
-    try
-    {
-      bases = getStrand ().getBases ().getSubSequenceC(new Range(1,sequence_length), Strand.FORWARD);
-    }
-    catch(OutOfRangeException e)
-    {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
-    }
+    final String bases = getStrand ().getBases ().toString ();
+
     // the number of windows to search
     final int window_count = sequence_length - window_size;
 
@@ -150,14 +141,14 @@ public class GCSDWindowAlgorithm extends BaseAlgorithm {
 
     for (int i = - window_size ; i < window_count ; ++i) {
       if (i > 0) {
-        final char previous_char = bases[i - 1];
+        final char previous_char = bases.charAt (i - 1);
 
         if (previous_char == 'g' || previous_char == 'c') {
           --current_gc_count;
         }
       }
 
-      final char new_char = bases[i + window_size];
+      final char new_char = bases.charAt (i + window_size);
 
       if (new_char == 'g' || new_char == 'c') {
         ++current_gc_count;
diff --git a/uk/ac/sanger/artemis/plot/GCWindowAlgorithm.java b/uk/ac/sanger/artemis/plot/GCWindowAlgorithm.java
index a608deab7..a4b5bd362 100644
--- a/uk/ac/sanger/artemis/plot/GCWindowAlgorithm.java
+++ b/uk/ac/sanger/artemis/plot/GCWindowAlgorithm.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/plot/GCWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/plot/GCWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  **/
 
 package uk.ac.sanger.artemis.plot;
@@ -37,7 +37,7 @@ import uk.ac.sanger.artemis.sequence.*;
  *  constructor.
  *
  *  @author Kim Rutherford
- *  @version $Id: GCWindowAlgorithm.java,v 1.3 2009-03-13 20:39:37 tjc Exp $
+ *  @version $Id: GCWindowAlgorithm.java,v 1.4 2009-03-17 17:47:42 tjc Exp $
  **/
 
 public class GCWindowAlgorithm extends BaseAlgorithm {
@@ -59,27 +59,28 @@ public class GCWindowAlgorithm extends BaseAlgorithm {
    *    this array.
    **/
   public void getValues (int start, int end, final float [] values) {
-    final char[] sequence;
+    final String sequence;
 
     try {
-      sequence = getStrand ().getBases().getSubSequenceC(
-          new Range (start, end), getStrand ().getDirection());
+      sequence = getStrand ().getSubSequence (new Range (start, end));
     } catch (OutOfRangeException e) {
       throw new Error ("internal error - unexpected exception: " + e);
     }
 
     float gc_count = 0;
 
-    final int sequence_length = sequence.length;
-    for (int i = 0 ; i < sequence_length ; ++i) 
-    {
-      if (sequence[i] == 'g' || sequence[i] == 'c') 
+    for (int i = 0 ; i < sequence.length () ; ++i) {
+      final char this_char = sequence.charAt (i);
+//      System.out.println (this_char);
+
+      if (this_char == 'g' || this_char == 'c') {
         ++gc_count;
+      }
     }
 
 //    System.out.println ("start: " + start + " end: " + end + " returning: " + gc_count/sequence.length ()); 
 
-    values[0] = gc_count/sequence_length * 100;
+    values[0] = gc_count/sequence.length () * 100;
   }
 
   /**
-- 
GitLab