[Biojava-l] RNATools.translate

Thomas Down td2@sanger.ac.uk
Wed, 5 Sep 2001 13:04:30 +0100


On Wed, Sep 05, 2001 at 09:28:45AM +0100, Keith James wrote:
> >>>>> "Greg" == Cox, Greg <gcox@netgenics.com> writes:
> 
> [...]
> 
>     Greg> It seems that there's an additional step of translating the
>     Greg> RNA strand into codons before it can be translated into
>     Greg> amino acids.
> 
> You're right. Something along the lines of
> 
> StrandedFeature f = (StrandedFeature) fi.next();
> 
> SymbolList rna = RNATools.transcribe(f.getSymbols());
> 
> SymbolList codons = SymbolListViews.windowedSymbolList(rna, 3);
> 
> SymbolList translation =
>      SymbolListViews.translate(codons,
>                                RNATools.getGeneticCode("UNIVERSAL"));
> 
> is needed. After the various Perl APIs it made me do a double-take.


It does look a little...  baroque, doesn't it.  Certainly,
the step of explicity building the RNA^3 view gets people a
lot closer to the guts than they should really need to be.
I've attached a patch to auto-detect when you're just passing
in straight RNA, and build the windowed view then.

I think Ewan is probably right insofar as there should be
a convenience method for translating DNA, too.  I guess the
options are:

  - Put it on DNATools (probably neatest).

  - Add another trap to RNATools.translate to catch DNA.

Any preferences?

   Thomas.



diff -u -r1.13 RNATools.java
--- src/org/biojava/bio/seq/RNATools.java	2001/08/03 17:27:58	1.13
+++ src/org/biojava/bio/seq/RNATools.java	2001/09/05 12:00:06
@@ -292,13 +292,20 @@
   }
   
   /**
-   * Translate RNA into protein (with termination symbols).
+   * Translate RNA into protein (with termination symbols).  For
+   * compatibility with BioJava 1.1, this will also handle sequences
+   * which are already expressed in the (RNA x RNA x RNA) (codon)
+   * alphabet.
    *
    * @since 1.1
    */
   public static SymbolList translate(SymbolList syms)
-  throws IllegalAlphabetException {
-    return SymbolListViews.translate(syms, getGeneticCode("UNIVERSAL"));
+    throws IllegalAlphabetException 
+  {
+      if (syms.getAlphabet() == getRNA()) {
+	  syms = SymbolListViews.windowedSymbolList(syms, 3);
+      }
+      return SymbolListViews.translate(syms, getGeneticCode("UNIVERSAL"));
   }
   
   private static void loadGeneticCodes() {