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 * 021 */ 022package org.biojava.nbio.structure.io.mmcif.chem; 023 024import java.io.Serializable; 025import java.util.*; 026 027/** 028 * Enumerates the classification of polymers. 029 * This information is derived from the mmcif dictionary 030 * @author mulvaney 031 * @author Andreas Prlic 032 * @see <a href="http://mmcif.rcsb.org/dictionaries/mmcif_pdbx.dic/Items/_entity_poly.type.html">link into mmCIF dictionary</a> 033 * @since 1.7 034 */ 035public enum PolymerType implements Serializable 036{ 037 038 /** 039 * polypeptide(L) 040 */ 041 peptide("polypeptide(L)"), 042 043 /** 044 * polypeptide(D) 045 */ 046 dpeptide("polypeptide(D)"), 047 048 /** 049 * polydeoxyribonucleotide 050 */ 051 dna("polydeoxyribonucleotide"), 052 053 /** 054 * polyribonucleotide 055 */ 056 rna("polyribonucleotide"), 057 058 /** 059 * polydeoxyribonucleotide/polyribonucleotide hybrid 060 */ 061 dnarna("polydeoxyribonucleotide/polyribonucleotide hybrid"), 062 063 /** 064 * polysaccharide(D) 065 */ 066 polysaccharide("polysaccharide(D)"), 067 068 /** 069 * polysaccharide(L) 070 */ 071 lpolysaccharide("polysaccharide(L)"), 072 073 /** 074 * other 075 */ 076 otherPolymer("other"), 077 078 /** 079 * cyclic peptides 080 */ 081 cyclicPeptide("cyclic-pseudo-peptide"), 082 083 /** 084 * Peptide nucleic acids 085 */ 086 peptideNucleicAcid("peptide nucleic acid"), 087 088 /** 089 * if all else fails... 090 */ 091 unknown(null); 092 093 static Map<String,PolymerType> lookupTable = new HashMap<>(); 094 095 static { 096 097 for (PolymerType rt : PolymerType.values() ) { 098 if ( rt == unknown) 099 continue; 100 lookupTable.put(rt.entity_poly_type,rt); 101 lookupTable.put(rt.entity_poly_type.toLowerCase(),rt); 102 } 103 } 104 105 106 PolymerType(String entity_poly_type) 107 { 108 this.entity_poly_type = entity_poly_type; 109 } 110 public final String entity_poly_type; 111 112 public static PolymerType polymerTypeFromString(String polymerType) 113 { 114 115 if ( polymerType.equalsIgnoreCase(peptide.entity_poly_type)) 116 return peptide; 117 118 PolymerType ptype = lookupTable.get(polymerType); 119 if ( ptype != null) 120 return ptype; 121 122 ptype = lookupTable.get(polymerType.toLowerCase()); 123 if ( ptype != null) 124 return ptype; 125 126 127 for(PolymerType pt : PolymerType.values()) 128 { 129 if(polymerType.equals(pt.entity_poly_type)) 130 { 131 return pt; 132 } 133 } 134 return unknown; 135 } 136 137 /** 138 * Convenience <tt>Set</tt> of polymer types classified as protein. This only contains {@link #peptide} 139 */ 140 public static final Set<PolymerType> PROTEIN_ONLY; 141 142 /** 143 * Convenience <tt>Set</tt> of polymer types classified as DNA. This only contains {@link #dna} 144 */ 145 public static final Set<PolymerType> DNA_ONLY; 146 147 /** 148 * Convenience <tt>Set</tt> of polymer types classified as RNA. This only contains {@link #rna} 149 */ 150 public static final Set<PolymerType> RNA_ONLY; 151 152 /** 153 * Convenience <tt>Set</tt> of polymer types classified as DNA. This contains: 154 * <ul> 155 * <li>{@link #dna}</li> 156 * <li>{@link #rna}</li> 157 * <li>{@link #dnarna}</li> 158 * </ul> 159 */ 160 public static final Set<PolymerType> POLYNUCLEOTIDE_ONLY; 161 162 /** 163 * Convenience <tt>Set</tt> of all polymer types. 164 */ 165 public static final Set<PolymerType> ALL_POLYMER_TYPES; 166 167 static { 168 Set<PolymerType> tmp; 169 170 tmp = new HashSet<PolymerType>(); 171 tmp.add(peptide); 172 PROTEIN_ONLY = Collections.unmodifiableSet(tmp); 173 174 tmp = new HashSet<PolymerType>(); 175 tmp.add(dna); 176 DNA_ONLY = Collections.unmodifiableSet(tmp); 177 178 tmp = new HashSet<PolymerType>(); 179 tmp.add(rna); 180 RNA_ONLY = Collections.unmodifiableSet(tmp); 181 182 tmp = new HashSet<PolymerType>(); 183 tmp.add(dna); 184 tmp.add(rna); 185 tmp.add(dnarna); 186 POLYNUCLEOTIDE_ONLY = Collections.unmodifiableSet(tmp); 187 188 ALL_POLYMER_TYPES = Collections.unmodifiableSet(new HashSet<PolymerType>(Arrays.asList(values()))); 189 } 190 191}