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 java.util.ArrayList;
023import java.util.List;
024
025import org.xml.sax.Attributes;
026import org.xml.sax.SAXException;
027
028/**
029 * transcript
030 *
031 * @author Hanning Ni    Doubletwist Inc
032 */
033public class AGAVETranscriptHandler
034               extends StAXFeatureHandler implements AGAVEEvidenceCallbackItf
035{
036
037  public static final StAXHandlerFactory AGAVE_TRANSCRIPT_HANDLER_FACTORY
038    = new StAXHandlerFactory() {
039    public StAXContentHandler getHandler(StAXFeatureHandler staxenv) {
040      return new AGAVETranscriptHandler(staxenv);
041    }
042  };
043
044
045 AGAVETranscriptHandler(StAXFeatureHandler staxenv) {
046    // setup up environment stuff
047    super( staxenv );
048    featureListener = staxenv.featureListener;
049    setHandlerCharacteristics("transcript", true);
050
051    // setup handlers
052       super.addHandler(new ElementRecognizer.ByLocalName("exons"),
053         AGAVEExonsPropHandler.AGAVE_EXONS_PROP_HANDLER_FACTORY);
054      super.addHandler(new ElementRecognizer.ByLocalName("cds"),
055         AGAVECdsHandler.AGAVE_CDS_HANDLER_FACTORY);
056
057      super.addHandler(new ElementRecognizer.ByLocalName("mrna"),
058         AGAVEMrnaHandler.AGAVE_MRNA_HANDLER_FACTORY);
059
060      super.addHandler(new ElementRecognizer.ByLocalName("predicted_protein"),
061         AGAVEPredictedProteinHandler.AGAVE_PREDICTED_PROTEIN_HANDLER_FACTORY);
062  }
063  public void addElementId(String id)
064  {
065      try{
066         Object ob = UtilHelper.getProperty(featureTemplate.annotation, "exons") ;
067         if( ob == null ){
068            ob = new ArrayList(1) ;
069            featureTemplate.annotation.setProperty("exons", ob ) ;
070         }
071         ((List)ob).add( id) ;
072      }catch(Exception e){
073        e.printStackTrace() ;
074      }
075  }
076
077   public void startElementHandler(
078                String nsURI,
079                String localName,
080                String qName,
081                Attributes attrs)
082         throws SAXException
083  {
084      featureTemplate.type = "transcript" ;
085  }
086
087
088  /**
089   protected Feature.Template createTemplate() {
090    // create Gene Template for this
091    StrandedFeature.Template st = new StrandedFeature.Template();
092
093    // assume feature set to describe a transcript
094    st.type = "transcript";
095    st.strand = StrandedFeature.UNKNOWN;
096    // set up annotation bundle
097    st.annotation = annot;
098    st.location = new  Location.EmptyLocation();
099    if( staxenv != null )
100        staxenv. subFeatures .add( this ) ;
101
102    return st;
103  }**/
104
105
106}