Translating DNA to protein using biojava
0
0
Entering edit mode
4.6 years ago

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 • 1.1k views
ADD COMMENT

Login before adding your answer.

Traffic: 1817 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6