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
023package org.biojava.bio.dp;
024
025import java.io.Serializable;
026import java.util.HashMap;
027import java.util.Iterator;
028import java.util.List;
029import java.util.Map;
030import java.util.NoSuchElementException;
031import java.util.Set;
032
033import org.biojava.bio.alignment.Alignment;
034import org.biojava.bio.alignment.SimpleAlignment;
035import org.biojava.bio.symbol.Alphabet;
036import org.biojava.bio.symbol.Edit;
037import org.biojava.bio.symbol.IllegalAlphabetException;
038import org.biojava.bio.symbol.Location;
039import org.biojava.bio.symbol.Symbol;
040import org.biojava.bio.symbol.SymbolList;
041import org.biojava.utils.ChangeVetoException;
042import org.biojava.utils.Unchangeable;
043
044/**
045 * A no-frills implementation of StatePath.
046 *
047 * @author Matthew Pocock
048 * @author Nimesh Singh
049 */
050public class SimpleStatePath
051  extends
052    Unchangeable
053  implements
054    StatePath,
055    Serializable
056{
057  private final double score;
058  private final Alignment delegate;
059
060  public double getScore() {
061    return score;
062  }
063
064  public SimpleStatePath(
065    double score,
066    SymbolList sequence,
067    SymbolList states,
068    SymbolList scores
069  ) throws IllegalArgumentException {
070    this.score = score;
071    Map map = new HashMap();
072    map.put(StatePath.SEQUENCE, sequence);
073    map.put(StatePath.STATES, states);
074    map.put(StatePath.SCORES, scores);
075    this.delegate = new SimpleAlignment(map);
076  }
077
078  public Alphabet getAlphabet() {
079    return delegate.getAlphabet();
080  }
081
082  public List getLabels() {
083    return delegate.getLabels();
084  }
085
086  public int length() {
087    return delegate.length();
088  }
089
090  public Alignment subAlignment(Set labels, Location loc)
091  throws NoSuchElementException {
092    return delegate.subAlignment(labels, loc);
093  }
094
095  public Symbol symbolAt(int col)
096  throws IndexOutOfBoundsException {
097    return delegate.symbolAt(col);
098  }
099
100  public Symbol symbolAt(String label, int col)
101  throws IndexOutOfBoundsException, NoSuchElementException {
102    return delegate.symbolAt(label, col);
103  }
104
105  public SymbolList symbolListForLabel(String label)
106  throws NoSuchElementException {
107    return delegate.symbolListForLabel(label);
108  }
109
110  public Iterator<Symbol> iterator() {
111    return delegate.iterator();
112  }
113
114  public SymbolList subList(int start, int end) {
115    return delegate.subList(start, end);
116  }
117
118  public List<Symbol> toList() {
119    return delegate.toList();
120  }
121
122  public String seqString() {
123    return delegate.seqString();
124  }
125
126  public String subStr(int start, int end)
127  throws IndexOutOfBoundsException {
128    return delegate.subStr(start, end);
129  }
130
131  public void edit(Edit edit)
132  throws IllegalAlphabetException, IndexOutOfBoundsException, ChangeVetoException {
133    throw new ChangeVetoException("Can't edit SimpleStatePath");
134  }
135
136  public Iterator<SymbolList> symbolListIterator() {
137    return new Alignment.SymbolListIterator(this);
138  }
139}