[Biojava-l] Using SeqIOTools.biojavaToFile
Richard Holland
richard.holland at ebi.ac.uk
Wed Jun 28 08:56:20 UTC 2006
Your code is reading all the way through the sequence iterator (the
variable seq_iter) in a while loop. Then, you are using the same
sequence iterator to write out the database using
SeqIOTools.biojavaToFile. You get no output because the iterator has
been iterated over and all used up in the while loop, so has no more
sequences to supply.
If you want to write out as well as parse the sequences, you either have
to write them out one at a time in the while loop, or open a new
sequence iterator over the file at the end of the loop to pass to the
SeqIOTools.biojavaToFile call.
cheers,
Richard
On Wed, 2006-06-28 at 00:22 -0700, Jessicaa wrote:
> Hello,
> I compiled a java file and I tried to execute my program to change embl flat
> file to ncbi flat file.
> But output file(Toncbi.gbk) is o byte.
>
>
> //ex>java embl_togbk embl_sample
>
>
> import java.io.*;
> import java.util.*;
> import java.lang.*;
> import org.biojava.bio.*;
> import org.biojava.bio.seq.*;
> import org.biojava.bio.seq.io.*;
> import org.biojava.bio.symbol.*;
>
>
> public class embl_togbk {
> public static void main(String[] args) {
> String fileName = args[0];
> BufferedReader br;
> SequenceIterator seq_iter;
> Sequence seq;
> try {
> br = new BufferedReader(new FileReader(fileName));
> seq_iter = SeqIOTools.readEmbl(br);
> while(seq_iter.hasNext()) {
> seq =seq_iter.nextSequence();
> System.out.println(seq.getName());
> Iterator feat_iter = seq.features();
> while(feat_iter.hasNext()) {
> Feature f= (Feature) (feat_iter.next());
> Annotation annot = f.getAnnotation();
> System.out.println("*+feature: "+ f.getType());
> System.out.println();
> }
> }
> // System.out.println();
> SeqIOTools.biojavaToFile("GenBank","dna", new
> FileOutputStream("Toncbi.gbk"), seq_iter);
>
> br.close();
> } catch(Exception e) {
> e.printStackTrace();
> }
> }
> }
>
>
>
> //-----------------------------------------------
> //file:embl_sample
> ID A1MVRNA2 standard; DNA; 2593 BP.
> XX
> AC X01572;
> XX
> DT 03-AUG-1987 (an correction)
> DT 30-JAN-1986 (author review)
> DT 17-JUL-1985 (first entry)
> XX
> DE Alfalfa mosaic virus (A1M4) RNA 2
> XX
> KW unidentified reading frame.
> XX
> OS Alfalfa mosaic virus
> OC Viridae; ss-RNA nonenveloped viruses; Alfamovirus.
> XX
> RN [1] (bases 1-2593; enum. 1 to 2593)
> RA Cornelissen B.J.C., Brederode F.T., Veeneman G.H., van Boom J.H.,
> RA Bol J.F.;
> RT "Complete nucleotide sequence of alfalfa mosaic virus RNA 2";
> RL Nucl. Acids Res. 11:3019-3025(1983).
> XX
> CC Data kindly reviewed (30-JAN-1986) by J.F. Bol
> XX
> FH Key From To Description
> FH
> FT TRANSCR 1 80 A1MV RNA 2
> FT CDS 11 80 unidentified reading frame
> XX
> SQ Sequence 80 BP; 13 A; 14 C; 21 G; 32 T;
> TTTTTTTTTT ATGCCCCCCCC GGGGGGGGGG TTTTTTTTTT TTTTTTTTTT GGGGGGGGGG
> AAAAAAAAAA CCCCCCCCTAA
> //
>
> -------------------------------------------------------
> Is there a problem with this code?
> Thank you very much for answer.
>
> Regards.
>
> Jessica
--
Richard Holland (BioMart Team)
EMBL-EBI
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
UNITED KINGDOM
Tel: +44-(0)1223-494416
More information about the Biojava-l
mailing list