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
022package org.biojava.bio.chromatogram;
023
024import java.util.Map;
025
026import org.biojava.bio.symbol.AtomicSymbol;
027import org.biojava.bio.symbol.IllegalAlphabetException;
028import org.biojava.bio.symbol.IllegalSymbolException;
029import org.biojava.bio.symbol.SymbolList;
030import org.biojava.utils.SmallMap;
031
032/**
033 * A basic chromatogram implementation which provides public mutators 
034 * for setting the various attributes of the chromatogram.  
035 * <p>
036 * In general, <b>new chromatogram implementations</b> should be derived from
037 * {@link AbstractChromatogram}, <b>not this class</b>, as it is generally 
038 * undesirable to allow the internal structures of a {@link Chromatogram} to be
039 * manipulated externally. This class could still be useful, however, for 
040 * programatically generated "chromatograms".
041 * </p>
042 *
043 * @author Rhett Sutphin (<a href="http://genome.uiowa.edu/">UI CBCB</a>)
044 * @author Matthew Pocock
045 * @since 1.3
046 */
047public class SimpleChromatogram extends AbstractChromatogram {
048    
049    /** Creates a new instance of SimpleChromatogram. */
050    public SimpleChromatogram() {
051        super();
052    }
053    
054    /**
055     * Set the DNA and OFFSETS symbol lists for the basecall alignment.  Beware:
056     * this method does no consistency checks to be sure that all the offsets
057     * are valid indices into the trace arrays.
058     *
059     * @param dna a symbol list in the DNA alphabet that contains the base calls
060     *        for this chromatogram
061     * @param offsets a symbol list in an integer or sub-integer alphabet that
062     *        contains the locations in the chromatogram for the bases called 
063     *        in <code>dna</code>
064     * @throws IllegalAlphabetException when the alphabets aren't as specified
065     * @throws IllegalArgumentException when the lists aren't the same length
066     */
067    public void setSymbolLists(SymbolList dna, SymbolList offsets)
068    throws IllegalAlphabetException, IllegalArgumentException {
069        if (dna.length() != offsets.length())
070            throw new IllegalArgumentException("The SymbolLists must be the same length");
071        Map map = new SmallMap(2);
072        map.put(Chromatogram.DNA, dna);
073        map.put(Chromatogram.OFFSETS, offsets);
074        super.setBaseCallAlignment(super.createImmutableAlignment(map));
075    }
076    
077    /**
078     * Sets the trace array for one of the DNA nucleotides.  The provided
079     * array <i>will not be copied</i>, so any modifications to it will be
080     * reflected in calls to {@link #getTrace}.
081     * <p>
082     * If you need to set a new set of traces whose length is different
083     * from the old set, you must call {@link #clearTraceValues} first,
084     * or you will provoke an <code>IllegalArgumentException</code>.
085     * </p>
086     *
087     * @param nuc the nucleotide for which to set the trace
088     * @param trace the sampled intensities along the trace
089     * @param maxVal the maximum value on the trace, or {@link java.lang.Integer#MIN_VALUE}
090     *        to force this method to calculate it
091     * @throws IllegalArgumentException when trace.length is different
092     *         from any of the existing (non-null) traces
093     * @throws IllegalSymbolException when nuc is not a concrete DNA nucleotide
094     */
095    public void setTraceValues(AtomicSymbol nuc, int[] trace, int maxVal)
096    throws IllegalArgumentException, IllegalSymbolException {
097        super.setTrace(nuc, trace, maxVal);
098    }
099    
100    /**
101     * Sets all the traces to null.
102     */
103    public void clearTraceValues() {
104        super.clearTraces();
105    }
106    
107    /**
108     * Sets the number of significant bits in the data.
109     * @param bits how many bits of the trace samples are significant
110     * @see Chromatogram#getSignificantBits
111     */
112    public void setSignificantBits(int bits) {
113        super.setBits(bits);
114    }
115    
116    protected AbstractChromatogram reverseComplementInstance() {
117        return new SimpleChromatogram();
118    }
119}