[Biojava-l] Reading frames and amino acids

mark.schreiber at group.novartis.com mark.schreiber at group.novartis.com
Thu Mar 4 23:16:09 EST 2004


Hi Gera -

The code below seems to work for me. Please note that I have not tested it 
thoroughly so you might want to eyeball a few results to make sure they 
are sensible.

You could probably improve it by making some of the 'in line' code into 
methods etc.

- Mark

import java.io.*;

import org.biojava.bio.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.seq.io.*;
import org.biojava.bio.symbol.*;

/**
 * <p>Program to six-frame translate a nucleotide sequence</p>
 */

public class Hex {
  /**
   * Call this to get usage info, program terminates after call.
   */
  public static void help() {
    System.out.println(
        "usage: java utils.Hex <file> <format eg fasta> <dna|rna>");
    System.exit( -1);
  }
 
  public static void main(String[] args) throws Exception{
    if (args.length != 3) {
      help();
    }
 
    BufferedReader br = null;
    String format = args[1];
    String alpha = args[2];
 
    try {
      br = new BufferedReader(new FileReader(args[0]));
 
      SequenceIterator seqi = 
          (SequenceIterator)SeqIOTools.fileToBiojava(format, alpha, br);
 
      //for each sequence
      while(seqi.hasNext()){
        Sequence seq = seqi.nextSequence();
 
        //for each frame
        for (int i = 0; i < 3; i++) {
          SymbolList prot;
          Sequence trans;
 
          //take the reading frame
          SymbolList syms = seq.subList(
                i+1,
                seq.length() - (seq.length() - i)%3);


          //if it is DNA transcribe it to RNA 
          if(syms.getAlphabet() == DNATools.getDNA()){
            syms = RNATools.transcribe(syms);
          }
 
          //output forward translation to STDOUT
          prot = RNATools.translate(syms);
          trans = SequenceTools.createSequence(prot, "", 
                                               seq.getName()+
                                               "TranslationFrame: +"+i,
 Annotation.EMPTY_ANNOTATION);
          SeqIOTools.writeFasta(System.out, trans);
 
          //output reverse frame translation to STDOUT
          syms = RNATools.reverseComplement(syms);
          prot = RNATools.translate(syms);
          trans = SequenceTools.createSequence(prot, "",
                                               seq.getName() +
                                               "TranslationFrame: -" + i,
 Annotation.EMPTY_ANNOTATION);
          SeqIOTools.writeFasta(System.out, trans);
        }
      }
    }
    finally {
      if(br != null){
        br.close();
      }
    }
  }
}





"Jellema, Gera" <Gera.Jellema at wur.nl>
Sent by: biojava-l-bounces at portal.open-bio.org
03/04/2004 09:30 PM

 
        To:     <biojava-l at portal.open-bio.org>
        cc: 
        Subject:        [Biojava-l] Reading frames and amino acids


Hi,
I'm new to biojava so I don't know if this has already been asked. I have 
a genome sequence and I want to have it in the 6 reading frames, and then 
per reading frame translated into amino acids so I can look for proteins. 
I don't know how I have to do it.
Thanks,
Gera

_______________________________________________
Biojava-l mailing list  -  Biojava-l at biojava.org
http://biojava.org/mailman/listinfo/biojava-l

[ Attachment ''WINMAIL.DAT'' removed by Mark Schreiber ]




More information about the Biojava-l mailing list