From bac273a1ea308a183dcc8ddb4d7385442ec017d8 Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Thu, 23 Dec 2004 15:33:46 +0000 Subject: [PATCH] speed up git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@2157 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- .../artemis/components/FeatureDisplay.java | 59 +++++++++++-------- uk/ac/sanger/artemis/io/StreamSequence.java | 8 +-- uk/ac/sanger/artemis/sequence/Bases.java | 38 ++++++------ 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/uk/ac/sanger/artemis/components/FeatureDisplay.java b/uk/ac/sanger/artemis/components/FeatureDisplay.java index fb681cc78..074137286 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.18 2004-12-23 10:19:05 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.19 2004-12-23 15:33:46 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.18 2004-12-23 10:19:05 tjc Exp $ + * @version $Id: FeatureDisplay.java,v 1.19 2004-12-23 15:33:46 tjc Exp $ **/ public class FeatureDisplay extends EntryGroupPanel @@ -60,21 +60,21 @@ public class FeatureDisplay extends EntryGroupPanel final static public int SCROLLBAR_AT_TOP = 1; final static public int SCROLLBAR_AT_BOTTOM = 2; - final static public int NO_SCROLLBAR = 3; + final static private int NO_SCROLLBAR = 3; - public final static int FORWARD = Bases.FORWARD; - public final static int REVERSE = Bases.REVERSE; + private final static int FORWARD = Bases.FORWARD; + private final static int REVERSE = Bases.REVERSE; - public final static int NO_FRAME = FeatureSegment.NO_FRAME; - public final static int FORWARD_STRAND = FeatureSegment.FORWARD_STRAND; - public final static int REVERSE_STRAND = FeatureSegment.REVERSE_STRAND; - public final static int FORWARD_FRAME_1 = FeatureSegment.FORWARD_FRAME_1; - public final static int FORWARD_FRAME_2 = FeatureSegment.FORWARD_FRAME_2; - public final static int FORWARD_FRAME_3 = FeatureSegment.FORWARD_FRAME_3; - public final static int REVERSE_FRAME_3 = FeatureSegment.REVERSE_FRAME_3; - public final static int REVERSE_FRAME_2 = FeatureSegment.REVERSE_FRAME_2; - public final static int REVERSE_FRAME_1 = FeatureSegment.REVERSE_FRAME_1; - public final static int SCALE_LINE = FeatureSegment.SCALE_LINE; + private final static int NO_FRAME = FeatureSegment.NO_FRAME; + private final static int FORWARD_STRAND = FeatureSegment.FORWARD_STRAND; + private final static int REVERSE_STRAND = FeatureSegment.REVERSE_STRAND; + private final static int FORWARD_FRAME_1 = FeatureSegment.FORWARD_FRAME_1; + private final static int FORWARD_FRAME_2 = FeatureSegment.FORWARD_FRAME_2; + private final static int FORWARD_FRAME_3 = FeatureSegment.FORWARD_FRAME_3; + private final static int REVERSE_FRAME_3 = FeatureSegment.REVERSE_FRAME_3; + private final static int REVERSE_FRAME_2 = FeatureSegment.REVERSE_FRAME_2; + private final static int REVERSE_FRAME_1 = FeatureSegment.REVERSE_FRAME_1; + private final static int SCALE_LINE = FeatureSegment.SCALE_LINE; /** @@ -2133,7 +2133,13 @@ public class FeatureDisplay extends EntryGroupPanel else g.setColor(Color.black); - for(int i = 0 ; i < codon_positions.length ; ++i) + + int length = 0; + if(direction != FORWARD) + length = getBases().getLength(); + + final int codon_positions_length = codon_positions.length; + for(int i = 0; i < codon_positions_length; ++i) { final int codon_base_start = codon_positions[i]; @@ -2147,13 +2153,14 @@ public class FeatureDisplay extends EntryGroupPanel draw_x_position = getLowXPositionOfBase(codon_base_start); else { - final int raw_base_position = - getBases().getComplementPosition(codon_base_start); + final int raw_base_position = length - codon_base_start + 1; +// final int raw_base_position = +// getBases().getComplementPosition(codon_base_start); draw_x_position = getLowXPositionOfBase(raw_base_position); } // draw only if we haven't drawn on the position already - if(last_x_position == -1 || draw_x_position != last_x_position) + if(draw_x_position != last_x_position || last_x_position == -1) { drawOneCodonMark(g, draw_x_position, draw_y_position, direction, mark_height); @@ -4316,7 +4323,7 @@ public class FeatureDisplay extends EntryGroupPanel * than or equal to zero than controls the number of bases that can appear * on screen. See getScaleValue(). **/ - public int getScaleFactor() + protected int getScaleFactor() { return scale_factor; } @@ -4427,7 +4434,7 @@ public class FeatureDisplay extends EntryGroupPanel * the sequence length. If hard_left_edge is true this method will always * return the same as getForwardBaseAtLeftEdge*(. **/ - public int getFirstVisibleForwardBase() + protected int getFirstVisibleForwardBase() { if(left_edge_base < 1) return 1; @@ -4442,7 +4449,7 @@ public class FeatureDisplay extends EntryGroupPanel * being display in the forward direction will be the reverse strand if * rev_comp_display is true. **/ - public int getForwardBaseAtLeftEdge() + protected int getForwardBaseAtLeftEdge() { return left_edge_base; } @@ -4476,7 +4483,7 @@ public class FeatureDisplay extends EntryGroupPanel * edge of the canvas. The number returned will always be > 1 and < the * sequence length. **/ - public int getLastVisibleForwardBase() + protected int getLastVisibleForwardBase() { final int possible_last_base = (int)(getForwardBaseAtLeftEdge() + getMaxVisibleBases()); @@ -4558,7 +4565,7 @@ public class FeatureDisplay extends EntryGroupPanel * Return the number of bases we can fit on screen at once, ie the number * that will fit side by side on the canvas. **/ - public int getMaxVisibleBases() + protected int getMaxVisibleBases() { return(int)(getWidth() / getScaleValue()); } @@ -4590,7 +4597,7 @@ public class FeatureDisplay extends EntryGroupPanel * Scroll and scale the display so that the given first base is at the left * edge of the screen and the given last base is at the right edge. **/ - public void setFirstAndLastBase(final int first, final int last) + protected void setFirstAndLastBase(final int first, final int last) { left_edge_base = first; setScaleValue(1.0F * getWidth() /(last - first + 1)); @@ -4600,7 +4607,7 @@ public class FeatureDisplay extends EntryGroupPanel * Scroll the display so that the given first base is at the left edge of * the screen. **/ - public void setFirstBase(int base_position) + protected void setFirstBase(int base_position) { if(base_position > getSequenceLength()) base_position = getSequenceLength(); diff --git a/uk/ac/sanger/artemis/io/StreamSequence.java b/uk/ac/sanger/artemis/io/StreamSequence.java index 3ab163826..64d297df0 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.2 2004-12-23 10:19:05 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/StreamSequence.java,v 1.3 2004-12-23 15:33:46 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.2 2004-12-23 10:19:05 tjc Exp $ + * @version $Id: StreamSequence.java,v 1.3 2004-12-23 15:33:46 tjc Exp $ **/ public abstract class StreamSequence @@ -94,11 +94,11 @@ 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); + sequence.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 5bf37e03a..278c12a73 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.6 2004-12-23 10:19:05 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.7 2004-12-23 15:33:46 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.6 2004-12-23 10:19:05 tjc Exp $ */ + * @version $Id: Bases.java,v 1.7 2004-12-23 15:33:46 tjc Exp $ */ public class Bases { /** @@ -167,15 +167,15 @@ public class Bases { **/ public static int getIndexOfBase (final char base) { switch (base) { - case 't': - case 'u': - return 0; case 'c': return 1; case 'a': return 2; case 'g': return 3; + case 't': + case 'u': + return 0; } return 4; @@ -510,13 +510,13 @@ public class Bases { int current_return_array_index = 0; -// final char sequence_string[] = -// getSequence().getSubSequence(1, getLength()).toCharArray(); + final String sequence_string = + getSequence().getSubSequence(1, getLength()); - final char sequence_string[] = - getSequence().getCharSubSequence(1, getLength()); +// final char sequence_string[] = +// getSequence().getCharSubSequence(1, getLength()); - final int sequence_string_length = sequence_string.length; + 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; @@ -957,6 +957,7 @@ public class Bases { * or 'x' (any base) is 'n'. **/ public static char complement (final char base) { + switch (base) { case 'a': case 'A': return 't'; case 't': case 'T': case 'u': case 'U': return 'a'; @@ -996,31 +997,31 @@ public class Bases { * complement of those three bases is a stop codon. * Codons that contain an X are considered to be stop codons. **/ - private static boolean isStopCodon (final char[] sequence, + private static boolean isStopCodon (final String sequence_string, final int start_index, final int direction) { final char translation; if (direction == FORWARD) { - final char first_letter = sequence[start_index]; - final char second_letter = sequence[start_index + 1]; - final char third_letter = sequence[start_index + 2]; + final char first_letter = sequence_string.charAt (start_index); + final char second_letter = sequence_string.charAt (start_index + 1); + final char third_letter = sequence_string.charAt (start_index + 2); if (first_letter == 'x' || second_letter == 'x' || third_letter == 'x') { // codons that contain an X are considered to be stop codons. return true; } - + translation = AminoAcidSequence.getCodonTranslation (first_letter, second_letter, third_letter); } else { final char first_letter = - complement (sequence[start_index - 2]); + complement (sequence_string.charAt (start_index - 2)); final char second_letter = - complement (sequence[start_index - 1]); + complement (sequence_string.charAt (start_index - 1)); final char third_letter = - complement (sequence[start_index]); + complement (sequence_string.charAt (start_index)); if (first_letter == 'x' || second_letter == 'x' || third_letter == 'x') { // codons that contain an X are considered to be stop codons. @@ -1039,6 +1040,7 @@ public class Bases { } } + /** * Check a three character substring and return true if and only if the * three bases are legal (see isLegalBase ()). -- GitLab