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.ProteinSequence;
027import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
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 * Used to create a ProteinSequence from a String to allow for details
038 * about the location of the sequence etc.
039 *
040 * @author Scooter Willis <willishf at gmail dot com>
041 */
042public class ProteinSequenceCreator implements
043                SequenceCreatorInterface<AminoAcidCompound> {
044
045        private CompoundSet<AminoAcidCompound> compoundSet;
046/**
047 *
048 * @param compoundSet
049 */
050        public ProteinSequenceCreator(CompoundSet<AminoAcidCompound> compoundSet) {
051                this.compoundSet = compoundSet;
052        }
053/**
054 *
055 * @param sequence
056 * @param index not used in this implementation
057 * @return
058 * @throws CompoundNotFoundException
059 */
060        @Override
061public AbstractSequence<AminoAcidCompound> getSequence(String sequence,
062                        long index) throws CompoundNotFoundException {
063                return new ProteinSequence(sequence, compoundSet);
064        }
065/**
066 *
067 * @param list
068 * @return
069 */
070        @Override
071public AbstractSequence<AminoAcidCompound> getSequence(
072                        List<AminoAcidCompound> list) {
073                ArrayListProxySequenceReader<AminoAcidCompound> store = new ArrayListProxySequenceReader<AminoAcidCompound>();
074                store.setCompoundSet(compoundSet);
075                store.setContents(list);
076                return new ProteinSequence(store);
077        }
078/**
079 *
080 * @param proxyLoader
081 * @param index not used in this implementation
082 * @return
083 */
084        @Override
085public AbstractSequence<AminoAcidCompound> getSequence(
086                        ProxySequenceReader<AminoAcidCompound> proxyLoader, long index) {
087                return new ProteinSequence(proxyLoader, compoundSet);
088        }
089}