@@ -6,67 +6,71 @@ There are multiple ways how to read a Genbank file.
66## Method 1: Read a Genbank file using the GenbankProxySequenceReader
77
88``` java
9-
10- GenbankProxySequenceReader<AminoAcidCompound > genbankProteinReader
11- = new GenbankProxySequenceReader<AminoAcidCompound > (" /tmp" , " NP_000257" , AminoAcidCompoundSet . getAminoAcidCompoundSet());
12- ProteinSequence proteinSequence = new ProteinSequence (genbankProteinReader);
13- genbankProteinReader. getHeaderParser(). parseHeader(genbankProteinReader. getHeader(), proteinSequence);
14- System . out. println(" Sequence" + " (" + proteinSequence. getAccession() + " ," + proteinSequence. getLength() + " )=" +
15- proteinSequence. getSequenceAsString(). substring(0 , 10 ) + " ..." );
16-
17- GenbankProxySequenceReader<NucleotideCompound > genbankDNAReader
18- = new GenbankProxySequenceReader<NucleotideCompound > (" /tmp" , " NM_001126" , DNACompoundSet . getDNACompoundSet());
19- DNASequence dnaSequence = new DNASequence (genbankDNAReader);
20- genbankDNAReader. getHeaderParser(). parseHeader(genbankDNAReader. getHeader(), dnaSequence);
21- System . out. println(" Sequence" + " (" + dnaSequence. getAccession() + " ," + dnaSequence. getLength() + " )=" +
22- dnaSequence. getSequenceAsString(). substring(0 , 10 ) + " ..." );
23-
9+ GenbankProxySequenceReader<AminoAcidCompound > genbankProteinReader =
10+ new GenbankProxySequenceReader<AminoAcidCompound > (" /tmp" , " NP_000257" ,
11+ AminoAcidCompoundSet . getAminoAcidCompoundSet());
12+ ProteinSequence proteinSequence = new ProteinSequence (genbankProteinReader);
13+ genbankProteinReader. getHeaderParser(). parseHeader(
14+ genbankProteinReader. getHeader(), proteinSequence);
15+ System . out. format(" Sequence(%s,%d)=%s..." ,
16+ proteinSequence. getAccession(),
17+ proteinSequence. getLength(),
18+ proteinSequence. getSequenceAsString(). substring(0 , 10 ));
19+
20+ GenbankProxySequenceReader<NucleotideCompound > genbankDNAReader =
21+ new GenbankProxySequenceReader<NucleotideCompound > (" /tmp" , " NM_001126" ,
22+ DNACompoundSet . getDNACompoundSet());
23+ DNASequence dnaSequence = new DNASequence (genbankDNAReader);
24+ genbankDNAReader. getHeaderParser(). parseHeader(genbankDNAReader. getHeader(), dnaSequence);
25+ System . out. format(" Sequence(%s,%d)=%s..." , dnaSequence. getAccession(),
26+ dnaSequence. getLength(),
27+ dnaSequence. getSequenceAsString(). substring(0 , 10 ));
2428```
2529
2630
2731## Method 2: Read a Genbank file using GenbankReaderHelper
2832
2933``` java
30- File dnaFile = new File (" src/test/resources/NM_000266.gb" );
31- File protFile = new File (" src/test/resources/BondFeature.gb" );
32-
33- LinkedHashMap<String , DNASequence > dnaSequences = GenbankReaderHelper . readGenbankDNASequence( dnaFile );
34- for ( DNASequence sequence : dnaSequences . values()) {
35- System . out . println( sequence . getSequenceAsString() );
36- }
37-
38- LinkedHashMap< String , ProteinSequence > protSequences = GenbankReaderHelper . readGenbankProteinSequence(protFile);
39- for ( ProteinSequence sequence : protSequences. values()) {
40- System . out . println( sequence . getSequenceAsString() );
41- }
42-
34+ File dnaFile = new File (" src/test/resources/NM_000266.gb" );
35+ File protFile = new File (" src/test/resources/BondFeature.gb" );
36+
37+ LinkedHashMap<String , DNASequence > dnaSequences =
38+ GenbankReaderHelper . readGenbankDNASequence( dnaFile );
39+ for ( DNASequence sequence : dnaSequences . values()) {
40+ System . out . println( sequence . getSequenceAsString() );
41+ }
42+
43+ LinkedHashMap< String , ProteinSequence > protSequences =
44+ GenbankReaderHelper . readGenbankProteinSequence(protFile );
45+ for ( ProteinSequence sequence : protSequences . values()) {
46+ System . out . println( sequence . getSequenceAsString() );
4347```
4448
4549## Method 3 : Read a Genbank file using the GenbankReader Object
4650
4751```java
48-
49- FileInputStream is = new FileInputStream (dnaFile);
50- GenbankReader< DNASequence , NucleotideCompound > dnaReader = new GenbankReader<DNASequence , NucleotideCompound > (
51- is,
52- new GenericGenbankHeaderParser<DNASequence ,NucleotideCompound > (),
53- new DNASequenceCreator (DNACompoundSet . getDNACompoundSet())
54- );
55- dnaSequences = dnaReader. process();
56- is. close();
57- System . out. println(dnaSequences);
58-
59- is = new FileInputStream (protFile);
60- GenbankReader<ProteinSequence , AminoAcidCompound > protReader = new GenbankReader< ProteinSequence , AminoAcidCompound > (
61- is,
62- new GenericGenbankHeaderParser< ProteinSequence , AminoAcidCompound > () ,
63- new ProteinSequenceCreator ( AminoAcidCompoundSet . getAminoAcidCompoundSet())
64- );
65- protSequences = protReader . process( );
66- is . close ();
67- System . out . println(protSequences );
68-
69- ```
52+ FileInputStream is = new FileInputStream (dnaFile);
53+ GenbankReader< DNASequence , NucleotideCompound > dnaReader =
54+ new GenbankReader<DNASequence , NucleotideCompound > (
55+ is,
56+ new GenericGenbankHeaderParser<DNASequence ,NucleotideCompound > (),
57+ new DNASequenceCreator (DNACompoundSet . getDNACompoundSet())
58+ );
59+ dnaSequences = dnaReader. process();
60+ is. close();
61+ System . out. println(dnaSequences);
62+
63+ is = new FileInputStream (protFile);
64+ GenbankReader<ProteinSequence , AminoAcidCompound > protReader =
65+ new GenbankReader< ProteinSequence , AminoAcidCompound > (
66+ is ,
67+ new GenericGenbankHeaderParser< ProteinSequence , AminoAcidCompound > (),
68+ new ProteinSequenceCreator ( AminoAcidCompoundSet . getAminoAcidCompoundSet())
69+ );
70+ protSequences = protReader . process ();
71+ is . close( );
72+ System . out . println(protSequences);
73+ ```
7074
7175
7276# Write a Genbank file
@@ -75,28 +79,28 @@ dnaSequence.getSequenceAsString().substring(0, 10) + "...");
7579Use the GenbankWriterHelper to write DNA sequences into a Genbank file.
7680
7781```java
78-
79- // First let's read dome DNA sequences from a genbank file
80-
81- File dnaFile = new File (" src/test/resources/NM_000266.gb" );
82- LinkedHashMap<String , DNASequence > dnaSequences = GenbankReaderHelper . readGenbankDNASequence( dnaFile );
83- ByteArrayOutputStream fragwriter = new ByteArrayOutputStream ();
84- ArrayList<DNASequence > seqs = new ArrayList<DNASequence > ();
85- for (DNASequence seq : dnaSequences. values()) {
86- seqs. add(seq);
87- }
88-
89- // ok now we got some DNA sequence data. Next step is to write it
90-
91- GenbankWriterHelper . writeNucleotideSequence(fragwriter, seqs,
92- GenbankWriterHelper . LINEAR_DNA );
93-
94- // the fragwriter object now contains a string representation in the Genbank format
95- // and you could write this into a file
96- // or print it out on the console
97- System . out. println(fragwriter. toString());
98-
82+ // First let's read dome DNA sequences from a genbank file
83+
84+ File dnaFile = new File (" src/test/resources/NM_000266.gb" );
85+ LinkedHashMap<String , DNASequence > dnaSequences =
86+ GenbankReaderHelper . readGenbankDNASequence( dnaFile );
87+ ByteArrayOutputStream fragwriter = new ByteArrayOutputStream ();
88+ ArrayList<DNASequence > seqs = new ArrayList<DNASequence > ();
89+ for (DNASequence seq : dnaSequences. values()) {
90+ seqs. add(seq);
91+ }
92+
93+ // ok now we got some DNA sequence data. Next step is to write it
94+
95+ GenbankWriterHelper . writeNucleotideSequence(fragwriter, seqs,
96+ GenbankWriterHelper . LINEAR_DNA );
97+
98+ // the fragwriter object now contains a string representation in the Genbank format
99+ // and you could write this into a file
100+ // or print it out on the console
101+ System . out. println(fragwriter. toString());
99102```
103+
100104< ! -- automatically generated footer-- >
101105
102106-- -
0 commit comments