diff --git a/uk/ac/sanger/artemis/components/FeatureDisplay.java b/uk/ac/sanger/artemis/components/FeatureDisplay.java index 7240955480c9972b2130230c4cc958ac1fef0dbb..195804790b7d8ad89a89ebadcc31a959663ec57e 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.16 2004-12-21 13:46:47 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.17 2004-12-22 13:28:31 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.16 2004-12-21 13:46:47 tjc Exp $ + * @version $Id: FeatureDisplay.java,v 1.17 2004-12-22 13:28:31 tjc Exp $ **/ public class FeatureDisplay extends EntryGroupPanel @@ -1988,7 +1988,7 @@ public class FeatureDisplay extends EntryGroupPanel final int frame_line = getFrameDisplayLine(FORWARD_FRAME_1 + i); final AminoAcidSequence this_frame_translation = - strand.getTranslation(newRange(start_base, end_base), false); + strand.getSpacedTranslation(newRange(start_base, end_base), false); final String this_frame_translation_string = this_frame_translation.toString(); @@ -2027,7 +2027,7 @@ public class FeatureDisplay extends EntryGroupPanel final int frame_line = getFrameDisplayLine(REVERSE_FRAME_1 - i); final AminoAcidSequence this_frame_translation = - strand.getTranslation(newRange(start_base, end_base), false); + strand.getSpacedTranslation(newRange(start_base, end_base), false); final String this_frame_translation_string = this_frame_translation.toString(); @@ -2051,11 +2051,9 @@ public class FeatureDisplay extends EntryGroupPanel * @param direction The direction to draw the letters in(see the * frame_start parameter). **/ - private void drawCodonLine(Graphics g, - int frame_start, - int line_number, - String codons, - int direction) + private void drawCodonLine(Graphics g, int frame_start, + int line_number, String codons, + int direction) { final int offset; @@ -2064,26 +2062,22 @@ public class FeatureDisplay extends EntryGroupPanel else offset = 0; - final String upper_case_codons = codons.toUpperCase(); + codons = codons.toUpperCase(); final int draw_y_position = line_number * getLineHeight(); - - // draw each AA letter - for(int i = 0 ; i < upper_case_codons.length() ; ++i) + final int draw_x_position; + + if(direction == REVERSE) { - int draw_x_position = - (int)((offset + frame_start + 3 * i + 1) * getScaleValue()); + draw_x_position = getLowXPositionOfBase(getLastVisibleForwardBase()) - + (int)((offset+frame_start+codons.length()) * getScaleValue()); - if(direction == REVERSE) - { - // draw in the opposite direction - draw_x_position = - getLowXPositionOfBase(getLastVisibleForwardBase()) - - draw_x_position; - } - - g.drawString(upper_case_codons.substring(i,i+1), - draw_x_position, draw_y_position + getFontAscent() + 1); + codons = reverse(codons); } + else + draw_x_position = (int)((offset + frame_start + 1) * getScaleValue()); + + g.drawString(codons, draw_x_position, + draw_y_position + getFontAscent() + 1); } /** diff --git a/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java b/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java index c1c8e56dd1ad72e232c6052f195dfc15365b324e..3ec8812f0ff4f93d3de21a8fb194daa0d7a8c8a9 100644 --- a/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java +++ b/uk/ac/sanger/artemis/sequence/AminoAcidSequence.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/AminoAcidSequence.java,v 1.4 2004-12-21 10:28:02 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java,v 1.5 2004-12-22 13:28:31 tjc Exp $ */ package uk.ac.sanger.artemis.sequence; @@ -33,7 +33,7 @@ import uk.ac.sanger.artemis.util.*; * Objects of this class represent a string of amino acids. * * @author Kim Rutherford - * @version $Id: AminoAcidSequence.java,v 1.4 2004-12-21 10:28:02 tjc Exp $ + * @version $Id: AminoAcidSequence.java,v 1.5 2004-12-22 13:28:31 tjc Exp $ **/ public class AminoAcidSequence @@ -77,7 +77,36 @@ public class AminoAcidSequence else aa_buffer.append (aa); } + return new AminoAcidSequence(aa_buffer.toString()); + } + /** + * Translate a sequence of bases into the corresponding single letter amino + * acid codes and appending 2 spaces after each amino acid character. + * @param bases The bases to translated. If the string length is not a + * multiple of three the last codon is incomplete and will not be + * translated. + * @param unknown_is_x If this parameter is true codons that contain + * ambiguous bases will be translated as 'x', if false they will be + * translated as '.' + * @return The translated sequence in one letter abbreviated form. + **/ + public static AminoAcidSequence getSpacedTranslation(final String bases, + final boolean unknown_is_x) + { + final StringBuffer aa_buffer = new StringBuffer(); + final int number_of_codons = bases.length() / 3; + for(int i = 0 ; i < number_of_codons * 3 ; i += 3) + { + final char aa = getCodonTranslation(bases.charAt(i), + bases.charAt(i+1), + bases.charAt(i+2)); + if(aa == '.' && unknown_is_x) + aa_buffer.append('x'); + else + aa_buffer.append(aa); + aa_buffer.append(" "); + } return new AminoAcidSequence(aa_buffer.toString()); } diff --git a/uk/ac/sanger/artemis/sequence/Bases.java b/uk/ac/sanger/artemis/sequence/Bases.java index 4a78d30ae76a178c7435d17bc6cff1fa3714baca..d16d56aca939321fd6a504425b7e6f023eae1feb 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.2 2004-11-17 13:20:10 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.3 2004-12-22 13:28:31 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.2 2004-11-17 13:20:10 tjc Exp $ */ + * @version $Id: Bases.java,v 1.3 2004-12-22 13:28:31 tjc Exp $ */ public class Bases { /** @@ -249,6 +249,17 @@ public class Bases { return AminoAcidSequence.getTranslation (sub_sequence, unknown_is_x); } + + public AminoAcidSequence getSpacedTranslation (final Range range, + final int direction, + final boolean unknown_is_x) { + // getSubSequence () will return a sequence going in the right direction + // so we don't have to worry. + final String sub_sequence = getSubSequence (range, direction); + + return AminoAcidSequence.getSpacedTranslation (sub_sequence, unknown_is_x); + } + /** * Return an array containing the positions of the codons that match the * strings given by the query_codons argument. Only those codons that are diff --git a/uk/ac/sanger/artemis/sequence/Strand.java b/uk/ac/sanger/artemis/sequence/Strand.java index 51984032bd1e2c4b0c6d2552ff5bbb0f98936270..ff96b9b3f31394a78ed005780895751d9f974dfd 100644 --- a/uk/ac/sanger/artemis/sequence/Strand.java +++ b/uk/ac/sanger/artemis/sequence/Strand.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/Strand.java,v 1.1 2004-06-09 09:52:27 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Strand.java,v 1.2 2004-12-22 13:28:31 tjc Exp $ */ package uk.ac.sanger.artemis.sequence; @@ -39,7 +39,7 @@ import org.biojava.bio.symbol.IllegalSymbolException; * what direction the Strand represents. * * @author Kim Rutherford - * @version $Id: Strand.java,v 1.1 2004-06-09 09:52:27 tjc Exp $ + * @version $Id: Strand.java,v 1.2 2004-12-22 13:28:31 tjc Exp $ **/ public class Strand { @@ -583,11 +583,17 @@ public class Strand { * translated as '.' * @return The translated sequence in one letter abbreviated form. **/ - public AminoAcidSequence getTranslation (final Range range, - final boolean unknown_is_x) { + public AminoAcidSequence getTranslation(final Range range, + final boolean unknown_is_x) { return getBases ().getTranslation (range, getDirection (), unknown_is_x); } + public AminoAcidSequence getSpacedTranslation(final Range range, + final boolean unknown_is_x) { + return getBases ().getSpacedTranslation (range, getDirection (), unknown_is_x); + } + + /** * Return a sub-sequence of bases from this strand. * @param range The inclusive range of bases to return.