001/* 002 003 * BioJava development code 004 005 * 006 007 * This code may be freely distributed and modified under the 008 009 * terms of the GNU Lesser General Public Licence. This should 010 011 * be distributed with the code. If you do not have a copy, 012 013 * see: 014 015 * 016 017 * http://www.gnu.org/copyleft/lesser.html 018 019 * 020 021 * Copyright for this code is held jointly by the individual 022 023 * authors. These should be listed in @author doc comments. 024 025 * 026 027 * For more information on the BioJava project and its aims, 028 029 * or to join the biojava-l mailing list, visit the home page 030 031 * at: 032 033 * 034 035 * http://www.biojava.org/ 036 037 * 038 039 */ 040 041 042 043package org.biojava.bio.proteomics; 044 045import java.io.ObjectStreamException; 046import java.io.Serializable; 047 048import org.biojava.bio.BioError; 049import org.biojava.bio.BioException; 050import org.biojava.bio.seq.ProteinTools; 051import org.biojava.bio.seq.io.SymbolTokenization; 052import org.biojava.bio.symbol.Alphabet; 053import org.biojava.bio.symbol.AlphabetManager; 054import org.biojava.bio.symbol.FiniteAlphabet; 055import org.biojava.bio.symbol.IllegalSymbolException; 056import org.biojava.bio.symbol.SimpleSymbolList; 057import org.biojava.bio.symbol.SymbolList; 058 059 060 061 062 063/** The protease class stores parameters needed by Digest to digest a protein sequence. 064 065 * A custom protease can be created or one derived from the attributes set in the 066 067 * ProteaseManager.xml resource. 068 069 * @author Michael Jones 070 * @author Mark Schreiber (refactoring to ProteaseManager) 071 072 */ 073 074public class Protease implements Serializable { 075 076 public static final String TRYPSIN = ProteaseManager.TRYPSIN; 077 public static final String LYS_C = ProteaseManager.LYS_C; 078 public static final String ARG_C = ProteaseManager.ARG_C; 079 public static final String ASP_N = ProteaseManager.ASP_N; 080 public static final String GLU_C_BICARB = ProteaseManager.GLU_C_BICARB; 081 public static final String GLU_C_PHOS = ProteaseManager.GLU_C_PHOS; 082 public static final String CHYMOTRYP = ProteaseManager.CHYMOTRYP; 083 public static final String CNBr = ProteaseManager.CNBr; 084 085 private SymbolList cleavageResidues; 086 087 private SymbolList notCleaveResidues; 088 089 private boolean endoProtease = true; 090 private String name; 091 092 093 protected Protease(SymbolList cleaveRes, 094 boolean endoProtease, 095 SymbolList notCleaveRes, 096 String name)throws IllegalSymbolException{ 097 098 if(cleaveRes.getAlphabet() != ProteinTools.getAlphabet()){ 099 throw new IllegalSymbolException 100 ("Cleaveage residues must be from the PROTEIN alphabet"); 101 } 102 if(notCleaveRes.getAlphabet() != ProteinTools.getAlphabet() && 103 notCleaveRes.getAlphabet() != Alphabet.EMPTY_ALPHABET){ 104 throw new IllegalSymbolException 105 ("Cleaveage residues must be from the PROTEIN alphabet or an EmptySymbolList"); 106 } 107 this.cleavageResidues = cleaveRes; 108 this.endoProtease = endoProtease; 109 this.notCleaveResidues = notCleaveRes; 110 this.name = name; 111 } 112 113 /** 114 * @deprecated Creating a Protease with this constructor will not register it 115 * with the ProteaseManager (use ProteaseManager.createProtease()) 116 */ 117 118 public Protease(SymbolList cleaveRes, 119 120 boolean endoProtease, 121 122 SymbolList notCleaveRes) 123 124 throws IllegalSymbolException, BioException { 125 126 127 128 } 129 130 131 132 133 /** 134 * @deprecated Creating a Protease with this constructor will not register it 135 * with the ProteaseManager (use ProteaseManager.createProtease()) 136 */ 137 138 public Protease(String cleaveRes, 139 140 boolean endoProtease, 141 142 String notCleaveRes) 143 144 throws IllegalSymbolException, BioException { 145 146 this.cleavageResidues = createSymbolList(cleaveRes); 147 148 this.endoProtease = endoProtease; 149 150 this.notCleaveResidues = createSymbolList(notCleaveRes); 151 152 } 153 154 155 156 /** 157 * @deprecated Creating a Protease with this constructor will not register it 158 * with the ProteaseManager (use ProteaseManager.createProtease()) 159 */ 160 161 public Protease(String cleavageRes, boolean endoProtease) 162 163 throws IllegalSymbolException, BioException { 164 165 this.cleavageResidues = createSymbolList(cleavageRes); 166 167 this.endoProtease = endoProtease; 168 169 this.notCleaveResidues = createSymbolList(""); 170 171 } 172 173 174 /** 175 * The list of residues that the protease will cleave at. 176 * @return the residues as a SymbolList 177 */ 178 public SymbolList getCleaveageResidues() 179 180 { 181 return cleavageResidues; 182 } 183 184 /** 185 * Gets the name of this Protease 186 * @return the name as a String 187 */ 188 public String getName(){ 189 return name; 190 } 191 192 193 /** 194 * The list of residues that will prevent cleavage if they follow the cleavage 195 * residue. 196 */ 197 public SymbolList getNotCleaveResidues() 198 199 { 200 return notCleaveResidues; 201 } 202 203 204 205 public boolean isEndoProtease() 206 207 { 208 209 return endoProtease; 210 211 } 212 213 214 215 216 217 /** 218 * Get the list of Protease names defined in the ProteaseManager 219 * (Internally calls ProteaseManager. 220 * @return A String array of protease names 221 */ 222 223 public static String[] getProteaseList(){ 224 java.util.Set s = ProteaseManager.getNames(); 225 String[] names = new String[s.size()]; 226 return (String[])s.toArray(names); 227 } 228 229 230 231 /** 232 * Retrieves a reference to the named Protease. 233 * (Internally calls ProteaseManager.getProteaseByName()) 234 * @param proteaseName A protease name that is registered in the ProteaseManager (case sensitive) 235 * @return A Protease instance for the given protease name 236 */ 237 238 public static final Protease getProteaseByName(String proteaseName) 239 throws BioException { 240 return ProteaseManager.getProteaseByName(proteaseName); 241 242 } 243 244 245 246 private SymbolList createSymbolList(String seq) 247 248 throws IllegalSymbolException, BioException { 249 250 if(seq == null || seq.trim().equals("")){ 251 return SymbolList.EMPTY_LIST; 252 } 253 254 SymbolList sList; 255 256 FiniteAlphabet prot 257 258 = (FiniteAlphabet)AlphabetManager.alphabetForName("PROTEIN"); 259 260 261 262 SymbolTokenization tokenization = prot.getTokenization("token"); 263 264 sList = new SimpleSymbolList (tokenization, seq); 265 266 return sList; 267 268 } 269 270 /** 271 * Prevent duplication of the object during Serialization 272 * @throws ObjectStreamException 273 */ 274 protected Object readResolve() throws ObjectStreamException{ 275 try { 276 if(ProteaseManager.registered(this.getName())){ 277 return ProteaseManager.getProteaseByName(this.getName()); 278 }else{ 279 ProteaseManager.registerProtease(this); 280 return this; 281 } 282 } 283 catch (BioException ex) { 284 throw new BioError( 285 "Assertion Error: Cannot register Protease instance following de serialization", ex 286 ); 287 } 288 } 289 290} 291