001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.seq.io;
023
024import java.io.BufferedReader;
025import java.io.IOException;
026import java.util.ArrayList;
027import java.util.ListIterator;
028
029import javax.xml.parsers.ParserConfigurationException;
030import javax.xml.parsers.SAXParser;
031import javax.xml.parsers.SAXParserFactory;
032
033import org.biojava.bio.symbol.IllegalSymbolException;
034import org.xml.sax.Attributes;
035import org.xml.sax.InputSource;
036import org.xml.sax.SAXException;
037import org.xml.sax.helpers.DefaultHandler;
038
039/**
040 * Format reader for GenBank XML files.
041 * 
042 * @author Alan Li - alanli[at]xyworks.com
043 * @deprecated Use org.biojavax.bio.seq.io.INSDseqFormat
044 */
045
046public class GenbankXmlFormat extends GenbankFormat
047{
048    private SAXParser m_xmlParser;
049    private GenbankXmlHandler m_handler;
050    private boolean m_parsed;
051    private int m_sequenceIndex;
052    
053    public GenbankXmlFormat()
054    {
055        m_parsed = false;
056    }
057    
058    public boolean readSequence( BufferedReader reader,
059                                 SymbolTokenization symParser,
060                                 SeqIOListener listener)
061    throws IllegalSymbolException, IOException, ParseException
062    {
063        // only parse the sequence only once
064        if( ! m_parsed )
065        {
066            SAXParserFactory factory = SAXParserFactory.newInstance();
067            factory.setValidating( true );
068            try
069            {
070                m_xmlParser = factory.newSAXParser();
071            }
072            catch( ParserConfigurationException ex )
073            {
074                throw new ParseException( ex );
075            }
076            catch( SAXException ex )
077            {
078                throw new ParseException( ex );
079            }
080            
081            InputSource source = new InputSource( reader );
082            m_handler = new GenbankXmlHandler();
083                    
084            try
085            {
086                m_xmlParser.parse( source, m_handler );
087            }
088            catch( SAXException ex )
089            {
090                throw new ParseException( ex );
091            }
092            
093            m_parsed = true;
094        }
095        
096        // after parsing the input into one or more sequences, pass only 
097        // one sequence per readSequence()
098        ArrayList sequences = m_handler.getSequences();     
099        listener.startSequence();
100        GenbankXmlSequence sequence = 
101            (GenbankXmlSequence) sequences.get( m_sequenceIndex++ );
102        generateSequenceForListener( sequence, listener, symParser );
103        listener.endSequence();
104        
105        return ( m_sequenceIndex < sequences.size() );
106    }
107   
108    // helper method to handle the genbank xml objects to the SeqIOListener
109    private void generateSequenceForListener( GenbankXmlSequence sequence, SeqIOListener listener,
110                                              SymbolTokenization symParser )
111        throws ParseException, IllegalSymbolException
112    {
113        listener.addSequenceProperty( LOCUS_TAG, sequence.getLocus() );
114        listener.addSequenceProperty( SIZE_TAG, sequence.getLength() );
115        
116        String strandedness = sequence.getStrandedness();
117        if( strandedness != null )
118            listener.addSequenceProperty( STRAND_NUMBER_TAG, 
119                                          convertToStrandednessName( strandedness ) );
120        
121        String moltype = sequence.getMolType();
122        if( moltype != null )
123            listener.addSequenceProperty( TYPE_TAG, 
124                                          convertToMolTypeName( moltype ) );
125        String topology = sequence.getTopology();
126        if( topology != null )
127            listener.addSequenceProperty( CIRCULAR_TAG,
128                                          convertToTopologyName( topology ) );
129        
130        listener.addSequenceProperty( DIVISION_TAG, sequence.getDivision() );
131        listener.addSequenceProperty( DATE_TAG, sequence.getUpdateDate() );
132        listener.addSequenceProperty( DEFINITION_TAG, sequence.getDefinition() );
133        
134        String primaryAccession = sequence.getPrimaryAccession();
135        if( primaryAccession != null )
136            listener.addSequenceProperty( ACCESSION_TAG, primaryAccession );
137        
138        String accessionVersion = sequence.getAccessionVersion();
139        if( accessionVersion != null )
140            listener.addSequenceProperty( VERSION_TAG, accessionVersion );
141        
142        handleOtherSequenceIds( sequence, listener );  
143        handleKeywords( sequence, listener );
144        
145        listener.addSequenceProperty( SOURCE_TAG, sequence.getSource() );
146        listener.addSequenceProperty( ORGANISM_TAG, sequence.getOrganism() + sequence.getTaxonomy() );
147        
148        handleReferences( sequence, listener );
149        
150        String comment = sequence.getComment();
151        if( comment != null )
152            listener.addSequenceProperty( COMMENT_TAG, comment );
153        
154        handleFeatures( sequence, listener );
155        
156        String seq = sequence.getSequence();
157        if( seq != null && ! getElideSymbols() )
158        {
159            StreamParser streamParser = symParser.parseStream( listener );
160            streamParser.characters( seq.toCharArray(), 0, seq.length() );
161        }
162    }
163
164    private void handleOtherSequenceIds( GenbankXmlSequence sequence, SeqIOListener listener ) 
165        throws ParseException
166    {
167        ArrayList otherSeqIds = sequence.getOtherSequencesIds();
168        ListIterator iter = otherSeqIds.listIterator();
169        while( iter.hasNext() )
170        {
171            String seqId = (String) iter.next();
172            if( seqId.startsWith( "gi|" ) )
173                listener.addSequenceProperty( GI_TAG, seqId.substring( 3 ) );
174        }
175    }
176
177    private void handleKeywords( GenbankXmlSequence sequence, SeqIOListener listener ) 
178        throws ParseException
179    {
180        ArrayList keywords = sequence.getKeywords();
181        ListIterator iter = keywords.listIterator();
182        while( iter.hasNext() )
183        {
184            String keyword = (String) iter.next();
185            listener.addSequenceProperty( "KEYWORDS", keyword );
186        }
187    }
188
189    private void handleReferences( GenbankXmlSequence sequence, SeqIOListener listener ) throws ParseException
190    {
191        ArrayList references = sequence.getReferences();
192        ListIterator iter = references.listIterator();
193        while( iter.hasNext() )
194        {
195            GenbankXmlReference reference = (GenbankXmlReference) iter.next();
196            
197            listener.addSequenceProperty( REFERENCE_TAG, reference.getReference() );
198            
199            ArrayList authors = reference.getAuthors();
200            ListIterator authorIter = authors.listIterator();
201            StringBuffer theAuthors = new StringBuffer( "" );
202            while( authorIter.hasNext() )
203            {
204                String author = (String) authorIter.next();
205                theAuthors.append( author );
206                if( authorIter.hasNext() )
207                    theAuthors.append( ", " );
208            }
209            listener.addSequenceProperty( AUTHORS_TAG, theAuthors.toString() );
210            
211            String title = reference.getTitle();
212            if( title != null )
213                listener.addSequenceProperty( TITLE_TAG, title );
214            
215            listener.addSequenceProperty( JOURNAL_TAG, reference.getJournal() );
216            
217            // Added by RichardH to include Medline/Pubmed refs.
218            String pubmed = reference.getPubmed();
219            if (pubmed!=null) listener.addSequenceProperty(PUBMED_TAG, pubmed);
220            String medline = reference.getMedline();
221            if (medline!=null) listener.addSequenceProperty(MEDLINE_TAG, medline);
222        }
223    }
224    
225    private void handleFeatures( GenbankXmlSequence sequence, SeqIOListener listener ) throws ParseException
226    {
227        ArrayList features = sequence.getFeatures();
228        ListIterator iter = features.listIterator();
229        while( iter.hasNext() )
230        {
231            GenbankXmlFeature feature = (GenbankXmlFeature) iter.next();
232            String key = feature.getKey();
233            int keyLength = key.length();
234            String featureString = feature.getKey() + createBlankString( 16 - keyLength ) + 
235                                   feature.getLocation();
236            listener.addSequenceProperty( FEATURE_FLAG, featureString );
237            
238            ArrayList qualifiers = feature.getQualifiers();
239            ListIterator qualifiersIter = qualifiers.listIterator();
240            while( qualifiersIter.hasNext() )
241            {
242                GenbankXmlQualifier qualifier = (GenbankXmlQualifier) qualifiersIter.next();
243                String qualifierString = "                /" + qualifier.getName() + "=" +
244                                         "\"" + qualifier.getValue() + "\"";
245                listener.addSequenceProperty( FEATURE_FLAG, qualifierString );
246            }
247        }
248    }
249    
250    public String getDefaultFormat()
251    {
252        return "GenbankXml";
253    }
254 
255    private String createBlankString( int size )
256    {
257        StringBuffer sb = new StringBuffer();
258        for( int i = 0; i < size; i++ )
259            sb.append( ' ' );
260        return sb.toString();
261    }
262   
263    private String convertToStrandednessName( String strandednessIndex ) throws ParseException
264    {
265        int i = Integer.parseInt( strandednessIndex );
266        switch( i )
267        {
268            case 0:
269                return "not-set";
270            case 1:
271                return "single-stranded";
272            case 2:
273                return "double-stranded";
274            case 3:
275                return "mixed-stranded";
276            default:
277                throw new ParseException( "Unknown strandedness: " + strandednessIndex );
278        }
279    }
280    
281    private String convertToMolTypeName( String moltypeIndex ) throws ParseException
282    {
283        int i = Integer.parseInt( moltypeIndex );
284        switch( i )
285        {
286            case 0:
287                return "nucleic-acid";
288            case 1:
289                return "dna";
290            case 2:
291                return "rna";
292            case 3:
293                return "trna";
294            case 4:
295                return "rrna";
296            case 5:
297                return "mrna";
298            case 6:
299                return "urna";
300            case 7:
301                return "snrna";
302            case 8:
303                return "snorna";
304            case 9:
305                return "peptide";
306            default:
307                throw new ParseException( "Unknown molecule type: " + i );
308        }
309    }
310    
311    private String convertToTopologyName( String topologyIndex ) throws ParseException
312    {
313        int i = Integer.parseInt( topologyIndex );
314        switch( i )
315        {
316            case 1:
317                return "linear";
318            case 2:
319                return "circular";
320            default:
321                throw new ParseException( "Unknown topology: " + i );
322        }
323    }
324     
325    // SAX event handler extended to parse the Genbank XML format
326    // see details about GenbankXML format at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
327    private static class GenbankXmlHandler extends DefaultHandler
328    {
329        private GenbankXmlSequence m_currentSequence;
330        private ArrayList m_sequences;
331        private StringBuffer m_currentString;
332        
333        private GenbankXmlHandler()
334        {
335            m_sequences = new ArrayList();
336            m_currentString = new StringBuffer();
337        }
338        
339        public void startElement( String uri, String localName, String qName, 
340                                  Attributes attributes )
341        {
342            if( qName.equals( "GBSeq" ) )
343                m_currentSequence = new GenbankXmlSequence();
344            else if( qName.equals( "GBReference" ) )
345                m_currentSequence.addNewReference();
346            else if( qName.equals( "GBFeature" ) )
347                m_currentSequence.addNewFeature();
348            else if( qName.equals( "GBQualifier" ) )
349                m_currentSequence.getCurrentFeature().addNewQualifier();
350            else if( qName.equals( "GBInterval" ) )
351                m_currentSequence.getCurrentFeature().addNewInterval();
352        }
353        
354        public void endElement( String uri, String localName, String qName ) throws SAXException
355        {
356            if( qName.equals( "GBSet" ) )
357                return;     // do nothing
358            else if( qName.equals( "GBSeq" ) )
359                m_sequences.add( m_currentSequence );
360            else if( qName.equals( "GBSeq_locus" ) )
361                m_currentSequence.setLocus( m_currentString.toString() );
362            else if( qName.equals( "GBSeq_length" ) )
363                m_currentSequence.setLength( m_currentString.toString() );
364            else if( qName.equals( "GBSeq_strandedness" ) )
365                m_currentSequence.setStrandedness( m_currentString.toString() );
366            else if( qName.equals( "GBSeq_moltype" ) )
367                m_currentSequence.setMolType( m_currentString.toString() );
368            else if( qName.equals( "GBSeq_topology" ) )
369                m_currentSequence.setTopology( m_currentString.toString() );
370            else if( qName.equals( "GBSeq_division" ) )
371                m_currentSequence.setDivision( m_currentString.toString() );
372            else if( qName.equals( "GBSeq_update-date" ) )
373                m_currentSequence.setUpdateDate( m_currentString.toString() );
374            else if( qName.equals( "GBSeq_create-date") )
375                m_currentSequence.setCreateDate( m_currentString.toString() );
376            else if( qName.equals( "GBSeq_update-release" ) )
377                m_currentSequence.setUpdateRelease( m_currentString.toString() );
378            else if( qName.equals( "GBSeq_create-release") )
379                m_currentSequence.setCreateRelease( m_currentString.toString() );
380            else if( qName.equals( "GBSeq_definition" ) )
381                m_currentSequence.setDefinition( m_currentString.toString() );
382            else if( qName.equals( "GBSeq_primary-accession" ) )
383                m_currentSequence.setPrimaryAccession( m_currentString.toString() );
384            else if( qName.equals( "GBSeq_entry-version" ) )
385                m_currentSequence.setEntryVersion( m_currentString.toString() );
386            else if( qName.equals( "GBSeq_accession-version" ) )
387                m_currentSequence.setAccessionVersion( m_currentString.toString() );
388            else if( qName.equals( "GBSeq_other-seqids" ) )
389                return;     // nothing to do
390            else if( qName.equals( "GBSeqid" ) )
391                m_currentSequence.addOtherSequenceId( m_currentString.toString() );
392            else if( qName.equals( "GBSeq_secondary-accessions" ) )
393                return;     // nothing to do
394            else if( qName.equals( "GBSecondary-accn" ) )
395                m_currentSequence.addSecondaryAccession( m_currentString.toString() );
396            else if( qName.equals( "GBSeq_keywords" ) )
397                return;     // nothing to do
398            else if( qName.equals( "GBKeyword" ) )
399                m_currentSequence.addKeyword( m_currentString.toString() );
400            else if( qName.equals( "GBSeq_segment" ) )
401                m_currentSequence.setSegment( m_currentString.toString() );
402            else if( qName.equals( "GBSeq_source" ) )
403                m_currentSequence.setSource( m_currentString.toString() );
404            else if( qName.equals( "GBSeq_organism" ) )
405                m_currentSequence.setOrganism( m_currentString.toString() );
406            else if( qName.equals( "GBSeq_taxonomy" ) )
407                m_currentSequence.setTaxonomy( m_currentString.toString() );
408            else if( qName.equals( "GBSeq_references" ) )
409                return;     // nothing to do
410            else if( qName.equals( "GBReference" ) )
411                return;     // nothing to do
412            else if( qName.equals( "GBReference_reference" ) )
413                m_currentSequence.getCurrentReference().setReference( m_currentString.toString() );
414            else if( qName.equals( "GBReference_authors" ) )
415                return;     //nothing to do
416            else if( qName.equals( "GBAuthor" ) )
417                m_currentSequence.getCurrentReference().addAuthor( m_currentString.toString() );
418            else if( qName.equals( "GBReference_consortium" ) )
419                m_currentSequence.getCurrentReference().setConsortium( m_currentString.toString() );
420            else if( qName.equals( "GBReference_title" ) )
421                m_currentSequence.getCurrentReference().setTitle( m_currentString.toString() );
422            else if( qName.equals( "GBReference_journal" ) )
423                m_currentSequence.getCurrentReference().setJournal( m_currentString.toString() );
424            else if( qName.equals( "GBReference_medline" ) )
425                m_currentSequence.getCurrentReference().setMedline( m_currentString.toString() );
426            else if( qName.equals( "GBReference_pubmed" ) )
427                m_currentSequence.getCurrentReference().setPubmed( m_currentString.toString() );
428            else if( qName.equals( "GBReference_remark" ) )
429                m_currentSequence.getCurrentReference().setRemark( m_currentString.toString() );
430            else if( qName.equals( "GBSeq_comment" ) )
431                m_currentSequence.setComment( m_currentString.toString() );
432            else if( qName.equals( "GBSeq_primary" ) )
433                m_currentSequence.setPrimary( m_currentString.toString() );
434            else if( qName.equals( "GBSeq_source-db" ) )
435                m_currentSequence.setSourceDb( m_currentString.toString() );
436            else if( qName.equals( "GBSeq_database-reference" ) )
437                m_currentSequence.setDatabaseReference( m_currentString.toString() );
438            else if( qName.equals( "GBSeq_feature-table" ) )
439                return;     // do nothing
440            else if( qName.equals( "GBFeature" ) )
441                return;     // do nothing
442            else if( qName.equals( "GBFeature_key" ) )
443                m_currentSequence.getCurrentFeature().setKey( m_currentString.toString() );
444            else if( qName.equals( "GBFeature_location" ) )
445                m_currentSequence.getCurrentFeature().setLocation( m_currentString.toString() );
446            else if( qName.equals( "GBFeature_intervals" ) )
447                return;     // do nothing
448            else if( qName.equals( "GBInterval" ) )
449                return;     // do nothing
450            else if( qName.equals( "GBInterval_from" ) )
451                m_currentSequence.getCurrentFeature().getCurrentInterval().setFrom( m_currentString.toString() );
452            else if( qName.equals( "GBInterval_to" ) )
453                m_currentSequence.getCurrentFeature().getCurrentInterval().setTo( m_currentString.toString() );
454            else if( qName.equals( "GBInterval_point" ) )
455                m_currentSequence.getCurrentFeature().getCurrentInterval().setPoint( m_currentString.toString() );
456            else if( qName.equals( "GBInterval_accession" ) )
457                m_currentSequence.getCurrentFeature().getCurrentInterval().setAccession( m_currentString.toString() );
458            else if( qName.equals( "GBFeature_quals" ) )
459                return;     // do nothing
460            else if( qName.equals( "GBQualifier" ) )
461                return;     // do nothing
462            else if( qName.equals( "GBQualifier_name" ) )
463                m_currentSequence.getCurrentFeature().getCurrentQualifier().setName( m_currentString.toString() );
464            else if( qName.equals( "GBQualifier_value" ) )
465                m_currentSequence.getCurrentFeature().getCurrentQualifier().setValue( m_currentString.toString() );
466            else if( qName.equals( "GBSeq_sequence" ) )
467                m_currentSequence.setSequence( m_currentString.toString() );
468            else if( qName.equals( "GBSeq_contig" ) )
469                m_currentSequence.setContig( m_currentString.toString() );
470            else
471                throw new SAXException( "Unrecognized tag: " + qName );
472            
473            m_currentString.delete( 0, m_currentString.length() );
474        }
475        
476        public void characters( char[] ch, int start, int length )
477        {
478            m_currentString.append( ch, start, length );
479        }
480        
481        private ArrayList getSequences()
482        {
483            return m_sequences;
484        }
485    }
486    
487    // see GBSeq at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
488    private static class GenbankXmlSequence
489    {
490        private String m_locus;
491        private String m_length;
492        private String m_strandedness;
493        private String m_moltype;
494        private String m_topology;
495        private String m_division;
496        private String m_updateDate;
497        private String m_createDate;
498        private String m_updateRelease;
499        private String m_createRelease;
500        private String m_definition;
501        private String m_primaryAccession;
502        private String m_entryVersion;
503        private String m_accessionVersion;
504        private ArrayList m_otherSeqIds;
505        private ArrayList m_secondaryAccessions;
506        private ArrayList m_keywords;
507        private String m_segment;
508        private String m_source;
509        private String m_organism;
510        private String m_taxonomy;
511        private ArrayList m_references;
512        private GenbankXmlReference m_currReference;
513        private String m_comment;
514        private String m_primary;
515        private String m_sourceDb;
516        private String m_databaseReference;
517        private ArrayList m_features;
518        private GenbankXmlFeature m_currFeature;
519        private String m_sequence;
520        private String m_contig;
521        
522        private GenbankXmlSequence()
523        {
524            m_otherSeqIds = new ArrayList();
525            m_secondaryAccessions = new ArrayList();
526            m_keywords = new ArrayList();
527            m_references = new ArrayList();
528            m_features = new ArrayList();
529        }
530        
531        private void setLocus( String locus )
532        {
533            m_locus = locus;
534        }
535        
536        private String getLocus()
537        {
538            return m_locus;
539        }
540        
541        private void setLength( String length )
542        {
543            m_length = length;
544        }
545        
546        private String getLength()
547        {
548            return m_length;
549        }
550        
551        private void setStrandedness( String strandedness )
552        {
553            m_strandedness = strandedness;
554        }
555        
556        private String getStrandedness()
557        {
558            return m_strandedness;
559        }
560        
561        private void setMolType( String moltype )
562        {
563            m_moltype = moltype;
564        }
565        
566        private String getMolType()
567        {
568            return m_moltype;
569        }
570        
571        private void setTopology( String topology )
572        {
573            m_topology = topology;
574        }
575        
576        private String getTopology()
577        {
578            return m_topology;
579        }
580        
581        private void setDivision( String division )
582        {
583            m_division = division;
584        }
585        
586        private String getDivision()
587        {
588            return m_division;
589        }
590        
591        private void setUpdateDate( String updateDate )
592        {
593            m_updateDate = updateDate;
594        }
595        
596        private String getUpdateDate()
597        {
598            return m_updateDate;
599        }
600        
601        private void setCreateDate( String createDate )
602        {
603            m_createDate = createDate;
604        }
605        
606        String getCreateDate()
607        {
608            return m_createDate;
609        }
610        
611        private void setUpdateRelease( String updateRelease )
612        {
613            m_updateRelease = updateRelease;
614        }
615        
616        String getUpdateRelease()
617        {
618            return m_updateRelease;
619        }
620        
621        private void setCreateRelease( String createRelease )
622        {
623            m_createRelease = createRelease;
624        }
625        
626        String getCreateRelease()
627        {
628            return m_createRelease;
629        }
630        
631        private void setDefinition( String definition )
632        {
633            m_definition = definition;
634        }
635        
636        private String getDefinition()
637        {
638            return m_definition;
639        }
640        
641        private void setPrimaryAccession( String primaryAccession )
642        {
643            m_primaryAccession = primaryAccession;
644        }
645        
646        private String getPrimaryAccession()
647        {
648            return m_primaryAccession;
649        }
650        
651        private void setEntryVersion( String entryVersion )
652        {
653            m_entryVersion = entryVersion;
654        }
655        
656        String getEntryVersion()
657        {
658            return m_entryVersion;
659        }
660        
661        private void setAccessionVersion( String accessionVersion )
662        {
663            m_accessionVersion = accessionVersion;
664        }
665        
666        private String getAccessionVersion()
667        {
668            return m_accessionVersion;
669        }
670        
671        private void addOtherSequenceId( String seqId )
672        {
673            m_otherSeqIds.add( seqId );
674        }
675        
676        private ArrayList getOtherSequencesIds()
677        {
678            return new ArrayList( m_otherSeqIds );
679        }
680        
681        private void addSecondaryAccession( String secondaryAccession )
682        {
683            m_secondaryAccessions.add( secondaryAccession );
684        }
685        
686        ArrayList getSecondaryAccessions()
687        {
688            return new ArrayList( m_secondaryAccessions );
689        }
690        
691        private void addKeyword( String keyword )
692        {
693            m_keywords.add( keyword );
694        }
695        
696        private ArrayList getKeywords()
697        {
698            return new ArrayList( m_keywords );
699        }
700        
701        private void setSegment( String segment )
702        {
703            m_segment = segment;
704        }
705        
706        String getSegment()
707        {
708            return m_segment;
709        }
710        
711        private void setSource( String source )
712        {
713            m_source = source;
714        }
715        
716        private String getSource()
717        {
718            return m_source;
719        }
720        
721        private void setOrganism( String organism )
722        {
723            m_organism = organism;
724        }
725        
726        private String getOrganism()
727        {
728            return m_organism;
729        }
730        
731        private void setTaxonomy( String taxonomy )
732        {
733            m_taxonomy = taxonomy;
734        }
735        
736        private String getTaxonomy()
737        {
738            return m_taxonomy;
739        }
740        
741        private void addNewReference()
742        {
743            m_currReference = new GenbankXmlReference();
744            m_references.add( m_currReference );
745        }
746        
747        private GenbankXmlReference getCurrentReference()
748        {
749            return m_currReference;
750        }
751        
752        private ArrayList getReferences()
753        {
754            return new ArrayList( m_references );
755        }
756        
757        private void setComment( String comment )
758        {
759            m_comment = comment;
760        }
761        
762        private String getComment()
763        {
764            return m_comment;
765        }
766        
767        private void setPrimary( String primary )
768        {
769            m_primary = primary;
770        }
771        
772        String getPrimary()
773        {
774            return m_primary;
775        }
776        
777        private void setSourceDb( String sourceDb )
778        {
779            m_sourceDb = sourceDb;
780        }
781        
782        String getSourceDb()
783        {
784            return m_sourceDb;
785        }
786        
787        private void setDatabaseReference( String databaseReference )
788        {
789            m_databaseReference = databaseReference;
790        }
791        
792        String getDatabaseReference()
793        {
794            return m_databaseReference;
795        }
796        
797        private void addNewFeature()
798        {
799            m_currFeature = new GenbankXmlFeature();
800            m_features.add( m_currFeature );
801        }
802        
803        private GenbankXmlFeature getCurrentFeature()
804        {
805            return m_currFeature;
806        }
807        
808        private ArrayList getFeatures()
809        {
810            return new ArrayList( m_features );
811        }
812        
813        private void setSequence( String sequence )
814        {
815            m_sequence = sequence;
816        }
817        
818        private String getSequence()
819        {
820            return m_sequence;
821        }
822        
823        private void setContig( String contig )
824        {
825            m_contig = contig;
826        }
827        
828        String getContig()
829        {
830            return m_contig;
831        }
832    }
833    
834    // see GBReference at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
835    private static class GenbankXmlReference
836    {
837        private String m_reference;
838        private ArrayList m_authors;
839        private String m_consortium;
840        private String m_title;
841        private String m_journal;
842        private String m_medline;
843        private String m_pubmed;
844        private String m_remark;
845        
846        private GenbankXmlReference()
847        {
848            m_authors = new ArrayList();
849        }
850        
851        private void setReference( String reference )
852        {
853            m_reference = reference;
854        }
855        
856        private String getReference()
857        {
858            return m_reference;
859        }
860        
861        private void addAuthor( String author )
862        {
863            m_authors.add( author );
864        }
865        
866        private ArrayList getAuthors()
867        {
868            return new ArrayList( m_authors );
869        }
870        
871        private void setConsortium( String consortium )
872        {
873            m_consortium = consortium;
874        }
875        
876        String getConsortium()
877        {
878            return m_consortium;
879        }
880        
881        private void setTitle( String title )
882        {
883            m_title = title;
884        }
885        
886        private String getTitle()
887        {
888            return m_title;
889        }
890        
891        private void setJournal( String journal )
892        {
893            m_journal = journal;
894        }
895        
896        private String getJournal()
897        {
898            return m_journal;
899        }
900        
901        private void setMedline( String medline )
902        {
903            m_medline = medline;
904        }
905        
906        private String getMedline()
907        {
908            return m_medline;
909        }
910        
911        private void setPubmed( String pubmed )
912        {
913            m_pubmed = pubmed;
914        }
915        
916        private String getPubmed()
917        {
918            return m_pubmed;
919        }
920        
921        private void setRemark( String remark )
922        {
923            m_remark = remark;
924        }
925        
926        String getRemark()
927        {
928            return m_remark;
929        }
930    }
931    
932    // see GBFeature at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
933    private static class GenbankXmlFeature
934    {
935        private String m_key;
936        private String m_location;
937        private ArrayList m_intervals;
938        private GenbankXmlInterval m_currInterval;
939        private ArrayList m_qualifiers;
940        private GenbankXmlQualifier m_currQualifier;
941        
942        private GenbankXmlFeature()
943        {
944            m_intervals = new ArrayList();
945            m_qualifiers = new ArrayList();
946        }
947        
948        private void setKey( String key )
949        {
950            m_key = key;
951        }
952        
953        private String getKey()
954        {
955            return m_key;
956        }
957        
958        private void setLocation( String location )
959        {
960            m_location = location;
961        }
962        
963        private String getLocation()
964        {
965            return m_location;
966        }
967        
968        private void addNewInterval()
969        {
970            m_currInterval = new GenbankXmlInterval();
971            m_intervals.add( m_currInterval );
972        }
973        
974        private GenbankXmlInterval getCurrentInterval()
975        {
976            return m_currInterval;
977        }
978        
979        ArrayList getIntervals()
980        {
981            return new ArrayList( m_intervals );
982        }
983        
984        private void addNewQualifier()
985        {
986            m_currQualifier = new GenbankXmlQualifier();
987            m_qualifiers.add( m_currQualifier );
988        }
989        
990        private GenbankXmlQualifier getCurrentQualifier()
991        {
992            return m_currQualifier;
993        }
994        
995        private ArrayList getQualifiers()
996        {
997            return new ArrayList( m_qualifiers );
998        }
999    }
1000    
1001    // see GBQualifier at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
1002    private static class GenbankXmlQualifier
1003    {
1004        private String m_name;
1005        private String m_value;
1006        
1007        private void setName( String name )
1008        {
1009            m_name = name;
1010        }
1011        
1012        private String getName()
1013        {
1014            return m_name;
1015        }
1016        
1017        private void setValue( String value )
1018        {
1019            m_value = value;
1020        }
1021        
1022        private String getValue()
1023        {
1024            return m_value;
1025        }
1026    }
1027    
1028    // see GBInterval at http://www.ncbi.nlm.nih.gov/dtd/NCBI_GBSeq.mod
1029    private static class GenbankXmlInterval
1030    {
1031        private String m_from;
1032        private String m_to;
1033        private String m_point;
1034        private String m_accession;
1035        
1036        private void setFrom( String from )
1037        {
1038            m_from = from;
1039        }
1040        
1041        String getFrom()
1042        {
1043            return m_from;
1044        }
1045        
1046        private void setTo( String to )
1047        {
1048            m_to = to;
1049        }
1050        
1051        String getTo()
1052        {
1053            return m_to;
1054        }
1055        
1056        private void setPoint( String point )
1057        {
1058            m_point = point;
1059        }
1060        
1061        String getPoint()
1062        {
1063            return m_point;
1064        }
1065        
1066        private void setAccession( String accession )
1067        {
1068            m_accession = accession;
1069        }
1070        
1071        String getAccession()
1072        {
1073            return m_accession;
1074        }
1075    }
1076}