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 */
021
022/*
023 * Created on 2005-08-03
024 */
025package org.biojava.bio.alignment;
026
027import java.util.LinkedList;
028import java.util.List;
029import java.util.NoSuchElementException;
030
031import org.biojava.bio.seq.Sequence;
032import org.biojava.bio.seq.SequenceIterator;
033import org.biojava.bio.seq.db.SequenceDB;
034import org.biojava.bio.symbol.SymbolList;
035
036/**
037 * This Interface provides methods for the alignment of bio-sequences.
038 * 
039 * @author Andreas Dr&auml;ger <andreas.draeger@uni-tuebingen.de>
040 * @author Mark Schreiber
041 */
042public abstract class AlignmentAlgorithm {
043
044        /**
045         * @param source
046         *            a SequenceIterator containing a set of sequences to be aligned
047         *            with
048         * @param subjectDB
049         *            the SequenceDB containing another set of sequences.
050         * @return a list containing the results of all single alignments performed
051         *         by this method.
052         * @throws NoSuchElementException
053         * @throws Exception
054         */
055        public List<AlignmentPair> alignAll(SequenceIterator source,
056                        SequenceDB subjectDB) throws Exception {
057                List<AlignmentPair> l = new LinkedList<AlignmentPair>();
058                while (source.hasNext()) {
059                        Sequence query = source.nextSequence();
060                        // compare all the sequences of both sets.
061                        SequenceIterator target = subjectDB.sequenceIterator();
062                        while (target.hasNext())
063                                try {
064                                        l.add(pairwiseAlignment(query, target.nextSequence()));
065                                        // pairwiseAlignment(query, target.nextSequence());
066                                } catch (Exception exc) {
067                                        exc.printStackTrace();
068                                }
069                }
070                return l;
071        }
072
073        /**
074         * Performs a pairwise sequence alignment of the two given sequences.
075         * 
076         * @param query
077         * @param subject
078         * @return score of the alignment or the distance.
079         * @throws Exception
080         */
081        public abstract AlignmentPair pairwiseAlignment(SymbolList query, SymbolList subject)
082                        throws Exception;
083}