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