Question: Biojava Fetchgenbank
0
gravatar for J.Ashley
6.5 years ago by
J.Ashley10
J.Ashley10 wrote:

Hi everyone

Can someone help with this error please. I am trying to translate 6 open reading frames from the fetchgenbank.java program and Translation:SixFrames java program. used in biojava. I am trying to combine the two error but keep receiving the exception error.

Here is what I have so far

 import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.NoSuchElementException;

import org.biojava.bio.BioException;
import org.biojavax.bio.db.ncbi.GenbankRichSequenceDB;
import org.biojavax.bio.seq.RichSequence;

import org.biojava.bio.Annotation;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.RNATools;
import org.biojava.bio.seq.Sequence;
import org.biojava.bio.seq.SequenceIterator;
import org.biojava.bio.seq.SequenceTools;
import org.biojava.bio.seq.io.SymbolTokenization;
import org.biojava.bio.symbol.AlphabetManager;
import org.biojava.bio.symbol.IllegalAlphabetException;
import org.biojava.bio.symbol.SymbolList;

import java.util.Scanner;

public class test4{

     public static void main(String[] args) {
             RichSequence rs = null;
             GenbankRichSequenceDB grsdb = new GenbankRichSequenceDB();
             Scanner input = new ScannerSystem.in);

             try{
             // get data via GenBank accession number or gi number
                 System.out.println("Enter a GenBank accession number or gi number: ");
                 String id = input.nextLine();
             }
finally{
                 String id;
                rs = grsdb.getRichSequence(id);
                 System.out.println(rs.getName()+" | "+rs.getDescription());
                 System.out.println(rs.seqString());
             }

             String type;
            SymbolTokenization toke = AlphabetManager.alphabetForName(type)
                     .getTokenization("token");
BufferedReader br = new BufferedReader(new FileReader(type));

SequenceIterator seqi = RichSequence.IOTools.readFasta(br,toke, 
null);

SequenceIterator seqi1 = RichSequence.IOTools.readFasta(br,
toke, null);
                while (seqi1.hasNext()) {
                Sequence seq = seqi1.nextSequence();

                // for each frame
                for (int i = 0; i < 3; i++) {
                    SymbolList prot;
                    Sequence trans;


SymbolList syms = seq.subList(i + 1, seq.length()
- (seq.length() - i) % 3);
if (syms.getAlphabet() == DNATools.getDNA()) {
syms = DNATools.toRNA(syms);
}
prot = RNATools.translate(syms);
trans = SequenceTools.createSequence(prot, "", seq
            .getName()
        + "TranslationFrame: +" + i,
    Annotation.EMPTY_ANNOTATION);

    syms = RNATools.reverseComplement(syms);
    prot = RNATools.translate(syms);
    trans = SequenceTools.createSequence(prot, "", seq
    .getName()
    + " TranslationFrame: -" + i,
    Annotation.EMPTY_ANNOTATION);

            }
            br.close();
        } 
     }
} catch (IOException e) {
    e.printStackTrace();
} catch (IllegalAlphabetException e) {
    e.printStackTrace();
} catch (NoSuchElementException e) {
    e.printStackTrace();
} catch (BioException e) {
    e.printStackTrace();
}
}
}
ncbi sequence translation dna • 2.4k views
ADD COMMENTlink modified 6.4 years ago by Hamish3.1k • written 6.5 years ago by J.Ashley10

and what is the stacktrace ??

ADD REPLYlink written 6.5 years ago by Pierre Lindenbaum123k

this is the error I am receiving

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at test4.main(test4.java:28)

I am not quite sure since from looking at the other biojava programs the "catch (exceptions) seems to be right

ADD REPLYlink modified 6.5 years ago • written 6.5 years ago by J.Ashley10

are you running your program from eclipse ?

ADD REPLYlink written 6.5 years ago by Pierre Lindenbaum123k

yes I am using eclipse

ADD REPLYlink written 6.5 years ago by J.Ashley10

a *.jar is missing in your configuration.

ADD REPLYlink written 6.5 years ago by Pierre Lindenbaum123k

i added the *.jar but still recieved the same results

ADD REPLYlink written 6.5 years ago by J.Ashley10

make sure to show the entire traceback and also specify exactly which jar files are in discussion

ADD REPLYlink written 6.5 years ago by Istvan Albert ♦♦ 81k
0
gravatar for Hamish
6.4 years ago by
Hamish3.1k
UK
Hamish3.1k wrote:

As your exception message states, the provided code will not compile.

The following code is a corrected version which does the fetch from GenBank and performs the translation, outputting the sequences in fasta format:

import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import org.biojava.bio.Annotation;
import org.biojava.bio.BioException;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.RNATools;
import org.biojava.bio.seq.Sequence;
import org.biojava.bio.seq.SequenceTools;
import org.biojava.bio.symbol.IllegalAlphabetException;
import org.biojava.bio.symbol.SymbolList;
import org.biojavax.bio.db.ncbi.GenbankRichSequenceDB;
import org.biojavax.bio.seq.RichSequence;

/** Fetch a GenBank entry and output the translated sequence.
 * 
 * Based on:
 * http://biojava.org/wiki/BioJava:CookBook:ExternalSources:NCBIFetch
 * http://biojava.org/wiki/BioJava:Cookbook:Translation:SixFrames
 *
 */
public class test4 {
    public static void main(String[] args) {
        RichSequence rs = null;
        GenbankRichSequenceDB grsdb = new GenbankRichSequenceDB();
        Scanner input = new ScannerSystem.in);
        try {
            // get data via GenBank accession number or gi number
            System.out.println("Enter a GenBank accession number or gi number: ");
            String id = input.nextLine();
            // Fetch the entry from GenBank/RefSeq.
            rs = grsdb.getRichSequence(id);
            // Output in fasta format.
            RichSequence.IOTools.writeFasta(System.out, rs, null);
            // Assuming this is a nucleotide sequence...
            // For each frame
            for (int i = 0; i < 3; i++) {
                SymbolList syms = rs.subList(i + 1, rs.length() - (rs.length() - i) % 3);
                if (syms.getAlphabet() == DNATools.getDNA()) {
                    syms = DNATools.toRNA(syms);
                }
                // Forward frame.
                SymbolList prot = RNATools.translate(syms);
                Sequence trans = SequenceTools.createSequence(prot, "", 
                        rs.getName() + " TranslationFrame: +" + i,
                        Annotation.EMPTY_ANNOTATION);
                RichSequence.IOTools.writeFasta(System.out, trans, null);
                // Reverse frame.
                syms = RNATools.reverseComplement(syms);
                prot = RNATools.translate(syms);
                trans = SequenceTools.createSequence(prot, "", 
                        rs.getName() + " TranslationFrame: -" + i,
                        Annotation.EMPTY_ANNOTATION);
                RichSequence.IOTools.writeFasta(System.out, trans, null);
            }
        } catch (IllegalAlphabetException e) {
            e.printStackTrace();
        } catch (NoSuchElementException e) {
            e.printStackTrace();
        } catch (BioException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Please note that the use of GenBank entry names is not a good idea, since these can change and are specific to GenBank and do not appear in the other INSDC databases. I would suggest using the INSDC primary accessions (i.e. getAccession() instead of getName()) instead to avoid future confusion.

ADD COMMENTlink written 6.4 years ago by Hamish3.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 765 users visited in the last hour