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 */
021package org.biojava.bio.seq.io.agave;
022import org.biojava.bio.seq.StrandedFeature;
023import org.biojava.bio.symbol.Location;
024import org.xml.sax.Attributes;
025import org.xml.sax.SAXException;
026
027/**
028 *
029 * Handles the AGAVE <bio_sequence> element
030 *
031 * @author David Huen
032 * @author Hanning Ni     Doubletwist Inc
033 */
034public class AGAVEBioSequenceHandler
035               extends StAXFeatureHandler
036
037{
038  public static final StAXHandlerFactory AGAVE_BIO_SEQUENCE_HANDLER_FACTORY
039    = new StAXHandlerFactory() {
040    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
041      return new AGAVEBioSequenceHandler(staxenv);
042    }
043  };
044
045
046  AGAVEBioSequenceHandler(StAXFeatureHandler staxenv) {
047    // setup up environment stuff
048    super( staxenv );
049    featureListener = staxenv.featureListener;
050    setHandlerCharacteristics("bio_sequence", true);
051
052    // setup handlers
053       // <db_id>
054       super.addHandler(new ElementRecognizer.ByLocalName("db_id"),
055         AGAVEDbIdPropHandler.AGAVE_DBID_PROP_HANDLER_FACTORY);
056       // <note>
057       super.addHandler(new ElementRecognizer.ByLocalName("note"),
058         AGAVENotePropHandler.AGAVE_NOTE_PROP_HANDLER_FACTORY);
059       // <gene>
060       super.addHandler(new ElementRecognizer.ByLocalName("description"),
061         AGAVEDescPropHandler.AGAVE_DESC_PROP_HANDLER_FACTORY);
062       // <keyword>
063       super.addHandler(new ElementRecognizer.ByLocalName("keyword"),
064         AGAVEKeywordPropHandler.AGAVE_KEYWORD_PROP_HANDLER_FACTORY);
065       // <sequence>
066       super.addHandler(new ElementRecognizer.ByLocalName("sequence"),
067         AGAVESeqPropHandler.AGAVE_SEQ_PROP_HANDLER_FACTORY);
068       // <alt_ids>
069       super.addHandler(new ElementRecognizer.ByLocalName("alt_ids"),
070         AGAVEAltIdsPropHandler.AGAVE_ALT_IDS_PROP_HANDLER_FACTORY);
071       // <xrefs>
072       super.addHandler(new ElementRecognizer.ByLocalName("xrefs"),
073         AGAVEXrefsPropHandler.AGAVE_XREFS_PROP_HANDLER_FACTORY);
074       //<sequence_map>
075       super.addHandler(new ElementRecognizer.ByLocalName("sequence_map"),
076         AGAVESeqMapHandler.AGAVE_SEQ_MAP_HANDLER_FACTORY);
077       //<map_location>
078       super.addHandler(new ElementRecognizer.ByLocalName("map_location"),
079         AGAVEMapLocationPropHandler.AGAVE_MAP_LOCATION_PROP_HANDLER_FACTORY);
080       //<classification>
081       super.addHandler(new ElementRecognizer.ByLocalName("classification"),
082         AGAVEClassificationHandler.AGAVE_CLASSIFICATION_HANDLER_FACTORY);
083  }
084
085  public void reportStrand(StrandedFeature.Strand strand)
086  {
087    // obtains strand from elements that are in the know.
088    ((StrandedFeature.Template) featureTemplate).strand = strand;
089  }
090  public void reportFeature(Location loc)
091  {
092    // obtains strand from elements that are in the know.
093    ((StrandedFeature.Template) featureTemplate).location = loc;
094  }
095
096
097
098  public void startElementHandler(
099                String nsURI,
100                String localName,
101                String qName,
102                Attributes attrs)
103                throws SAXException
104  {
105      try{
106      featureListener.startSequence();
107      boolean forFeature = false ;
108      setProperty("element_id",  attrs.getValue("element_id") , forFeature) ;
109      setProperty( "sequence_id",  attrs.getValue("sequence_id") , forFeature) ;
110      setProperty( "seq_length",  attrs.getValue("seq_length") , forFeature) ;
111      setProperty( "molecule_type",  attrs.getValue("molecule_type") , forFeature) ;
112      setProperty( "organism_name",  attrs.getValue("organism_name"), forFeature ) ;
113      setProperty( "taxon_id",  attrs.getValue("taxon_id"), forFeature ) ;
114      setProperty( "clone_id",  attrs.getValue("clone_id"), forFeature ) ;
115      setProperty( "clone_library",  attrs.getValue("clone_library") , forFeature) ;
116      setProperty( "chromosome",  attrs.getValue("chromosome") , forFeature) ;
117      setProperty( "map_position",  attrs.getValue("map_position") , forFeature) ;
118      setProperty( "ec_number",  attrs.getValue("ec_number") , forFeature) ;
119      setProperty( "create_date",  attrs.getValue("create_date") , forFeature) ;
120      setProperty( "update_date",  attrs.getValue("update_date") , forFeature) ;
121      }catch(Exception e){
122         throw new SAXException( e.getMessage() ) ;
123      }
124
125  }
126
127
128  /**
129   protected Feature.Template createTemplate() {
130    // create Gene Template for this
131    StrandedFeature.Template st = new StrandedFeature.Template();
132
133    // assume feature set to describe a transcript
134    st.type = "bio_sequence";
135    st.strand = StrandedFeature.UNKNOWN;
136    // set up annotation bundle
137    st.annotation = annot;
138    st.location = new  Location.EmptyLocation();
139
140    if( staxenv != null )
141        staxenv. subFeatures .add( this ) ;
142
143    return st;
144  } **/
145
146
147
148}
149