This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Translating DNA to protein using biojava

I am new to biojava and am trying to convert a user inputted DNA sequence and get the protein sequence with 6 ORFs as the output. Below is the code that I have so far.I am at the point where it can read the file and output the DNA sequence. I am having trouble figuring out how to include the translation to protein with open reading frames in there.

import org.biojava.bio.BioException;
import org.biojavax.bio.seq.RichSequence;
import org.biojavax.bio.seq.RichSequence.IOTools;
import org.biojavax.bio.seq.RichSequenceIterator;
import java.io.*;
import java.util.Scanner;
import javax.swing.JFileChooser;

public class translate {
    private static JFileChooser ourChooser = new JFileChooser(".");

    public static BufferedReader openFile() {
        int value = ourChooser.showOpenDialog(null);
        BufferedReader br = null;

        if(value == JFileChooser.APPROVE_OPTION) {
            File file = ourChooser.getSelectedFile();

            try {
                br = new BufferedReader(new FileReader(file));
            }
            catch(FileNotFoundException e) {
                System.out.println("Program has trouble reading the file" + 
file.getName());
                e.printStackTrace();
            }
        }
        return br;
    }

    public static void main(String[] args) throws BioException {
        BufferedReader br = openFile();

        RichSequenceIterator it = IOTools.readFastaDNA(br, null);

        int count = 0;

        while (it.hasNext()) {
            count++;
            RichSequence seq = it.nextRichSequence();
            System.out.println(seq.getAccession());
            System.out.println(seq.seqString());

        }
        System.out.println("The number of sequences read is: " + count);
biojava java

0 answers

No answers yet.

Log in to answer this question.