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