[Biojava-l] Re: Biojava-l digest, Vol 1 #334 - 2 msgs
Sarath
sarath@decodon.com
Mon, 11 Jun 2001 18:32:08 +0200 (MEST)
Hello everyone
I have been using the biojava package for around a month and today
surprisingly i have met with a strange circumstance of simple program not
able to compute the gc content from a file in the gene bank format.I would
be very glad if some body can tell me the bug in the program to find the
gc content from the file (AE000783.gbk) from the url
ftp://ncbi.nlm.nih.gov/genbank/genomes/Bacteria/Borrelia_burgdorferi/
I am pasting the source code here i hope this is not an inconvenience
to some people.The code is exactly the same as that given in the tutorials
.Probably there is a bug in biojava ...who knows or should i blame the
genbank people????
import java.io.*;
import org.biojava.bio.symbol.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.seq.io.*;
public class GCContentgbk {
public static void main(String[] args)
throws Exception
{
if (args.length != 1)
throw new Exception("usage: java GCContent filename.gbk");
String fileName = args[0];
// Set up sequence iterator
BufferedReader br = new BufferedReader(
new FileReader(fileName));
SequenceIterator stream = SeqIOTools.readGenbank(br);
// Iterate over all sequences in the stream
System.out.println("now the stream has the sequences to iterate
over");
while (stream.hasNext()) {
System.out.println("entered the loop and acquiring the next
sequence");
Sequence seq = stream.nextSequence();
System.out.println("if this line prints my code should run ...do
u get it");
int gc = 0;
for (int pos = 1; pos <= seq.length(); ++pos) {
Symbol sym = seq.symbolAt(pos);
if (sym == DNATools.g() || sym == DNATools.c())
++gc;
}
System.out.println(seq.getName() + ": " +
((gc * 100.0) / seq.length()) +
"%");
}
}
}