From 464f89f1ad86859fe19c489817cf1851bde58ef9 Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Wed, 17 Nov 2004 13:20:55 +0000 Subject: [PATCH] genetic code tables git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@2059 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- etc/options | 170 ++++- uk/ac/sanger/artemis/Feature.java | 16 +- uk/ac/sanger/artemis/Options.java | 64 +- .../artemis/components/BasePlotGroup.java | 50 +- .../artemis/components/FeatureDisplay.java | 34 +- uk/ac/sanger/artemis/components/Splash.java | 155 +++- .../artemis/sequence/AminoAcidSequence.java | 691 ++++++++++-------- uk/ac/sanger/artemis/sequence/Bases.java | 13 +- 8 files changed, 801 insertions(+), 392 deletions(-) diff --git a/etc/options b/etc/options index ec1fb28e2..7227aa4ce 100644 --- a/etc/options +++ b/etc/options @@ -2,7 +2,7 @@ # (Note that comment lines start with a hash (#) symbol) -# $Header: //tmp/pathsoft/artemis/etc/options,v 1.12 2004-10-05 15:45:06 tjc Exp $ +# $Header: //tmp/pathsoft/artemis/etc/options,v 1.13 2004-11-17 13:20:55 tjc Exp $ # This file should contain option settings that look like this: # @@ -100,6 +100,174 @@ prokaryotic_start_codons = atg gtg ttg # d d e e \ # g g g g +# +# Genetic Codes : +# http://www3.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi?mode=t#SG1 +# http://www.ncbi.nlm.nih.gov/collab/FT/#7.5.5 +# + +genetic_codes = \ + Standard \ + Vertebrate_Mitochondrial \ + Yeast_Mitochondrial \ + Mold,_Protozoan,_Coelenterate_Mitochondrial_and_Mycoplasma/Spiroplasma \ + Invertebrate_Mitochondrial \ + Ciliate_Dasycladacean_and_Hexamita \ + - \ + - \ + Echinoderm_Flatworm_Mitochondrial \ + Euplotid \ + Bacterial_and_Plant_Plastid \ + Alternative_Yeast_Nuclear \ + Ascidian_Mitochondrial \ + Alternative_Flatworm_Mitochondrial \ + Blepharisma_Nuclear \ + Chlorophycean_Mitochondrial \ + - \ + - \ + - \ + - \ + Trematode_Mitochondrial \ + Scenedesmus_Obliquus_Mitochondrial \ + Thraustochytrium_Mitochondrial + + +# 1. standard code (default) +translation_table_1 = \ + f f l l \ + s s s s \ + y y * * \ + c c * w \ + \ + l l l l \ + p p p p \ + h h q q \ + r r r r \ + \ + i i i m \ + t t t t \ + n n k k \ + s s r r \ + \ + v v v v \ + a a a a \ + d d e e \ + g g g g + +start_codons_1 = atg + +# +# For the following Genetic Code tables the differences +# from the Standard Code are given. +# +# +# 2. Vertebrate Mitochondrial Code +# +translation_table_2 = \ + aga* agg* atam tgaw + +start_codons_2 = atg +#start_codons_2_bos = ata +#start_codons_2_homo = ata att +#start_codons_2_mus = ata att atc +#start_codons_2_coturnix_gallus = gtg + +# 3. Yeast Mitochondrial Code +translation_table_3 = \ + atam cttt ctct ctat ctgt tgaw + +start_codons_3 = ata atg + +# 4. Mold, Protozoan, and Coelenterate Mitochondrial Code and the +# Mycoplasma/Spiroplasma Code +translation_table_4 = \ + tgaw + +start_codons_4 = atg + +#start_codons_4_Trypanosoma = tta ttg ctg +#start_codons_4_Leishmania = att ata +#start_codons_4_Tertrahymena = att ata atg +#start_codons_4_Paramecium = att ata atg atc gtg gta + +# 5. Invertebrate Mitochondrial Code +translation_table_5 = \ + agas aggs atam tgaw + +start_codons_5 = atg ata att +#start_codons_5_apis = atg ata atc att +#start_codons_5_polyplacophora = atg ata gtg + +# 6. Ciliate, Dasycladacean and Hexamita Nuclear Code +translation_table_6 = \ + taaq tagq + +start_codons_6 = atg + +# 9. Echinoderm and Flatworm Mitochondrial Code +translation_table_9 = \ + aaan agas aggs tgaw + +start_codons_9 = atg gtg + +# 10. Euplotid Nuclear Code +translation_table_10 = \ + tgac + +start_codons_10 = atg + +# 11. Bacterial and Plant Plastid +translation_table_11 = + +start_codons_11 = atg gtg ttg + +# 12. Alternative Yeast Nuclear Code +translation_table_12 = \ + ctgs + +start_codons_12 = ctg atg + +# 13. Ascidian Mitochondrial Code +translation_table_13 = \ + agag aggg atam tgaw + +start_codons_13 = atg + +# 14. Alternative Flatworm Mitochondrial Code +translation_table_14 = \ + aaan agas aggs taay tgaw + +start_codons_14 = atg + +# 15. Blepharisma +translation_table_15 = \ + tagq + +start_codons_15 = atg + +# 16. Chlorophycean Mitochondrial +translation_table_16 = \ + tagl + +start_codons_16 = atg + +# 21. Trematode Mitochondrial +translation_table_21 = \ + tgaw atam aaan agas aggs + +start_codons_21 = atg gtg + +# 22. Scenedesmus obliquus mitochondrial +translation_table_22 = \ + tca* tagl + +start_codons_22 = atg + +# 23. Thraustochytrium Mitochondrial +translation_table_23 = \ + tta* + +start_codons_23 = att atg gtg # the sequence of colour numbers must not have any gaps - if for example # colour_5 is missing then all colours with higher numbers will be ignored diff --git a/uk/ac/sanger/artemis/Feature.java b/uk/ac/sanger/artemis/Feature.java index c3eccfc33..4c49dd99b 100644 --- a/uk/ac/sanger/artemis/Feature.java +++ b/uk/ac/sanger/artemis/Feature.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/Feature.java,v 1.1 2004-06-09 09:44:36 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/Feature.java,v 1.2 2004-11-17 13:20:34 tjc Exp $ */ package uk.ac.sanger.artemis; @@ -60,7 +60,7 @@ import java.util.Date; * embl.Feature and embl.Entry objects. * * @author Kim Rutherford - * @version $Id: Feature.java,v 1.1 2004-06-09 09:44:36 tjc Exp $ + * @version $Id: Feature.java,v 1.2 2004-11-17 13:20:34 tjc Exp $ **/ public class Feature @@ -953,11 +953,13 @@ public class Feature final StringVector start_codons; - if (Options.getOptions ().isEukaryoticMode ()) { - start_codons = Options.getOptions ().getEukaryoticStartCodons (); - } else { - start_codons = Options.getOptions ().getProkaryoticStartCodons (); - } + start_codons = Options.getOptions().getStartCodons(); + +// if (Options.getOptions ().isEukaryoticMode ()) { +// start_codons = Options.getOptions ().getEukaryoticStartCodons (); +// } else { +// start_codons = Options.getOptions ().getProkaryoticStartCodons (); +// } if (start_codons.contains (first_codon)) { return true; diff --git a/uk/ac/sanger/artemis/Options.java b/uk/ac/sanger/artemis/Options.java index 345bed1c2..341466364 100644 --- a/uk/ac/sanger/artemis/Options.java +++ b/uk/ac/sanger/artemis/Options.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/Options.java,v 1.3 2004-10-29 09:36:23 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/Options.java,v 1.4 2004-11-17 13:20:46 tjc Exp $ **/ package uk.ac.sanger.artemis; @@ -44,7 +44,7 @@ import java.util.*; * read in new options. * * @author Kim Rutherford - * @version $Id: Options.java,v 1.3 2004-10-29 09:36:23 tjc Exp $ + * @version $Id: Options.java,v 1.4 2004-11-17 13:20:46 tjc Exp $ **/ public class Options extends Properties @@ -710,36 +710,58 @@ public class Options extends Properties } - /** * Return a StringVector containing the bases of the possible start codons * for prokaryotes. This is stored in the prokaryotic_start_codons option * in the options file. **/ - public StringVector getProkaryoticStartCodons() - { - final StringVector option_values = - getOptionValues("prokaryotic_start_codons"); +//public StringVector getProkaryoticStartCodons() +//{ +// final StringVector option_values = +// getOptionValues("prokaryotic_start_codons"); - for(int i = 0; i<option_values.size() ; ++i) - { - final String new_value = option_values.elementAt(i).toLowerCase(); - option_values.setElementAt(new_value, i); - } - return option_values; - } +// for(int i = 0; i<option_values.size() ; ++i) +// { +// final String new_value = option_values.elementAt(i).toLowerCase(); +// option_values.setElementAt(new_value, i); +// } +// return option_values; +//} /** * Return a StringVector containing the bases of the possible eukaryotic * start codons. This is stored in the eukaryotic_start_codons option in * the options file. **/ - public StringVector getEukaryoticStartCodons() +//public StringVector getEukaryoticStartCodons() +//{ +// final StringVector option_values = +// getOptionValues("eukaryotic_start_codons"); + +// for(int i = 0; i<option_values.size() ; ++i) +// { +// final String new_value = option_values.elementAt(i).toLowerCase(); +// option_values.setElementAt(new_value, i); +// } + +// return option_values; +//} + + public StringVector getStartCodons() { - final StringVector option_values = - getOptionValues("eukaryotic_start_codons"); + final StringVector option_values; - for(int i = 0; i<option_values.size() ; ++i) + if(getProperty("start_codons") == null) + { + if(isEukaryoticMode()) + option_values = getOptionValues("eukaryotic_start_codons"); + else + option_values = getOptionValues("prokaryotic_start_codons"); + } + else + option_values = getOptionValues("start_codons"); + + for(int i = 0; i<option_values.size() ; ++i) { final String new_value = option_values.elementAt(i).toLowerCase(); option_values.setElementAt(new_value, i); @@ -977,6 +999,12 @@ public class Options extends Properties return false; } + public void setGeneticCode(String table) + { + put("translation_table",table); + fireChangeEvent("translation_table"); + } + /** * Set the organism type to eukaryotic if and only if the argument is * true. The other alternative is prokaryotic. diff --git a/uk/ac/sanger/artemis/components/BasePlotGroup.java b/uk/ac/sanger/artemis/components/BasePlotGroup.java index 2c8011064..8e5a45f49 100644 --- a/uk/ac/sanger/artemis/components/BasePlotGroup.java +++ b/uk/ac/sanger/artemis/components/BasePlotGroup.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/BasePlotGroup.java,v 1.3 2004-11-09 16:21:16 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/BasePlotGroup.java,v 1.4 2004-11-17 13:19:43 tjc Exp $ */ package uk.ac.sanger.artemis.components; @@ -42,7 +42,7 @@ import javax.swing.*; * which can toggled off and on. * * @author Kim Rutherford - * @version $Id: BasePlotGroup.java,v 1.3 2004-11-09 16:21:16 tjc Exp $ + * @version $Id: BasePlotGroup.java,v 1.4 2004-11-17 13:19:43 tjc Exp $ **/ public class BasePlotGroup extends JPanel @@ -80,21 +80,24 @@ public class BasePlotGroup extends JPanel {21,91,4,0,38} // t }; - final float [] [] test_weights2 = { + final float[][] test_weights2 = + { {11,11,10, 8,11,10,11,11, 7, 8,25, 3,100, 0,27}, {29,33,30,30,32,34,37,38,39,36,26,75, 0, 0,14}, {14,12,10,10, 9,11,10, 9, 7, 6,26, 1, 0,100,49}, {46,44,50,52,48,45,42,43,47,51,23,21, 0, 0,10} }; - final float [] [] test_weights3 = { + final float[][] test_weights3 = + { {0,0,1,0,0,0}, {0,0,0,1,0,0}, {1,0,0,0,1,0}, {0,1,0,0,0,1}, }; - final float [] cai_test = { + final float[] cai_test = + { 0.113F, 1.0F, 0.117F, 1.0F, 1.0F, 0.693F, 0.036F, 0.005F, 0.071F, 1.0F, 0.0F, 0.0F, @@ -142,6 +145,43 @@ public class BasePlotGroup extends JPanel addAlgorithm(new GCDeviationAlgorithm(forward_strand)); addAlgorithm(new ATDeviationAlgorithm(forward_strand)); addAlgorithm(new KarlinSigAlgorithm(forward_strand)); + + + //CumulativeATSkewAlgorithm + addAlgorithm(new CumulativeATSkewAlgorithm(forward_strand)); + addAlgorithm(new CumulativeGCSkewAlgorithm(forward_strand)); + + //Positional Asymmetry + addAlgorithm(new PositionalAsymmetryAlgorithm(forward_strand)); + + //Informational Entropy + addAlgorithm(new EntropyAlgorithm(forward_strand)); + + //Scaled Chi + addAlgorithm(new ScaledChiAlgorithm(forward_strand)); + addAlgorithm(new ScaledChiAlgorithm(reverse_strand)); +// addAlgorithm(new ScaledChiRevAlgorithm(reverse_strand)); + + //Corrected Scaled Chi Square + addAlgorithm(new CSCSAlgorithm(forward_strand)); + addAlgorithm(new CSCSAlgorithm(reverse_strand)); +// addAlgorithm(new CSCSRevAlgorithm(reverse_strand)); + + //Mutational Response Index + addAlgorithm(new MRIAlgorithm(forward_strand)); + addAlgorithm(new MRIAlgorithm(reverse_strand)); +// addAlgorithm(new MRIRevAlgorithm(reverse_strand)); + + //Effective Codon Number + addAlgorithm(new NcAlgorithm(forward_strand)); + addAlgorithm(new NcAlgorithm(reverse_strand)); +// addAlgorithm(new NcRevAlgorithm(reverse_strand)); + + //Intrinsic Codon Deviation Index + addAlgorithm(new ICDIAlgorithm(forward_strand)); + addAlgorithm(new ICDIAlgorithm(reverse_strand)); +// addAlgorithm(new ICDIRevAlgorithm(reverse_strand)); + } diff --git a/uk/ac/sanger/artemis/components/FeatureDisplay.java b/uk/ac/sanger/artemis/components/FeatureDisplay.java index 8a36c42d2..70e78d442 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.8 2004-11-09 14:24:41 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/FeatureDisplay.java,v 1.9 2004-11-17 13:19:43 tjc Exp $ */ package uk.ac.sanger.artemis.components; @@ -44,7 +44,7 @@ import javax.swing.JComponent; * This component is used for displaying an Entry. * * @author Kim Rutherford - * @version $Id: FeatureDisplay.java,v 1.8 2004-11-09 14:24:41 tjc Exp $ + * @version $Id: FeatureDisplay.java,v 1.9 2004-11-17 13:19:43 tjc Exp $ **/ public class FeatureDisplay extends EntryGroupPanel @@ -1010,6 +1010,7 @@ public class FeatureDisplay extends EntryGroupPanel **/ public void optionChanged(OptionChangeEvent event) { + getBases().clearStopCodonCache(); repaint(); } @@ -1832,7 +1833,8 @@ public class FeatureDisplay extends EntryGroupPanel if(show_stop_codons) { - forward_stop_codons = new int [][] { + forward_stop_codons = new int [][] + { strand.getStopCodons(newRange(start_base, end_base)), strand.getStopCodons(newRange(start_base + 1, end_base)), strand.getStopCodons(newRange(start_base + 2, end_base)) @@ -1844,14 +1846,15 @@ public class FeatureDisplay extends EntryGroupPanel if(show_start_codons) { - final StringVector start_codons; - - if(Options.getOptions().isEukaryoticMode()) - start_codons = Options.getOptions().getEukaryoticStartCodons(); - else - start_codons = Options.getOptions().getProkaryoticStartCodons(); + final StringVector start_codons = Options.getOptions().getStartCodons(); + +// if(Options.getOptions().isEukaryoticMode()) +// start_codons = Options.getOptions().getEukaryoticStartCodons(); +// else +// start_codons = Options.getOptions().getProkaryoticStartCodons(); - forward_start_codons = new int [][] { + forward_start_codons = new int [][] + { strand.getMatchingCodons(newRange(start_base, end_base), start_codons), strand.getMatchingCodons(newRange(start_base + 1, end_base), @@ -1864,7 +1867,6 @@ public class FeatureDisplay extends EntryGroupPanel for(int i = 0 ; i < 3 ; ++i) { final int frame_line = getFrameDisplayLine(FORWARD_FRAME_1 + i); - final int frame_x_start = i; if(show_start_codons) @@ -1933,12 +1935,12 @@ public class FeatureDisplay extends EntryGroupPanel if(show_start_codons) { - final StringVector start_codons; + final StringVector start_codons = Options.getOptions().getStartCodons();; - if(Options.getOptions().isEukaryoticMode()) - start_codons = Options.getOptions().getEukaryoticStartCodons(); - else - start_codons = Options.getOptions().getProkaryoticStartCodons(); +// if(Options.getOptions().isEukaryoticMode()) +// start_codons = Options.getOptions().getEukaryoticStartCodons(); +// else +// start_codons = Options.getOptions().getProkaryoticStartCodons(); reverse_start_codons = new int [][] { strand.getMatchingCodons(newRange(start_base, end_base), diff --git a/uk/ac/sanger/artemis/components/Splash.java b/uk/ac/sanger/artemis/components/Splash.java index 7e67f4194..240662b0a 100644 --- a/uk/ac/sanger/artemis/components/Splash.java +++ b/uk/ac/sanger/artemis/components/Splash.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/Splash.java,v 1.1 2004-06-09 09:47:48 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/Splash.java,v 1.2 2004-11-17 13:19:43 tjc Exp $ */ package uk.ac.sanger.artemis.components; @@ -30,6 +30,8 @@ import uk.ac.sanger.artemis.EntrySourceVector; import uk.ac.sanger.artemis.Logger; import uk.ac.sanger.artemis.util.InputStreamProgressListener; import uk.ac.sanger.artemis.util.InputStreamProgressEvent; +import uk.ac.sanger.artemis.util.StringVector; +import uk.ac.sanger.artemis.sequence.Bases; import java.awt.*; import java.awt.event.*; @@ -40,7 +42,7 @@ import javax.swing.border.Border; * Base class that creates a generic "Splash Screen" * * @author Kim Rutherford <kmr@sanger.ac.uk> - * @version $Id: Splash.java,v 1.1 2004-06-09 09:47:48 tjc Exp $ + * @version $Id: Splash.java,v 1.2 2004-11-17 13:19:43 tjc Exp $ **/ abstract public class Splash extends JFrame @@ -80,6 +82,8 @@ abstract public class Splash extends JFrame protected JMenu options_menu; + private String geneticCode; + /** * Create a new JFrame for a Splash screen. * @param program_name The full name of the program. @@ -187,13 +191,14 @@ abstract public class Splash extends JFrame } // return the program name and the program mode in one String - private String getNameString() - { - if(Options.getOptions().isEukaryoticMode()) - return program_name + " [Eukaryotic mode]"; - else - return program_name + " [Prokaryotic mode]"; - } +// private String getNameString() +// { +// if(Options.getOptions().isEukaryoticMode()) +// return program_name + " [Eukaryotic mode]"; +// else +// return program_name + " [Prokaryotic mode]"; +// return geneticCode; +// } /** * Draws the splash screen text. @@ -209,13 +214,16 @@ abstract public class Splash extends JFrame helix_width + left_margin, font_height); g.drawString(program_version, helix_width + left_margin, font_height * 2); - if(Options.getOptions().isEukaryoticMode()) - g.drawString("[Eukaryotic mode]", +// if(Options.getOptions().isEukaryoticMode()) +// g.drawString("[Eukaryotic mode]", +// helix_width + left_margin, font_height * 3); +// else +// g.drawString("[Prokaryotic mode]", +// helix_width + left_margin, font_height * 3); + g.drawString(geneticCode, helix_width + left_margin, font_height * 3); - else - g.drawString("[Prokaryotic mode]", - helix_width + left_margin, font_height * 3); - g.drawString("Copyright 1998 - 2003", + + g.drawString("Copyright 1998 - 2004", helix_width + left_margin, font_height * 9 / 2); g.drawString("Genome Research Limited", helix_width + left_margin, font_height * 11 / 2); @@ -388,20 +396,115 @@ abstract public class Splash extends JFrame }); options_menu.add(enable_direct_edit_item); - final JCheckBoxMenuItem enable_euk_mode_item = new JCheckBoxMenuItem( - "Eukaryotic Mode"); - enable_euk_mode_item.setState(Options.getOptions().isEukaryoticMode()); - enable_euk_mode_item.addItemListener(new ItemListener() + + // available genetic codes + String gcodes[] = Options.getOptions().getOptionValues("genetic_codes").getArray(); + + ButtonGroup gcodeGroup = new ButtonGroup(); + options_menu.addSeparator(); + options_menu.add(new JLabel(" --- Genetic Codes Tables ---")); + for(int i = 0; i< gcodes.length; i++) { - public void itemStateChanged(ItemEvent event) + if(gcodes[i].equals("-")) + continue; + + int ind1; + while((ind1 = gcodes[i].indexOf("_")) > -1) + gcodes[i] = gcodes[i].substring(0,ind1) + " " + + gcodes[i].substring(ind1+1,gcodes[i].length()); + + String num = Integer.toString(i+1); + final String gc_name = num+". "+gcodes[i]; + final JCheckBoxMenuItem geneCode = new JCheckBoxMenuItem(gc_name); + gcodeGroup.add(geneCode); + geneCode.setActionCommand(num); + + geneCode.addItemListener(new ItemListener() { - final boolean item_state = enable_euk_mode_item.getState(); - Options.getOptions().setEukaryoticMode(item_state); + public void itemStateChanged(ItemEvent event) + { + if(geneCode.getState()) + { + geneticCode = gc_name; + String tab = "translation_table_"+geneCode.getActionCommand(); + String startCodons = "start_codons_"+geneCode.getActionCommand(); + + StringVector options_file_table = + Options.getOptions().getOptionValues(tab); + + if(options_file_table != null) + { + if(options_file_table.size() == 64) + { + StringBuffer sbuff = new StringBuffer(); + for(int i = 0; i < 64; ++i) + sbuff.append(options_file_table.elementAt(i)+" "); + + Options.getOptions().setGeneticCode(sbuff.toString()); + } + else + { + StringVector table = Options.getOptions().getOptionValues("translation_table_1"); + + for(int i = 0; i < options_file_table.size(); ++i) + { + String cod_plus_aa = options_file_table.elementAt(i); +// System.out.println(cod_plus_aa); + final int codon_index = Bases.getIndexOfBase(cod_plus_aa.charAt(0)) * 16 + + Bases.getIndexOfBase(cod_plus_aa.charAt(1)) * 4 + + Bases.getIndexOfBase(cod_plus_aa.charAt(2)); + +// System.out.println(cod_plus_aa.substring(3)+" "+codon_index+" "+ +// table.elementAt(codon_index)); + table.setElementAt(cod_plus_aa.substring(3), codon_index); + } + + StringBuffer sbuff = new StringBuffer(); + for(int i = 0; i < 64; ++i) + sbuff.append(table.elementAt(i)+" "); + + Options.getOptions().setGeneticCode(sbuff.toString()); + } + + options_file_table = + Options.getOptions().getOptionValues(startCodons); + + if(options_file_table != null) + { + StringBuffer sbuff = new StringBuffer(); + for(int i = 0; i < options_file_table.size(); ++i) + sbuff.append(options_file_table.elementAt(i)+" "); + + Options.getOptions().setProperty("start_codons",sbuff.toString()); + } + } + + if(helix_canvas != null) + helix_canvas.repaint(); + } + } + }); + options_menu.add(geneCode); - helix_canvas.repaint(); - } - }); - options_menu.add(enable_euk_mode_item); + if(i == 0) + geneCode.setState(true); + } + options_menu.addSeparator(); + + +// final JCheckBoxMenuItem enable_euk_mode_item = new JCheckBoxMenuItem( +// "Eukaryotic Mode"); +// enable_euk_mode_item.setState(Options.getOptions().isEukaryoticMode()); +// enable_euk_mode_item.addItemListener(new ItemListener() +// { +// public void itemStateChanged(ItemEvent event) +// { +// final boolean item_state = enable_euk_mode_item.getState(); +// Options.getOptions().setEukaryoticMode(item_state); +// helix_canvas.repaint(); +// } +// }); +// options_menu.add(enable_euk_mode_item); final JCheckBoxMenuItem highlight_active_entry_item = new JCheckBoxMenuItem("Highlight Active Entry"); diff --git a/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java b/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java index 2a1b859ff..31aa792f3 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.1 2004-06-09 09:52:11 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/AminoAcidSequence.java,v 1.2 2004-11-17 13:20:10 tjc Exp $ */ package uk.ac.sanger.artemis.sequence; @@ -33,16 +33,18 @@ 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.1 2004-06-09 09:52:11 tjc Exp $ + * @version $Id: AminoAcidSequence.java,v 1.2 2004-11-17 13:20:10 tjc Exp $ **/ -public class AminoAcidSequence { +public class AminoAcidSequence +{ /** * Create a new AminoAcidSequence object from a string containing single * character amino acids symbols. **/ - public AminoAcidSequence (String amino_acid_string) { - this.amino_acid_string = amino_acid_string.toLowerCase (); + public AminoAcidSequence(String amino_acid_string) + { + this.amino_acid_string = amino_acid_string.toLowerCase(); } /** @@ -56,24 +58,25 @@ public class AminoAcidSequence { * translated as '.' * @return The translated sequence in one letter abbreviated form. **/ - public static AminoAcidSequence getTranslation (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) { + public static AminoAcidSequence getTranslation(final String bases, + final boolean unknown_is_x) + { + setGeneCode(); + 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 { + else aa_buffer.append (aa); - } } - return new AminoAcidSequence (aa_buffer.toString ()); + return new AminoAcidSequence(aa_buffer.toString()); } /** @@ -86,13 +89,14 @@ public class AminoAcidSequence { * contains more or less than three letters or the letters aren't from * "CTAG") **/ - public static char getCodonTranslation (String codon_string) { - if (codon_string.length () < 3) { + public static char getCodonTranslation(String codon_string) + { + if(codon_string.length() < 3) return '.'; - } - return getCodonTranslation (codon_string.charAt (0), - codon_string.charAt (1), - codon_string.charAt (2)); + + return getCodonTranslation(codon_string.charAt(0), + codon_string.charAt(1), + codon_string.charAt(2)); } /** @@ -104,75 +108,82 @@ public class AminoAcidSequence { * @return The translated sequence in one letter abbreviated form. The * return value will be '.' if the letters do not form a codon. **/ - public static char getCodonTranslation (char first_letter, - char second_letter, - char third_letter) { - final int first_index = Bases.getIndexOfBase (first_letter); - - if (first_index >= 4) { + public static char getCodonTranslation(char first_letter, + char second_letter, + char third_letter) + { + final int first_index = Bases.getIndexOfBase(first_letter); + if(first_index >= 4) return '.'; - } - final int second_index = Bases.getIndexOfBase (second_letter); - - if (second_index >= 4) { + final int second_index = Bases.getIndexOfBase(second_letter); + if(second_index >= 4) return '.'; - } - - final int third_index = Bases.getIndexOfBase (third_letter); - if (third_index >= 4) { + final int third_index = Bases.getIndexOfBase(third_letter); + if(third_index >= 4) return '.'; - } final int codon_index = first_index * 16 + second_index * 4 + third_index; +// char[] codon = { first_letter, +// second_letter, +// third_letter, +// codon_translation_array[codon_index] }; +// System.out.println(new String(codon)); return codon_translation_array[codon_index]; } + /** * Return the number of units in this amino acid sequence. **/ - public int length () { - return amino_acid_string.length (); + public int length() + { + return amino_acid_string.length(); } /** * Return the one letter codon code of the codon at the given index * (counting from zero). **/ - public char elementAt (final int index) { - return amino_acid_string.charAt (index); + public char elementAt(final int index) + { + return amino_acid_string.charAt(index); } /** * Return the total molecular weight of the amino acids in this * AminoAcidSequence.. **/ - public float getMolecularWeight () { + public float getMolecularWeight() + { float return_weight = 0; - for (int i = 0 ; i < amino_acid_string.length () ; ++i) { - final char this_char = amino_acid_string.charAt (i); + for(int i = 0 ; i < amino_acid_string.length() ; ++i) + { + final char this_char = amino_acid_string.charAt(i); return_weight += - molecular_weights[getSymbolIndex (this_char)]; + molecular_weights[getSymbolIndex(this_char)]; } - if (amino_acid_string.length () > 1) { + if(amino_acid_string.length() > 1) + { // need to take off the weight of a water molecule for each peptide bond return return_weight - molecular_weight_of_water * (amino_acid_string.length () - 1); - } else { - return return_weight; } + else + return return_weight; } /** * Return a string representation of this object. This string will contain * the one character amino acid codes for each acid in sequence. **/ - public String toString () { + public String toString() + { return amino_acid_string; } @@ -180,31 +191,31 @@ public class AminoAcidSequence { * Search the subject_sequence for this AminoAcidSequence as a substring. * 'X' AAs are treated as wildcards in both sequences. **/ - public boolean checkForMatch (final AminoAcidSequence subject_sequence) { - final String subject_sequence_string = subject_sequence.toString (); + public boolean checkForMatch(final AminoAcidSequence subject_sequence) + { + final String subject_sequence_string = subject_sequence.toString(); - for (int subject_index = 0 ; - subject_index < subject_sequence_string.length () - - toString ().length () + 1 ; - ++subject_index) { + for(int subject_index = 0; + subject_index < subject_sequence_string.length() - + toString ().length () + 1; + ++subject_index) + { int query_index = 0; boolean is_matching = true; - for (; - query_index < toString ().length () ; - ++query_index) { + for(; query_index < toString().length(); + ++query_index) + { final char this_query_char = - toString ().charAt (query_index); + toString().charAt(query_index); final char this_subject_char = - subject_sequence_string.charAt (subject_index + query_index); - if (!aminoAcidMatches (this_subject_char, - this_query_char)) { + subject_sequence_string.charAt(subject_index + query_index); + if(!aminoAcidMatches(this_subject_char, + this_query_char)) break; - } } - if (query_index == toString ().length ()) { + if(query_index == toString().length()) return true; - } } return false; @@ -214,16 +225,17 @@ public class AminoAcidSequence { * Return true if and only if the two argument are the same AA or if one is * an X. **/ - private static boolean aminoAcidMatches (final char aa_char1, - final char aa_char2) { - if (aa_char1 == aa_char2) { + private static boolean aminoAcidMatches(final char aa_char1, + final char aa_char2) + { + if (aa_char1 == aa_char2) return true; - } else { - if (aa_char1 == 'x' || aa_char2 == 'x') { + else + { + if(aa_char1 == 'x' || aa_char2 == 'x') return true; - } else { + else return false; - } } } @@ -245,10 +257,11 @@ public class AminoAcidSequence { * @return A MarkerRange covering the matching bases or null if there is no * match in the given range. **/ - public MarkerRange findMatch (final Bases bases, - final Marker search_start_marker, - final boolean search_backwards) { - final String bases_string = bases.toString (); + public MarkerRange findMatch(final Bases bases, + final Marker search_start_marker, + final boolean search_backwards) + { + final String bases_string = bases.toString(); // search the bases_string forward for the pattern_string and its // complement @@ -261,84 +274,108 @@ public class AminoAcidSequence { // for the reverse complement of this position final int complement_search_start_index; - if (search_backwards) { - if (search_start_marker == null) { + if(search_backwards) + { + if(search_start_marker == null) + { forward_search_start_index = bases.getLength () - 1; complement_search_start_index = bases.getLength () - 1; - } else { + } + else + { complement_search_start_index = - search_start_marker.getRawPosition () - 2; - if (search_start_marker.getStrand ().isForwardStrand ()) { + search_start_marker.getRawPosition() - 2; + if(search_start_marker.getStrand().isForwardStrand()) + { forward_search_start_index = - search_start_marker.getRawPosition () - 2; - } else { + search_start_marker.getRawPosition() - 2; + } + else + { forward_search_start_index = - search_start_marker.getRawPosition () - 1; + search_start_marker.getRawPosition() - 1; } } - } else { - if (search_start_marker == null) { + } + else + { + if(search_start_marker == null) + { forward_search_start_index = 0; complement_search_start_index = 0; - } else { - forward_search_start_index = search_start_marker.getRawPosition (); - if (search_start_marker.getStrand ().isForwardStrand ()) { + } + else + { + forward_search_start_index = search_start_marker.getRawPosition(); + if(search_start_marker.getStrand().isForwardStrand()) + { complement_search_start_index = - search_start_marker.getRawPosition () - 1; - } else { + search_start_marker.getRawPosition() - 1; + } + else + { complement_search_start_index = - search_start_marker.getRawPosition (); + search_start_marker.getRawPosition(); } } } final int forward_search_result = - searchFor (bases_string, - forward_search_start_index, - search_backwards); + searchFor(bases_string, + forward_search_start_index, + search_backwards); final int complement_search_result = - reverseComplementSearchFor (bases_string, - complement_search_start_index, - search_backwards); + reverseComplementSearchFor(bases_string, + complement_search_start_index, + search_backwards); final int match_first_base; final int match_last_base; final Strand match_strand; - if (forward_search_result == -1) { - if (complement_search_result == -1) { - // no match + if(forward_search_result == -1) + { + // no match + if(complement_search_result == -1) return null; - } } - if (search_backwards) { + if(search_backwards) + { // take the match that is closest to the end, or the complement match if // there is a tie - if (complement_search_result != -1 && - (forward_search_result == -1 || - complement_search_result >= forward_search_result)) { + if(complement_search_result != -1 && + (forward_search_result == -1 || + complement_search_result >= forward_search_result)) + { match_first_base = bases.getComplementPosition (complement_search_result + 1); match_last_base = match_first_base - (length () * 3 - 1); match_strand = bases.getReverseStrand (); - } else { + } + else + { match_first_base = forward_search_result + 1; match_last_base = match_first_base + length () * 3 - 1; match_strand = bases.getForwardStrand (); } - } else { + } + else + { // take the match that is closest to base 1, or the forward match if // there is a tie - if (forward_search_result != -1 && - (complement_search_result == -1 || - forward_search_result <= complement_search_result)) { + if(forward_search_result != -1 && + (complement_search_result == -1 || + forward_search_result <= complement_search_result)) + { match_first_base = forward_search_result + 1; match_last_base = match_first_base + length () * 3 - 1; match_strand = bases.getForwardStrand (); - } else { + } + else + { match_first_base = bases.getComplementPosition (complement_search_result + 1); match_last_base = match_first_base - (length () * 3 - 1); @@ -346,12 +383,15 @@ public class AminoAcidSequence { } } - try { - return new MarkerRange (match_strand, - match_first_base, - match_last_base); - } catch (OutOfRangeException e) { - throw new Error ("internal error - unexpected exception: " + e); + try + { + return new MarkerRange(match_strand, + match_first_base, + match_last_base); + } + catch (OutOfRangeException e) + { + throw new Error("internal error - unexpected exception: " + e); } } @@ -366,14 +406,14 @@ public class AminoAcidSequence { * first base, otherwise first to last. * @return The index of the match or -1 if there is no match. **/ - public int searchFor (final String bases_string, - final int start_index, - final boolean search_backwards) { - if (search_backwards) { - return searchBackwardFor (bases_string, start_index); - } else { - return searchForwardFor (bases_string, start_index); - } + public int searchFor(final String bases_string, + final int start_index, + final boolean search_backwards) + { + if(search_backwards) + return searchBackwardFor(bases_string, start_index); + else + return searchForwardFor(bases_string, start_index); } /** @@ -385,37 +425,38 @@ public class AminoAcidSequence { * should start. * @return The index of the match or -1 if there is no match. **/ - public int searchForwardFor (final String bases_string, - final int start_index) { - final int pattern_base_length = length () * 3; - - for (int base_index = start_index ; - base_index <= bases_string.length () - pattern_base_length ; - ++base_index) { + public int searchForwardFor(final String bases_string, + final int start_index) + { + final int pattern_base_length = length() * 3; + for(int base_index = start_index; + base_index <= bases_string.length() - pattern_base_length ; + ++base_index) + { boolean matched = true; - for (int offset = 0 ; offset < length () ; ++offset) { - final char search_aa = amino_acid_string.charAt (offset); + for(int offset = 0 ; offset < length(); ++offset) + { + final char search_aa = amino_acid_string.charAt(offset); - if (search_aa == 'x') { - // X matches any AA + // X matches any AA + if(search_aa == 'x') continue; - } - final char base1 = bases_string.charAt (base_index + offset * 3 + 0); - final char base2 = bases_string.charAt (base_index + offset * 3 + 1); - final char base3 = bases_string.charAt (base_index + offset * 3 + 2); + final char base1 = bases_string.charAt(base_index + offset * 3 + 0); + final char base2 = bases_string.charAt(base_index + offset * 3 + 1); + final char base3 = bases_string.charAt(base_index + offset * 3 + 2); - if (getCodonTranslation (base1, base2, base3) != search_aa) { + if(getCodonTranslation(base1, base2, base3) != search_aa) + { matched = false; break; } } - if (matched) { + if(matched) return base_index; - } } return -1; @@ -430,39 +471,38 @@ public class AminoAcidSequence { * should start. * @return The index of the match or -1 if there is no match. **/ - public int searchBackwardFor (final String bases_string, - int start_index) { - if (bases_string.length () - start_index < length () * 3) { - start_index = bases_string.length () - length () * 3; - } - - for (int base_index = start_index ; - base_index >= 0 ; - --base_index) { + public int searchBackwardFor(final String bases_string, + int start_index) + { + if(bases_string.length() - start_index < length() * 3) + start_index = bases_string.length() - length() * 3; + for(int base_index = start_index; base_index >= 0; + --base_index) + { boolean matched = true; - for (int offset = 0 ; offset < length () ; ++offset) { - final char search_aa = amino_acid_string.charAt (offset); + for(int offset = 0 ; offset < length() ; ++offset) + { + final char search_aa = amino_acid_string.charAt(offset); - if (search_aa == 'x') { - // X matches any AA + // X matches any AA + if(search_aa == 'x') continue; - } - final char base1 = bases_string.charAt (base_index + offset * 3 + 0); - final char base2 = bases_string.charAt (base_index + offset * 3 + 1); - final char base3 = bases_string.charAt (base_index + offset * 3 + 2); + final char base1 = bases_string.charAt(base_index + offset * 3 + 0); + final char base2 = bases_string.charAt(base_index + offset * 3 + 1); + final char base3 = bases_string.charAt(base_index + offset * 3 + 2); - if (getCodonTranslation (base1, base2, base3) != search_aa) { + if(getCodonTranslation(base1, base2, base3) != search_aa) + { matched = false; break; } } - if (matched) { + if(matched) return base_index; - } } return -1; @@ -479,14 +519,14 @@ public class AminoAcidSequence { * first base, otherwise first to last. * @return The index of the match or -1 if there is no match. **/ - public int reverseComplementSearchFor (final String bases_string, - final int start_index, - final boolean search_backwards) { - if (search_backwards) { - return reverseComplementSearchBackwardFor (bases_string, start_index); - } else { - return reverseComplementSearchForwardFor (bases_string, start_index); - } + public int reverseComplementSearchFor(final String bases_string, + final int start_index, + final boolean search_backwards) + { + if(search_backwards) + return reverseComplementSearchBackwardFor(bases_string, start_index); + else + return reverseComplementSearchForwardFor(bases_string, start_index); } /** @@ -499,41 +539,43 @@ public class AminoAcidSequence { * should start. * @return The index of the match or -1 if there is no match. **/ - public int reverseComplementSearchForwardFor (final String bases_string, - final int start_index) { - final int pattern_base_length = length () * 3; - - for (int base_index = start_index ; - base_index <= bases_string.length () - pattern_base_length ; - ++base_index) { + public int reverseComplementSearchForwardFor(final String bases_string, + final int start_index) + { + final int pattern_base_length = length() * 3; + for(int base_index = start_index ; + base_index <= bases_string.length() - pattern_base_length ; + ++base_index) + { boolean matched = true; - for (int offset = 0 ; offset < length () ; ++offset) { + for(int offset = 0; offset < length (); ++offset) + { final char base1 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 0)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 0)); final char base2 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 1)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 1)); final char base3 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 2)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 2)); final char amino_acid_char = - amino_acid_string.charAt (amino_acid_string.length () - offset - 1); + amino_acid_string.charAt(amino_acid_string.length() - offset - 1); - if (amino_acid_char == 'x') { + // X matches any AA + if(amino_acid_char == 'x') // X matches any AA continue; - } - if (getCodonTranslation (base3, base2, base1) != amino_acid_char) { + if(getCodonTranslation(base3, base2, base1) != amino_acid_char) + { matched = false; break; } } - if (matched) { + if(matched) return base_index; - } } return -1; @@ -549,44 +591,42 @@ public class AminoAcidSequence { * should start. * @return The index of the match or -1 if there is no match. **/ - public int reverseComplementSearchBackwardFor (final String bases_string, - int start_index) { - - if (bases_string.length () - start_index < length () * 3) { - start_index = bases_string.length () - length () * 3; - } - - for (int base_index = start_index ; - base_index >= 0 ; - --base_index) { + public int reverseComplementSearchBackwardFor(final String bases_string, + int start_index) + { + if(bases_string.length() - start_index < length() * 3) + start_index = bases_string.length() - length() * 3; + for(int base_index = start_index; base_index >= 0; + --base_index) + { boolean matched = true; - for (int offset = 0 ; offset < length () ; ++offset) { + for(int offset = 0 ; offset < length() ; ++offset) + { final char base1 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 0)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 0)); final char base2 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 1)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 1)); final char base3 = - Bases.complement (bases_string.charAt (base_index + offset * 3 + 2)); + Bases.complement(bases_string.charAt(base_index + offset * 3 + 2)); final char amino_acid_char = - amino_acid_string.charAt (amino_acid_string.length () - offset - 1); + amino_acid_string.charAt(amino_acid_string.length() - offset - 1); - if (amino_acid_char == 'x') { - // X matches any AA + // X matches any AA + if(amino_acid_char == 'x') continue; - } - if (getCodonTranslation (base3, base2, base1) != amino_acid_char) { + if(getCodonTranslation(base3, base2, base1) != amino_acid_char) + { matched = false; break; } } - if (matched) { + if(matched) return base_index; - } } return -1; @@ -595,13 +635,14 @@ public class AminoAcidSequence { /** * Return true if and only if this sequence contains a stop codon. **/ - public boolean containsStopCodon () { - for (int i = 0 ; i < amino_acid_string.length () ; ++i) { - final char this_char = amino_acid_string.charAt (i); + public boolean containsStopCodon() + { + for(int i = 0 ; i < amino_acid_string.length() ; ++i) + { + final char this_char = amino_acid_string.charAt(i); - if (isStopCodon (this_char)) { + if(isStopCodon (this_char)) return true; - } } return false; @@ -611,35 +652,37 @@ public class AminoAcidSequence { * Return true if and only if the given amino acid symbol is the * translation of a stop codon. ie #, * or +. **/ - public static boolean isStopCodon (final char amino_acid_char) { - if (amino_acid_char == '#' || - amino_acid_char == '*' || - amino_acid_char == '+') { + public static boolean isStopCodon(final char amino_acid_char) + { + if(amino_acid_char == '#' || + amino_acid_char == '*' || + amino_acid_char == '+') return true; - } else { + else return false; - } } /** * Return true if and only if the given one letter code symbol is the a * legal amino acid or stop symbol. **/ - public static boolean isLegalCodon (final char one_letter_code) { - switch (one_letter_code) { - case 'a': case 'r': case 'n': case 'd': case 'c': case 'q': case 'e': - case 'g': case 'h': case 'i': case 'l': case 'k': case 'm': case 'f': - case 'p': case 's': case 't': case 'w': case 'y': case 'v': case '*': - case '#': case '+': - return true; - default: - return false; + public static boolean isLegalCodon(final char one_letter_code) + { + switch(one_letter_code) + { + case 'a': case 'r': case 'n': case 'd': case 'c': case 'q': case 'e': + case 'g': case 'h': case 'i': case 'l': case 'k': case 'm': case 'f': + case 'p': case 's': case 't': case 'w': case 'y': case 'v': case '*': + case '#': case '+': + return true; + default: + return false; } } /** * This table is used for fast lookup of codon translations by - * getCodonTranslation (). There is one entry for each codon and the + * getCodonTranslation(). There is one entry for each codon and the * entries are in this order: TTT, TTC, TTA, TTG, TCT, TCC, ... **/ final public static char [] codon_translation_array = { @@ -665,35 +708,35 @@ public class AminoAcidSequence { }; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int POLAR_UNCHARGED_AA = 0; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int POSITIVELY_CHARGED_AA = 1; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int NEGATIVELY_CHARGED_AA = 2; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int HYDROPHOBIC_AA = 3; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int SPECIAL_AA = 4; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int STOP_AA = 5; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int UNKNOWN_AA = 6; /** - * Used by getAminoAcidType (). + * Used by getAminoAcidType(). **/ public final static int ILLEGAL_AA = 7; @@ -702,29 +745,31 @@ public class AminoAcidSequence { * NEGATIVELY_CHARGED_AA, HYDROPHOBIC_AA, SPECIAL_AA or STOP_AA depending * on the aa_char argument. **/ - public static int getAminoAcidType (final char aa_char) { - switch (aa_char) { - case 'S': case 'T': case 'N': case 'Q': - return POLAR_UNCHARGED_AA; + public static int getAminoAcidType(final char aa_char) + { + switch (aa_char) + { + case 'S': case 'T': case 'N': case 'Q': + return POLAR_UNCHARGED_AA; - case 'K': case 'R': case 'H': - return POSITIVELY_CHARGED_AA; + case 'K': case 'R': case 'H': + return POSITIVELY_CHARGED_AA; - case 'E': case 'D': - return NEGATIVELY_CHARGED_AA; + case 'E': case 'D': + return NEGATIVELY_CHARGED_AA; - case 'A': case 'I': case 'L': case 'M': case 'F': case 'W': case 'V': - case 'Y': - return HYDROPHOBIC_AA; + case 'A': case 'I': case 'L': case 'M': case 'F': case 'W': case 'V': + case 'Y': + return HYDROPHOBIC_AA; - case 'C': case 'G': case 'P': - return SPECIAL_AA; + case 'C': case 'G': case 'P': + return SPECIAL_AA; - case '#': case '*': case '+': - return STOP_AA; + case '#': case '*': case '+': + return STOP_AA; - default: - return ILLEGAL_AA; + default: + return ILLEGAL_AA; } } @@ -734,15 +779,16 @@ public class AminoAcidSequence { * name. * @return A one letter code or -1 if three_letter_code can't be understood. **/ - public static char getOneLetterCode (final String three_letter_code) { + public static char getOneLetterCode(final String three_letter_code) + { final String real_code = - three_letter_code.substring (0, 1).toUpperCase () + - three_letter_code.substring (1).toLowerCase (); + three_letter_code.substring(0, 1).toUpperCase() + + three_letter_code.substring(1).toLowerCase(); - for (int i = 0 ; i < amino_acid_one_letter_names.length ; ++i) { - if (real_code.equals (amino_acid_abbreviated_names[i])) { + for(int i = 0 ; i < amino_acid_one_letter_names.length ; ++i) + { + if(real_code.equals(amino_acid_abbreviated_names[i])) return amino_acid_one_letter_names[i]; - } } return (char) -1; @@ -752,20 +798,22 @@ public class AminoAcidSequence { * Return the three letter abbreviation for the given one letter amino acid * code. **/ - public static String getThreeLetterAbbreviation (char one_letter_code) { - for (int i = 0 ; i < amino_acid_one_letter_names.length ; ++i) { - if (one_letter_code == amino_acid_one_letter_names[i]) { + public static String getThreeLetterAbbreviation(char one_letter_code) + { + for(int i = 0 ; i < amino_acid_one_letter_names.length ; ++i) + { + if(one_letter_code == amino_acid_one_letter_names[i]) return amino_acid_abbreviated_names[i]; - } } - throw new Error ("internal error - illegal one letter amino acid code"); + throw new Error("internal error - illegal one letter amino acid code"); } /** * Return the three letter abbreviation for the given index code. **/ - public static String getThreeLetterAbbreviation (final int index) { + public static String getThreeLetterAbbreviation(final int index) + { return amino_acid_abbreviated_names[index]; } @@ -773,45 +821,48 @@ public class AminoAcidSequence { * Return an integer from 0 to 22 representing the index of a codon * symbol. **/ - public static int getSymbolIndex (char one_letter_code) { - switch (one_letter_code) { - case 'a': return 0; - case 'r': return 1; - case 'n': return 2; - case 'd': return 3; - case 'c': return 4; - case 'q': return 5; - case 'e': return 6; - case 'g': return 7; - case 'h': return 8; - case 'i': return 9; - case 'l': return 10; - case 'k': return 11; - case 'm': return 12; - case 'f': return 13; - case 'p': return 14; - case 's': return 15; - case 't': return 16; - case 'w': return 17; - case 'y': return 18; - case 'v': return 19; - case '*': return 20; - case '#': return 21; - case '+': return 22; - case '.': return 23; - case 'x': return 23; - case 'u': return 24; - default: - throw new Error ("Internal error - illegal one letter codon symbol: " + - one_letter_code); + public static int getSymbolIndex(char one_letter_code) + { + switch(one_letter_code) + { + case 'a': return 0; + case 'r': return 1; + case 'n': return 2; + case 'd': return 3; + case 'c': return 4; + case 'q': return 5; + case 'e': return 6; + case 'g': return 7; + case 'h': return 8; + case 'i': return 9; + case 'l': return 10; + case 'k': return 11; + case 'm': return 12; + case 'f': return 13; + case 'p': return 14; + case 's': return 15; + case 't': return 16; + case 'w': return 17; + case 'y': return 18; + case 'v': return 19; + case '*': return 20; + case '#': return 21; + case '+': return 22; + case '.': return 23; + case 'x': return 23; + case 'u': return 24; + default: + throw new Error("Internal error - illegal one letter codon symbol: " + + one_letter_code); } } /** * Given an index return a one letter codon symbol. This method is the - * inverse of getSymbolIndex (). + * inverse of getSymbolIndex(). **/ - public static char getSymbolFromIndex (final int index) { + public static char getSymbolFromIndex(final int index) + { return amino_acid_one_letter_names[index]; } @@ -825,7 +876,8 @@ public class AminoAcidSequence { * The names here correspond to the letter codes at the same indices in * amino_acid_one_letter_names. **/ - private final static String [] amino_acid_abbreviated_names = { + private final static String [] amino_acid_abbreviated_names = + { "Ala", "Arg", "Asn", "Asp", "Cys", "Gln", "Glu", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", @@ -839,7 +891,8 @@ public class AminoAcidSequence { * The names here correspond to the three letter codes at the same indices * in amino_acid_abbreviated_names. **/ - private final static char [] amino_acid_one_letter_names = { + private final static char [] amino_acid_one_letter_names = + { 'a', 'r', 'n', 'd', 'c', 'q', 'e', 'g', 'h', 'i', 'l', 'k', 'm', 'f', 'p', @@ -852,7 +905,8 @@ public class AminoAcidSequence { * three letter codes at the same indices in amino_acid_abbreviated_names. * For example "Met" corresponds to a weight of 149.22 **/ - private final static float [] molecular_weights = { + private final static float [] molecular_weights = + { 89.09F, 174.21F, 132.12F, 133.10F, 121.15F, 146.15F, 147.13F, 75.07F, 155.16F, 131.18F, 131.18F, 146.19F, 149.22F, 165.19F, 115.13F, @@ -882,23 +936,26 @@ public class AminoAcidSequence { public final static int amino_acid_symbol_count = 20; - static { + private static void setGeneCode() + { // if translation_table is in the options file use it to set // codon_translation_array final StringVector options_file_table = - Options.getOptions ().getOptionValues ("translation_table"); - - if (options_file_table != null) { - if (options_file_table.size () == 64) { - for (int i = 0 ; i < 64 ; ++i) { + Options.getOptions().getOptionValues("translation_table"); + + if(options_file_table != null) + { + if(options_file_table.size () == 64) + { + for(int i = 0 ; i < 64 ; ++i) + { final char new_table_char = - options_file_table.elementAt (i).charAt (0); + options_file_table.elementAt(i).charAt(0); - if (isLegalCodon (new_table_char)) { + if(isLegalCodon (new_table_char)) codon_translation_array[i] = new_table_char; - } else { + else codon_translation_array[i] = '.'; - } } } } diff --git a/uk/ac/sanger/artemis/sequence/Bases.java b/uk/ac/sanger/artemis/sequence/Bases.java index d3a1baea9..4a78d30ae 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.1 2004-06-09 09:52:15 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/sequence/Bases.java,v 1.2 2004-11-17 13:20:10 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.1 2004-06-09 09:52:15 tjc Exp $ */ + * @version $Id: Bases.java,v 1.2 2004-11-17 13:20:10 tjc Exp $ */ public class Bases { /** @@ -451,6 +451,15 @@ public class Bases { return reverse_stop_codon_cache; } + /** + * Clear stop codon cache (forward and reverse). + **/ + public void clearStopCodonCache() + { + forward_stop_codon_cache = null; + reverse_stop_codon_cache = null; + } + /** * Return an array containing the positions of the stop codons. Only those * codons that are in the same frame as the first base of the range are -- GitLab