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.impl;
023
024import org.biojava.bio.seq.DNATools;
025import org.biojava.bio.seq.Feature;
026import org.biojava.bio.seq.FeatureHolder;
027import org.biojava.bio.seq.Frame;
028import org.biojava.bio.seq.FramedFeature;
029import org.biojava.bio.seq.RNATools;
030import org.biojava.bio.seq.Sequence;
031import org.biojava.bio.symbol.IllegalAlphabetException;
032
033/**
034 * Title:        SimpleFramedFeature.<p>
035 * Description:  A no frills implementation of FramedFeature.<p>
036 * Copyright:    Copyright (c) 2001.<p>
037 *
038 * @author Mark Schreiber
039 * @version 1.0
040 */
041
042public class SimpleFramedFeature extends SimpleStrandedFeature implements FramedFeature, Frame {
043  private FramedFeature.ReadingFrame readingFrame;
044
045  public SimpleFramedFeature(Sequence sourceSeq, FeatureHolder parent, FramedFeature.Template template)
046    throws IllegalAlphabetException {
047    super(sourceSeq,parent,template);
048    this.readingFrame = template.readingFrame;
049    if (sourceSeq.getAlphabet() == RNATools.getRNA() && template.strand == NEGATIVE) {
050      throw new IllegalAlphabetException("Cannot create a FramedFeature on the negative strand of an RNA");
051    }
052    else if (sourceSeq.getAlphabet() != DNATools.getDNA()) {
053      //throw new IllegalAlphabetException("Cannot create a FramedFeature on a sequence of type "+
054      //                                    sourceSeq.getAlphabet().getName());
055    }
056  }
057  public ReadingFrame getReadingFrame() {
058    return readingFrame;
059  }
060
061  public int getFrame(){
062    return readingFrame.getFrame();
063  }
064
065  public Feature.Template makeTemplate(){
066    FramedFeature.Template ft = new FramedFeature.Template();
067    fillTemplate(ft);
068    return ft;
069  }
070
071  protected void fillTemplate(FramedFeature.Template ft){
072    super.fillTemplate(ft);
073        ft.readingFrame = getReadingFrame();
074  }
075  public String toString(){
076   return super.toString() + " "+getStrand().getToken()+""
077           + getReadingFrame().getFrame();
078  }
079
080}