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 * @author Hanning Ni    Doubletwist Inc
030 */
031public class AGAVEFragmentOrderHandler
032               extends StAXFeatureHandler
033
034{
035  public static final StAXHandlerFactory AGAVE_FRAGMENT_ORDER_HANDLER_FACTORY
036    = new StAXHandlerFactory() {
037    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
038      return new AGAVEFragmentOrderHandler(staxenv);
039    }
040  };
041
042
043  AGAVEFragmentOrderHandler(StAXFeatureHandler staxenv) {
044    // setup up environment stuff
045    super( staxenv );
046    featureListener = staxenv.featureListener;
047    setHandlerCharacteristics("fragment_order", true);
048
049    // setup handlers
050       //
051       super.addHandler(new ElementRecognizer.ByLocalName("fragment_orientation"),
052         AGAVEFragmentOrientationHandler.AGAVE_FRAGMENT_ORIENTATION_HANDLER_FACTORY);
053       //
054       super.addHandler(new ElementRecognizer.ByLocalName("bio_sequence"),
055         AGAVEBioSequenceHandler.AGAVE_BIO_SEQUENCE_HANDLER_FACTORY);
056       //
057       super.addHandler(new ElementRecognizer.ByLocalName("map_location"),
058         AGAVEMapLocationPropHandler.AGAVE_MAP_LOCATION_PROP_HANDLER_FACTORY);
059
060  }
061
062  public void reportStrand(StrandedFeature.Strand strand)
063  {
064    // obtains strand from elements that are in the know.
065    ((StrandedFeature.Template) featureTemplate).strand = strand;
066  }
067  public void reportFeature(Location loc)
068  {
069    ((StrandedFeature.Template) featureTemplate).location = loc;
070  }
071
072
073
074  public void startElementHandler(
075                String nsURI,
076                String localName,
077                String qName,
078                Attributes attrs)
079                throws SAXException
080  {
081      try{
082      featureListener.startSequence();
083      boolean forFeature = false ;
084      setProperty( "group_id",  attrs.getValue("group_id") , forFeature) ;
085      setProperty( "length",  attrs.getValue("length") , forFeature) ;
086      }catch(Exception e){
087          throw new SAXException( e.getMessage() ) ;
088      }
089  }
090
091  /**
092   protected Feature.Template createTemplate() {
093    // create Gene Template for this
094    StrandedFeature.Template st = new StrandedFeature.Template();
095
096    // assume feature set to describe a transcript
097    st.type = "fragment_order";
098    st.strand = StrandedFeature.UNKNOWN;
099    // set up annotation bundle
100    st.annotation = annot;
101    st.location = new  Location.EmptyLocation();
102    if( staxenv != null )
103        staxenv. subFeatures .add( this ) ;
104
105    return st;
106  }**/
107
108
109
110}
111