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();
}
}
}
1 answer
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.
Log in to answer this question.
and what is the stacktrace ??
this is the error I am receiving
I am not quite sure since from looking at the other biojava programs the "catch (exceptions) seems to be right
are you running your program from eclipse ?
yes I am using eclipse
a *.jar is missing in your configuration.
i added the *.jar but still recieved the same results
make sure to show the entire traceback and also specify exactly which jar files are in discussion