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 * Created on DATE
021 *
022 */
023package org.biojava.nbio.core.sequence;
024
025import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
026import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
027import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
028import org.biojava.nbio.core.sequence.loader.StringProxySequenceReader;
029import org.biojava.nbio.core.sequence.template.*;
030import org.biojava.nbio.core.sequence.transcription.Frame;
031import org.biojava.nbio.core.sequence.transcription.TranscriptionEngine;
032import org.biojava.nbio.core.sequence.views.ComplementSequenceView;
033import org.biojava.nbio.core.sequence.views.ReversedSequenceView;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037/**
038 * This is class should model the attributes associated with a DNA sequence
039 *
040 * @author Scooter Willis
041 */
042public class DNASequence extends AbstractSequence<NucleotideCompound> {
043
044        private final static Logger logger = LoggerFactory.getLogger(DNASequence.class);
045/**
046 * The type of DNA sequence
047 */
048        public enum DNAType {
049                CHROMOSOME, MITOCHONDRIAL, PLASMID, PLASTID, UNKNOWN
050        }
051        private DNAType dnaType = DNAType.UNKNOWN;
052
053        /**
054         * Shouldn't be used but makes it bean happy
055         */
056        public DNASequence() {
057//        throw new UnsupportedOperationException("Null constructor not supported");
058        }
059
060        /**
061         * String is king and create a sequence from DNA with default DNA compound set
062         * @param seqString
063         * @throws CompoundNotFoundException
064         */
065        public DNASequence(String seqString) throws CompoundNotFoundException {
066                super(seqString, DNACompoundSet.getDNACompoundSet());
067        }
068
069        /**
070         * Create a sequence where the actual storage of the sequence data is somewhere else
071         * @param proxyLoader
072         */
073        public DNASequence(SequenceReader<NucleotideCompound> proxyLoader) {
074                super(proxyLoader, DNACompoundSet.getDNACompoundSet());
075        }
076
077        /**
078         * Create a sequence from a string with user defined compound set
079         * @param seqString
080         * @param compoundSet
081         * @throws CompoundNotFoundException
082         */
083        public DNASequence(String seqString, CompoundSet<NucleotideCompound> compoundSet) throws CompoundNotFoundException {
084                super(seqString, compoundSet);
085        }
086
087        /**
088         * Create a sequence from a ProxySequencereader and user defined compound set
089         * @param proxyLoader
090         * @param compoundSet
091         */
092        public DNASequence(SequenceReader<NucleotideCompound> proxyLoader, CompoundSet<NucleotideCompound> compoundSet) {
093                super(proxyLoader, compoundSet);
094        }
095
096        /**
097         * Return the RNASequence equivalent of the DNASequence using default Transcription Engine. Not all
098         * species follow the same rules. If you don't know better use this method
099         * @return RNA sequence
100         */
101        public RNASequence getRNASequence() {
102          return getRNASequence(Frame.getDefaultFrame());
103        }
104
105        /**
106         * Allow a user to pass in a rules engine to do the DNA to RNA translation
107         * @param engine
108         * @return RNA sequence
109         */
110        public RNASequence getRNASequence(TranscriptionEngine engine) {
111          return getRNASequence(engine, Frame.getDefaultFrame());
112        }
113
114        /**
115         * Allows the user to pass in the Frame shift.
116         * @param frame
117         * @return rna sequence
118         */
119        public RNASequence getRNASequence(Frame frame) {
120          return getRNASequence(TranscriptionEngine.getDefault(), frame);
121        }
122
123        public RNASequence getRNASequence(TranscriptionEngine engine, Frame frame) {
124          return (RNASequence) engine.getDnaRnaTranslator().createSequence(this, frame);
125        }
126
127        /**
128         * Get the GC count in the DNA Sequence
129         * @return GC count
130         */
131        public int getGCCount() {
132                return SequenceMixin.countGC(this);
133        }
134
135        /**
136         * Returns a Sequence which runs in the current reverse order
137         */
138        public SequenceView<NucleotideCompound> getReverse() {
139                return new ReversedSequenceView<NucleotideCompound>(this);
140        }
141
142        /**
143         * Returns a Sequence which will complement every base
144         */
145        public SequenceView<NucleotideCompound> getComplement() {
146                return new ComplementSequenceView<NucleotideCompound>(this);
147        }
148
149        /**
150         * Delegates to {@link #getInverse() } for the reverse complement
151         */
152        public SequenceView<NucleotideCompound> getReverseComplement() {
153                return getInverse();
154        }
155
156        /**
157         * @return the dnaType
158         */
159        public DNAType getDNAType() {
160                return dnaType;
161        }
162
163        /**
164         * @param dnaType the dnaType to set
165         */
166        public void setDNAType(DNAType dnaType) {
167                this.dnaType = dnaType;
168        }
169        
170}