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