001package com.hfg.bio.seq.format.genbank; 002 003 004import com.hfg.exception.ProgrammingException; 005import com.hfg.util.StringUtil; 006 007import java.util.*; 008 009//------------------------------------------------------------------------------ 010/** 011 Valid keywords for the GenBank sequence format. 012 <p> 013 See <a href='ftp://ftp.ncbi.nlm.nih.gov/genbank/gbrel.txt'>ftp://ftp.ncbi.nlm.nih.gov/genbank/gbrel.txt</a> 014 </p> 015 <p> 016 See <a href='http://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html'>http://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html</a> 017 </p> 018 @author J. Alex Taylor, hairyfatguy.com 019 */ 020//------------------------------------------------------------------------------ 021// com.hfg 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 GenBankKeyword 042{ 043 private String mName; 044 private List<GenBankSubkeyword> mSubkeywords; 045 046 private static Map<String, GenBankKeyword> sUniqueMap = new HashMap<>(); 047 048 049 public static final GenBankKeyword ACCESSION = new GenBankKeyword("ACCESSION"); 050 public static final GenBankKeyword BASE_COUNT = new GenBankKeyword("BASE COUNT"); // Obsoleted in Oct 2003 051 public static final GenBankKeyword COMMENT = new GenBankKeyword("COMMENT"); 052 public static final GenBankKeyword CONTIG = new GenBankKeyword("CONTIG"); 053 public static final GenBankKeyword DBLINK = new GenBankKeyword("DBLINK"); 054 public static final GenBankKeyword DEFINITION = new GenBankKeyword("DEFINITION"); 055 public static final GenBankKeyword FEATURES = new GenBankKeyword("FEATURES"); 056 public static final GenBankKeyword KEYWORDS = new GenBankKeyword("KEYWORDS"); 057 public static final GenBankKeyword LOCUS = new GenBankKeyword("LOCUS"); 058 public static final GenBankKeyword NID = new GenBankKeyword("NID"); // Obsoleted in Dec 1999 059 public static final GenBankKeyword ORIGIN = new GenBankKeyword("ORIGIN"); 060 public static final GenBankKeyword PROJECT = new GenBankKeyword("PROJECT"); // Obsoleted in Apr 2009 061 public static final GenBankKeyword REFERENCE = new GenBankKeyword("REFERENCE"); 062 public static final GenBankKeyword SEGMENT = new GenBankKeyword("SEGMENT"); // Obsoleted in Aug 2017 063 public static final GenBankKeyword SOURCE = new GenBankKeyword("SOURCE"); 064 public static final GenBankKeyword VERSION = new GenBankKeyword("VERSION"); 065 /** Observed in GenBank files but not mentioned in the documentation */ 066 public static final GenBankKeyword PRIMARY = new GenBankKeyword("PRIMARY"); 067 068 static 069 { 070 SOURCE.addSubkeyword(GenBankSubkeyword.ORGANISM); 071 072 REFERENCE.addSubkeyword(GenBankSubkeyword.AUTHORS); 073 REFERENCE.addSubkeyword(GenBankSubkeyword.CONSRTM); 074 REFERENCE.addSubkeyword(GenBankSubkeyword.TITLE); 075 REFERENCE.addSubkeyword(GenBankSubkeyword.JOURNAL); 076 REFERENCE.addSubkeyword(GenBankSubkeyword.MEDLINE); 077 REFERENCE.addSubkeyword(GenBankSubkeyword.PUBMED); 078 REFERENCE.addSubkeyword(GenBankSubkeyword.REMARK); 079 } 080 081 //########################################################################### 082 // CONSTRUCTORS 083 //########################################################################### 084 085 //--------------------------------------------------------------------------- 086 protected GenBankKeyword(String inName) 087 { 088 if (sUniqueMap.containsKey(inName)) 089 { 090 throw new ProgrammingException("A GenBank keyword already exists with name " + StringUtil.singleQuote(inName) + "!"); 091 } 092 093 mName = inName; 094 sUniqueMap.put(inName, this); 095 } 096 097 098 //########################################################################### 099 // PUBLIC METHODS 100 //########################################################################### 101 102 //--------------------------------------------------------------------------- 103 public static GenBankKeyword valueOf(String inName) 104 { 105 return sUniqueMap.get(inName); 106 } 107 108 //--------------------------------------------------------------------------- 109 public static Collection<GenBankKeyword> values() 110 { 111 return sUniqueMap.values(); 112 } 113 114 //--------------------------------------------------------------------------- 115 @Override 116 public String toString() 117 { 118 return name(); 119 } 120 121 //--------------------------------------------------------------------------- 122 public String name() 123 { 124 return mName; 125 } 126 127 //--------------------------------------------------------------------------- 128 public boolean allowsSubkeyword(GenBankSubkeyword inSubkeyword) 129 { 130 return mSubkeywords != null && mSubkeywords.contains(inSubkeyword); 131 } 132 133 //--------------------------------------------------------------------------- 134 public List<GenBankSubkeyword> getSubkeywords() 135 { 136 return mSubkeywords; 137 } 138 139 //--------------------------------------------------------------------------- 140 private void addSubkeyword(GenBankSubkeyword inValue) 141 { 142 if (null == mSubkeywords) 143 { 144 mSubkeywords = new ArrayList<>(10); 145 } 146 147 mSubkeywords.add(inValue); 148 } 149 150}