001package com.hfg.bio.taxonomy.ncbi;
002
003import com.hfg.bio.taxonomy.SeqRepositoryDivision;
004import com.hfg.util.StringUtil;
005
006import java.util.HashMap;
007import java.util.Map;
008import java.util.Collection;
009import java.io.Serializable;
010
011
012//------------------------------------------------------------------------------
013/**
014 * Enumerated list of NCBI GenBank divisions.
015 * <div>
016 * Based on division.dmp file in ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
017 * </div>
018 * @author J. Alex Taylor, hairyfatguy.com
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041public class NCBIGenBankDivision implements SeqRepositoryDivision, Serializable
042{
043
044   //**************************************************************************
045   // PRIVATE FIELDS
046   //**************************************************************************
047
048   private String  mName;
049   private String  mCode;
050   private Integer mId;
051
052
053   private static Map<String, NCBIGenBankDivision> sUniqueIdMap = new HashMap<>(20);
054   private static Map<String, NCBIGenBankDivision> sUniqueCodeMap = new HashMap<>(20);
055
056   //**************************************************************************
057   // PUBLIC FIELDS
058   //**************************************************************************
059
060   /** Bacteria BCT 0 */
061   public static NCBIGenBankDivision BACTERIA      = new NCBIGenBankDivision("Bacteria", "BCT", 0);
062   /** Invertebrates INV 1 */
063   public static NCBIGenBankDivision INVERTEBRATES = new NCBIGenBankDivision("Invertebrates", "INV", 1);
064   /** Mammals MAM 2 */
065   public static NCBIGenBankDivision MAMMALS       = new NCBIGenBankDivision("Mammals", "MAM", 2);
066   /** Phages PHG 3 */
067   public static NCBIGenBankDivision PHAGES        = new NCBIGenBankDivision("Phages", "PHG", 3);
068   /** Plants PLN 4 */
069   public static NCBIGenBankDivision PLANTS        = new NCBIGenBankDivision("Plants", "PLN", 4);
070   /** Primates PRI 5 */
071   public static NCBIGenBankDivision PRIMATES      = new NCBIGenBankDivision("Primates", "PRI", 5);
072   /** Rodents ROD 6 */
073   public static NCBIGenBankDivision RODENTS       = new NCBIGenBankDivision("Rodents", "ROD", 6);
074   /** Synthetic SYN 7 */
075   public static NCBIGenBankDivision SYNTHETIC     = new NCBIGenBankDivision("Synthetic", "SYN", 7);
076   /** Unassigned UNA 8  (No species nodes should inherit this division assignment) */
077   public static NCBIGenBankDivision UNASSIGNED    = new NCBIGenBankDivision("Unassigned", "UNA", 8);
078   /** Viruses VRL 9 */
079   public static NCBIGenBankDivision VIRUSES       = new NCBIGenBankDivision("Viruses", "VRL", 9);
080   /** Vertebrates VRT 10 */
081   public static NCBIGenBankDivision VERTEBRATES   = new NCBIGenBankDivision("Vertebrates", "VRT", 10);
082   /** Environmental samples ENV 11   (Anonymous sequences cloned directly from the environment) */
083   public static NCBIGenBankDivision ENVIRONMENTAL_SAMPLES = new NCBIGenBankDivision("Environmental samples", "ENV", 11);
084
085   // Functional divisions
086
087   /** Constructed sequences */
088   public static NCBIGenBankDivision CONSTRUCTED = new NCBIGenBankDivision("Constructed", "CON");
089
090   /** EST sequences (Expressed Sequence Tags) */
091   public static NCBIGenBankDivision EST = new NCBIGenBankDivision("EST", "EST");
092
093   /** Patent sequences */
094   public static NCBIGenBankDivision PATENT = new NCBIGenBankDivision("Patent", "PAT");
095
096   /** STS sequences (Sequence Tagged Sites) */
097   public static NCBIGenBankDivision STS = new NCBIGenBankDivision("STS", "STS");
098
099   /** GSS sequences (Genome Survey Sequences) */
100   public static NCBIGenBankDivision GSS = new NCBIGenBankDivision("GSS", "GSS");
101
102   /** HTGS sequences (High Throughput Genomic sequences) */
103   public static NCBIGenBankDivision HTG = new NCBIGenBankDivision("HTG", "HTG");
104
105   /** HTC sequences (High Throughput cDNA sequences) */
106   public static NCBIGenBankDivision HTC = new NCBIGenBankDivision("HTC", "HTC");
107
108   /** Transcriptome Shotgun Assembly sequences */
109   public static NCBIGenBankDivision TSA = new NCBIGenBankDivision("TSA", "TSA");
110
111   //**************************************************************************
112   // CONSTRUCTORS
113   //**************************************************************************
114
115   //--------------------------------------------------------------------------
116   private NCBIGenBankDivision(String inName, String inCode, int inId)
117   {
118      this(inName, inCode);
119
120      mId = inId;
121
122      if (sUniqueIdMap.containsKey(mId + ""))
123      {
124         throw new RuntimeException("A object already exists with the id '" + mId + "'!");
125      }
126
127      sUniqueIdMap.put(mId + "", this);
128   }
129
130   //--------------------------------------------------------------------------
131   private NCBIGenBankDivision(String inName, String inCode)
132   {
133      mName = inName;
134      mCode = inCode;
135
136      if (sUniqueCodeMap.containsKey(mCode))
137      {
138         throw new RuntimeException("A object already exists with the code '" + mCode + "'!");
139      }
140
141      sUniqueCodeMap.put(mCode, this);
142   }
143
144   //**************************************************************************
145   // PUBLIC METHODS
146   //**************************************************************************
147
148   //--------------------------------------------------------------------------
149   public static Collection<NCBIGenBankDivision> values()
150   {
151      return sUniqueCodeMap.values();
152   }
153
154   //--------------------------------------------------------------------------
155   /**
156    Returns the corresponding NCBIGenBankDivision by comparing the id to the
157    id values of the enumerated set.
158    @param inId the id of the GenBank division to retrieve
159    @return NCBIGenBankDivsion object corresponding to the specified id
160    */
161   public static NCBIGenBankDivision valueOf(int inId)
162   {
163      return sUniqueIdMap.get(inId + "");
164   }
165
166   //--------------------------------------------------------------------------
167   /**
168    Returns the corresponding NCBIGenBankDivision by comparing the value to the
169    name, code, and id values of the enumerated set.
170    @param inValue the name, code, or id of the GenBank division to retrieve
171    @return NCBIGenBankDivsion object corresponding to the specified value
172    */
173   public static NCBIGenBankDivision valueOf(String inValue)
174   {
175      NCBIGenBankDivision value = null;
176
177      if (StringUtil.isSet(inValue))
178      {
179         for (NCBIGenBankDivision division : sUniqueCodeMap.values())
180         {
181            if (division.name().equalsIgnoreCase(inValue)
182                || division.getCode().equalsIgnoreCase(inValue)
183                || (division.getId() != null
184                    && (division.getId() + "").equals(inValue)))
185            {
186               value = division;
187               break;
188            }
189         }
190      }
191
192      return value;
193   }
194
195   //--------------------------------------------------------------------------
196   public String name()
197   {
198      return mName;
199   }
200
201   //--------------------------------------------------------------------------
202   /**
203    The same as name().
204    */
205   @Override
206   public String toString()
207   {
208      return name();
209   }
210
211   //--------------------------------------------------------------------------
212   /**
213    Returns the 3-letter GenBank division code.
214    @return the 3-letter GenBank division code
215    */
216   public String getCode()
217   {
218      return mCode;
219   }
220
221   //--------------------------------------------------------------------------
222   public Integer getId()
223   {
224      return mId;
225   }
226
227   //**************************************************************************
228   // PRIVATE METHODS
229   //**************************************************************************
230
231   //--------------------------------------------------------------------------
232   /**
233    * This method is called after de-serialization, allowing the object
234    * to nominate a replacement object to be used in the output
235    * graph instead of this object. We don't want multiple objects of each type
236    * to exist in a target VM, so instances replace themselves with
237    * local objects.
238    */
239   private Object readResolve()
240   {
241      return sUniqueIdMap.get(mId + "");
242   }
243}