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 01-21-2010
021 */
022
023 package org.biojava3.core.sequence.io;
024
025 import java.util.List;
026
027 import org.biojava3.core.sequence.DNASequence;
028 import org.biojava3.core.sequence.compound.NucleotideCompound;
029 import org.biojava3.core.sequence.io.template.SequenceCreatorInterface;
030 import org.biojava3.core.sequence.loader.ArrayListProxySequenceReader;
031 import org.biojava3.core.sequence.template.AbstractSequence;
032 import org.biojava3.core.sequence.template.CompoundSet;
033 import org.biojava3.core.sequence.template.ProxySequenceReader;
034
035 /**
036 * A helper class that allows different ways to read a string and create a DNA sequence. Used in FastaReaderHelper
037 * and probably a layer that isn't needed
038 *
039 * @author Scooter Willis <willishf at gmail dot com>
040 */
041 public class DNASequenceCreator implements
042 SequenceCreatorInterface<NucleotideCompound> {
043
044 private final CompoundSet<NucleotideCompound> compoundSet;
045
046 /**
047 *
048 * @param compoundSet
049 */
050 public DNASequenceCreator(CompoundSet<NucleotideCompound> compoundSet) {
051 this.compoundSet = compoundSet;
052 }
053
054 /**
055 *
056 * @param sequence The Sequence from a String
057 * @param index Currently not used
058 * @return
059 */
060 public AbstractSequence<NucleotideCompound> getSequence(String sequence,
061 long index) {
062 return new DNASequence(sequence, compoundSet);
063 }
064 /**
065 *
066 * @param proxyLoader The Sequence from a ProxySequenceReader
067 * @param index Currently not used
068 * @return
069 */
070 public AbstractSequence<NucleotideCompound> getSequence(
071 ProxySequenceReader<NucleotideCompound> proxyLoader, long index) {
072 return new DNASequence(proxyLoader, compoundSet);
073 }
074
075 /**
076 *
077 * @param list
078 * @return
079 */
080 public AbstractSequence<NucleotideCompound> getSequence(
081 List<NucleotideCompound> list) {
082 ArrayListProxySequenceReader<NucleotideCompound> store = new ArrayListProxySequenceReader<NucleotideCompound>();
083 store.setCompoundSet(compoundSet);
084 store.setContents(list);
085 return new DNASequence(store);
086 }
087 }