001package com.hfg.bio.taxonomy.ncbi;
002
003import java.io.Serializable;
004import java.util.Collection;
005import java.util.HashMap;
006import java.util.Map;
007
008
009//------------------------------------------------------------------------------
010/**
011 * NCBI taxonomy levels.
012 * <p>
013 * Based on values in the nodes.dmp file in ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
014 * </p>
015 *
016 * @author J. Alex Taylor, hairyfatguy.com
017 */
018//------------------------------------------------------------------------------
019// com.hfg XML/HTML Coding Library
020//
021// This library is free software; you can redistribute it and/or
022// modify it under the terms of the GNU Lesser General Public
023// License as published by the Free Software Foundation; either
024// version 2.1 of the License, or (at your option) any later version.
025//
026// This library is distributed in the hope that it will be useful,
027// but WITHOUT ANY WARRANTY; without even the implied warranty of
028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
029// Lesser General Public License for more details.
030//
031// You should have received a copy of the GNU Lesser General Public
032// License along with this library; if not, write to the Free Software
033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
034//
035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
036// jataylor@hairyfatguy.com
037//------------------------------------------------------------------------------
038
039public class NCBITaxonNodeRank implements Comparable<NCBITaxonNodeRank>, Serializable
040{
041
042   //**************************************************************************
043   // PRIVATE FIELDS
044   //**************************************************************************
045
046   private String mName;
047   private int    mRank;
048
049   private static Map<String,  NCBITaxonNodeRank> sUniqueMap = new HashMap<>(30);
050
051   //**************************************************************************
052   // PUBLIC FIELDS
053   //**************************************************************************
054
055   public static NCBITaxonNodeRank SUPERKINGDOM     = new NCBITaxonNodeRank(160, "superkingdom");
056   public static NCBITaxonNodeRank KINGDOM          = new NCBITaxonNodeRank(155, "kingdom");
057   public static NCBITaxonNodeRank SUBKINGDOM       = new NCBITaxonNodeRank(150, "subkingdom");
058   public static NCBITaxonNodeRank SUPERPHYLUM      = new NCBITaxonNodeRank(145, "superphylum");
059   public static NCBITaxonNodeRank PHYLUM           = new NCBITaxonNodeRank(140, "phylum");
060   public static NCBITaxonNodeRank SUBPHYLUM        = new NCBITaxonNodeRank(135, "subphylum");
061   public static NCBITaxonNodeRank SUPERCLASS       = new NCBITaxonNodeRank(130, "superclass");
062   public static NCBITaxonNodeRank CLASS            = new NCBITaxonNodeRank(125, "class");
063   public static NCBITaxonNodeRank SUBCLASS         = new NCBITaxonNodeRank(120, "subclass");
064   public static NCBITaxonNodeRank INFRACLASS       = new NCBITaxonNodeRank(115, "infraclass");
065   public static NCBITaxonNodeRank COHORT           = new NCBITaxonNodeRank(110, "cohort");
066   public static NCBITaxonNodeRank SUBCOHORT        = new NCBITaxonNodeRank(109, "subcohort");
067   public static NCBITaxonNodeRank SUPERORDER       = new NCBITaxonNodeRank(105, "superorder");
068   public static NCBITaxonNodeRank ORDER            = new NCBITaxonNodeRank(100, "order");
069   public static NCBITaxonNodeRank SUBORDER         = new NCBITaxonNodeRank( 95, "suborder");
070   public static NCBITaxonNodeRank PARVORDER        = new NCBITaxonNodeRank( 90, "parvorder");
071   public static NCBITaxonNodeRank INFRAORDER       = new NCBITaxonNodeRank( 85, "infraorder");
072   public static NCBITaxonNodeRank SUPERFAMILY      = new NCBITaxonNodeRank( 80, "superfamily");
073   public static NCBITaxonNodeRank FAMILY           = new NCBITaxonNodeRank( 75, "family");
074   public static NCBITaxonNodeRank SUBFAMILY        = new NCBITaxonNodeRank( 70, "subfamily");
075   public static NCBITaxonNodeRank TRIBE            = new NCBITaxonNodeRank( 65, "tribe");
076   public static NCBITaxonNodeRank SUBTRIBE         = new NCBITaxonNodeRank( 60, "subtribe");
077   public static NCBITaxonNodeRank GENUS            = new NCBITaxonNodeRank( 55, "genus");
078   public static NCBITaxonNodeRank SUBGENUS         = new NCBITaxonNodeRank( 50, "subgenus");
079   public static NCBITaxonNodeRank SPECIES_GROUP    = new NCBITaxonNodeRank( 45, "species group");
080   public static NCBITaxonNodeRank SPECIES_SUBGROUP = new NCBITaxonNodeRank( 40, "species subgroup");
081   public static NCBITaxonNodeRank SPECIES          = new NCBITaxonNodeRank( 35, "species");
082   public static NCBITaxonNodeRank SUBSPECIES       = new NCBITaxonNodeRank( 30, "subspecies");
083   public static NCBITaxonNodeRank STRAIN           = new NCBITaxonNodeRank( 25, "strain");
084   public static NCBITaxonNodeRank VARIETAS         = new NCBITaxonNodeRank( 20, "varietas");
085   public static NCBITaxonNodeRank SUBVARIETY       = new NCBITaxonNodeRank( 19, "subvariety");
086   public static NCBITaxonNodeRank FORMA            = new NCBITaxonNodeRank( 15, "forma");
087   public static NCBITaxonNodeRank FORMA_SPECIALIS  = new NCBITaxonNodeRank( 14, "forma specialis");
088   public static NCBITaxonNodeRank SEROGROUP        = new NCBITaxonNodeRank( 10, "serogroup");
089   public static NCBITaxonNodeRank SEROTYPE         = new NCBITaxonNodeRank(  9, "serotype");
090   public static NCBITaxonNodeRank CLADE            = new NCBITaxonNodeRank(  7, "clade");
091   public static NCBITaxonNodeRank MORPH            = new NCBITaxonNodeRank(  6, "morph");
092   public static NCBITaxonNodeRank BIOTYPE          = new NCBITaxonNodeRank(  5, "biotype");
093   public static NCBITaxonNodeRank GENOTYPE         = new NCBITaxonNodeRank(  4, "genotype");
094   public static NCBITaxonNodeRank ISOLATE          = new NCBITaxonNodeRank(  3, "isolate");
095   public static NCBITaxonNodeRank SECTION          = new NCBITaxonNodeRank(  2, "section");
096   public static NCBITaxonNodeRank SUBSECTION       = new NCBITaxonNodeRank(  1, "subsection");
097   public static NCBITaxonNodeRank SERIES           = new NCBITaxonNodeRank(  0, "series");
098   public static NCBITaxonNodeRank PATHOGROUP       = new NCBITaxonNodeRank(  0, "pathogroup");
099   public static NCBITaxonNodeRank NO_RANK          = new NCBITaxonNodeRank( -1, "no rank");
100
101
102   //**************************************************************************
103   // CONSTRUCTORS
104   //**************************************************************************
105
106   //--------------------------------------------------------------------------
107   private NCBITaxonNodeRank(int inRank, String inName)
108   {
109      mRank = inRank;
110      mName = inName;
111
112      if (sUniqueMap.containsKey(mName))
113      {
114         throw new RuntimeException("A object already exists with the name '" + mName + "'!");
115      }
116
117      sUniqueMap.put(mName, this);
118   }
119
120   //**************************************************************************
121   // PUBLIC METHODS
122   //**************************************************************************
123
124   //--------------------------------------------------------------------------
125   public static Collection<NCBITaxonNodeRank> values()
126   {
127      return sUniqueMap.values();
128   }
129
130   //--------------------------------------------------------------------------
131   public static NCBITaxonNodeRank valueOf(String inValue)
132   {
133      return sUniqueMap.get(inValue);
134   }
135
136   //--------------------------------------------------------------------------
137   public int compareTo(NCBITaxonNodeRank inObj)
138   {
139      return inObj != null ? mRank - inObj.mRank : 1;
140   }
141
142   //--------------------------------------------------------------------------
143   public String name()
144   {
145      return mName;
146   }
147
148   //--------------------------------------------------------------------------
149   /**
150    The same as name().
151    */
152   @Override
153   public String toString()
154   {
155      return name();
156   }
157
158   //**************************************************************************
159   // PRIVATE METHODS
160   //**************************************************************************
161
162   //--------------------------------------------------------------------------
163   /**
164    * This method is called after de-serialization, allowing the object
165    * to nominate a replacement object to be used in the output
166    * graph instead of this object. We don't want multiple objects of each type
167    * to exist in a target VM, so instances replace themselves with
168    * local objects.
169    */
170   private Object readResolve()
171   {
172      return sUniqueMap.get(mName);
173   }
174}