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