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 DATE
021     *
022     */
023    package org.biojava3.core.sequence;
024    
025    import java.util.LinkedHashMap;
026    import org.biojava3.core.sequence.compound.DNACompoundSet;
027    import org.biojava3.core.sequence.compound.NucleotideCompound;
028    import org.biojava3.core.sequence.template.CompoundSet;
029    import org.biojava3.core.sequence.template.ProxySequenceReader;
030    
031    /**
032     * A ChromosomeSequence is a DNASequence but keeps track of geneSequences
033     * @author Scooter Willis
034     */
035    public class ChromosomeSequence extends DNASequence {
036    
037        private int chromosomeNumber;
038        private LinkedHashMap<String, GeneSequence> geneSequenceHashMap = new LinkedHashMap<String, GeneSequence>();
039    
040        /**
041         * Empty constructor used by tools that need a proper Bean that allows the actual
042         * sequence data to be set after construction. Not recommended
043         */
044        public ChromosomeSequence() {
045    //        throw new UnsupportedOperationException("Null constructor not supported");
046        }
047    
048        /**
049         * String is king and assume DNA
050         * @param seqString
051         */
052        public ChromosomeSequence(String seqString) {
053            super(seqString, DNACompoundSet.getDNACompoundSet());
054        }
055    
056        /**
057         * Fairly important constructor given the size of a ChromsomeSequence where the
058         * ProxySequenceReader could load from disk via RandomAccessFile so that the sequence
059         * doesn't need to be kept in memory. Could also be a NCBI proxy to load sequence
060         * data as needed from remote web server.
061         * @param proxyLoader
062         */
063        public ChromosomeSequence(ProxySequenceReader<NucleotideCompound> proxyLoader) {
064            super(proxyLoader, DNACompoundSet.getDNACompoundSet());
065        }
066    
067        /**
068         * Allows the creation of a ChromosomeSequence using String for the sequence with a custom CompoundSet
069         * @param seqString
070         * @param compoundSet
071         */
072        public ChromosomeSequence(String seqString, CompoundSet<NucleotideCompound> compoundSet) {
073            super(seqString, compoundSet);
074        }
075    
076        /**
077         * Allows the creation of a ChromosomeSequence using a ProxyResequenceReader for the sequence with a custom CompoundSet
078         * @param proxyLoader
079         * @param compoundSet
080         */
081        public ChromosomeSequence(ProxySequenceReader<NucleotideCompound> proxyLoader, CompoundSet<NucleotideCompound> compoundSet) {
082            super(proxyLoader, compoundSet);
083        }
084    
085        /**
086         * @return the chromosomeNumber
087         */
088        public int getChromosomeNumber() {
089            return chromosomeNumber;
090        }
091    
092        /**
093         * @param chromosomeNumber the chromosomeNumber to set
094         */
095        public void setChromosomeNumber(int chromosomeNumber) {
096            this.chromosomeNumber = chromosomeNumber;
097        }
098    
099        /**
100         * Get the list of genes that have been added to the ChromosomeSequence where accession.toString is the key.
101         * The list retains the order the genes are added
102         * @return
103         */
104    
105        public LinkedHashMap<String, GeneSequence> getGeneSequences() {
106            return geneSequenceHashMap;
107        }
108    
109        /**
110         *
111         * @param accession
112         * @return
113         */
114        public GeneSequence removeGeneSequence(String accession) {
115            return geneSequenceHashMap.remove(accession);
116        }
117    
118        /**
119         * Add a gene to the chromosome sequence using bioIndexing starts at 1 instead of 0. The
120         * GeneSequence that is returned will have a reference to parent chromosome sequence
121         * which actually contains the sequence data. Strand is important for positive and negative
122         * direction where negative strand means we need reverse complement. If negative strand then
123         * bioBegin will be greater than bioEnd
124         *
125         *
126         * @param accession
127         * @param begin
128         * @param end
129         * @param strand
130         * @return
131         */
132        public GeneSequence addGene(AccessionID accession, int bioBegin, int bioEnd, Strand strand) {
133            GeneSequence geneSequence = new GeneSequence(this, bioBegin, bioEnd, strand);
134            geneSequence.setAccession(accession);
135            geneSequenceHashMap.put(accession.toString(), geneSequence);
136            return geneSequence;
137        }
138    
139        /**
140         * Get the gene based on accession. Will return null if not found
141         * @param accession
142         * @return
143         */
144        public GeneSequence getGene(String accession) {
145            return geneSequenceHashMap.get(accession);
146        }
147    }