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 * Created on Sep 3, 2007 021 * 022 */ 023package org.biojava.nbio.structure; 024 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028import java.io.Serializable; 029import java.lang.reflect.Method; 030import java.util.Formatter; 031import java.util.Locale; 032 033 034/** A class to represent database cross references. This is just a simple bean that contains the infor from one 035 * DBREF line 036 * 037 * @author Andreas Prlic 038 * @since 4:56:14 PM 039 * @version %I% %G% 040 */ 041public class DBRef implements PDBRecord, Serializable{ 042 043 private final static Logger logger = LoggerFactory.getLogger(DBRef.class); 044 045 private static final long serialVersionUID = -1050178577542224379L; 046 047 private Structure parent; 048 private String idCode; 049 private String chainId; 050 private int seqbegin; 051 private char insertBegin; 052 private int seqEnd; 053 private char insertEnd; 054 055 private String database; 056 private String dbAccession; 057 private String dbIdCode; 058 059 private int dbSeqBegin; 060 private char idbnsBegin; 061 private int dbSeqEnd; 062 private char idbnsEnd; 063 064 private Long id; 065 066 public DBRef() { 067 insertBegin = ' '; 068 insertEnd = ' '; 069 idbnsBegin = ' '; 070 idbnsEnd = ' '; 071 } 072 073 /** Get the ID used by Hibernate. 074 * 075 * @return the ID used by Hibernate 076 * @see #setId(Long) 077 */ 078 public Long getId() { 079 return id; 080 } 081 082 /** Set the ID used by Hibernate. 083 * 084 * @param id the id assigned by Hibernate 085 * @see #getId() 086 */ 087 public void setId(Long id) { 088 this.id = id; 089 } 090 091 /** Set the structure object that this DBRef relates to. 092 * 093 * @param s a structure object 094 * @see #getParent() 095 */ 096 public void setParent(Structure s){ 097 parent = s; 098 099 } 100 101 /** Get the structure object that this DBRef relates to. 102 * 103 * @return s a structure object 104 * @see #setParent(Structure) 105 */ 106 public Structure getParent(){ 107 return parent; 108 } 109 110 /** Convert the DBRef object to a DBREF record as it is used in PDB files 111 * 112 * @return a PDB - DBREF formatted line 113 */ 114 @Override 115 public String toPDB(){ 116 117 StringBuffer buf = new StringBuffer(); 118 toPDB(buf); 119 return buf.toString(); 120 121 } 122 123 /** Append the PDB representation of this DBRef to the provided StringBuffer 124 * 125 * @param buf the StringBuffer to write to. 126 */ 127 @Override 128 public void toPDB(StringBuffer buf){ 129 Formatter formatter = new Formatter(new StringBuilder(),Locale.UK); 130// DBREF 3ETA A 990 1295 UNP P06213 INSR_HUMAN 1017 1322 131// DBREF 3EH2 A 2 767 UNP P53992 SC24C_HUMAN 329 1094 132// DBREF 3EH2 A 2 767 UNP P53992 SC24C_HUMAN 329 1094 133// DBREF 3ETA A 990 1295 UNP P06213 INSR_HUMAN 1017 1322 134 formatter.format("DBREF %4s %1s %4d%1s %4d%1s %-6s %-8s %-12s%6d%1c%6d%1c ", 135 idCode, chainId,seqbegin,insertBegin,seqEnd,insertEnd, 136 database,dbAccession,dbIdCode, 137 dbSeqBegin,idbnsBegin,dbSeqEnd,idbnsEnd 138 ); 139 140 buf.append(formatter.toString()); 141 formatter.close(); 142 143 } 144 /** String representation of a DBRef. 145 * @return a String 146 */ 147 @Override 148 public String toString(){ 149 StringBuilder buf = new StringBuilder(); 150 151 try { 152 153 @SuppressWarnings("rawtypes") 154 Class c = Class.forName(DBRef.class.getName()); 155 Method[] methods = c.getMethods(); 156 157 for (Method m : methods) { 158 String name = m.getName(); 159 160 if (name.substring(0, 3).equals("get")) { 161 if (name.equals("getClass")) { 162 continue; 163 } 164 Object o = m.invoke(this); 165 if (o != null) { 166 buf.append(name.substring(3, name.length())); 167 buf.append(": ").append(o).append(" "); 168 } 169 } 170 } 171 } catch (Exception e){ 172 logger.error("Exception: ", e); 173 } 174 175 return buf.toString(); 176 } 177 178 179 /** get the idCode for this entry 180 * 181 * @return the idCode 182 * @see #setIdCode(String) 183 */ 184 public String getIdCode() { 185 return idCode; 186 } 187 188 /** Set the idCode for this entry. 189 * 190 * @param idCode the idCode for this entry 191 * @see #getIdCode() 192 */ 193 public void setIdCode(String idCode) { 194 this.idCode = idCode; 195 } 196 197 /** The chain ID of the corresponding chain. 198 * 199 * @return chainId the ID of the corresponding chain. 200 */ 201 public String getChainId() { 202 return chainId; 203 } 204 205 206 /** The chain ID of the corresponding chain. 207 * 208 * @param chainId the ID of the corresponding chain 209 * @see #getChainId() 210 */ 211 public void setChainId(String chainId) { 212 this.chainId = chainId; 213 } 214 215 216 /** The database of the db-ref. 217 * uses the abbreviation as provided in the PDB files: 218 * 219 *<pre> Database name database 220 (code in columns 27 - 32) 221 ---------------------------------------------------------- 222 GenBank GB 223 Protein Data Bank PDB 224 Protein Identification Resource PIR 225 SWISS-PROT SWS 226 TREMBL TREMBL 227 UNIPROT UNP 228 </pre> 229 * @return name of database of this DBRef 230 * @see #setDatabase(String) 231 */ 232 public String getDatabase() { 233 return database; 234 } 235 236 /** Specifies the database value. 237 * 238 * @param database the database 239 * @see #getDatabase() 240 */ 241 public void setDatabase(String database) { 242 this.database = database; 243 } 244 245 /** Sequence database accession code. 246 * @return the dbAccession 247 * @see #setDbAccession(String) 248 * */ 249 public String getDbAccession() { 250 return dbAccession; 251 } 252 253 /** Sequence database accession code. 254 * @param dbAccession the dbAccession 255 * @see #getDbAccession() 256 * */ 257 public void setDbAccession(String dbAccession) { 258 this.dbAccession = dbAccession; 259 } 260 261 262 /** Sequence database identification code. 263 * 264 * @return the dbIdCode 265 * @see #setDbIdCode(String) 266 */ 267 public String getDbIdCode() { 268 return dbIdCode; 269 } 270 271 /** Sequence database identification code. 272 * 273 * @param dbIdCode identification code 274 * @see #getDbIdCode() 275 */ 276 public void setDbIdCode(String dbIdCode) { 277 this.dbIdCode = dbIdCode; 278 } 279 280 /** Initial sequence number of the 281 database seqment. 282 * @return position 283 * @see #setDbSeqBegin(int) 284 */ 285 public int getDbSeqBegin() { 286 return dbSeqBegin; 287 } 288 289 290 /** Initial sequence number of the 291 database seqment. 292 * @param dbSeqBegin a sequence position 293 * @see #getDbSeqBegin() 294 * 295 */ 296 public void setDbSeqBegin(int dbSeqBegin) { 297 this.dbSeqBegin = dbSeqBegin; 298 } 299 300 301 /** Ending sequence position of the database segment. 302 * @return dbSeqEnd 303 * @see #setDbSeqEnd(int) 304 */ 305 public int getDbSeqEnd() { 306 return dbSeqEnd; 307 } 308 309 310 /** The begin of the sequence position in the database 311 * 312 * @param dbSeqEnd sequence position 313 * @see #getDbSeqEnd() 314 */ 315 public void setDbSeqEnd(int dbSeqEnd) { 316 this.dbSeqEnd = dbSeqEnd; 317 } 318 319 /** Insertion code of initial residue of the segment, if PDB is the 320 reference. 321 * @return idbnsBegin isnertion code 322 * @see #setIdbnsBegin(char) 323 * */ 324 public char getIdbnsBegin() { 325 return idbnsBegin; 326 } 327 328 /** Insertion code of initial residue of the segment, if PDB is the 329 reference. 330 * @param idbnsBegin insertion code 331 * @see #getIdbnsBegin() 332 * */ 333 public void setIdbnsBegin(char idbnsBegin) { 334 this.idbnsBegin = idbnsBegin; 335 } 336 337 /** Insertion code of the ending 338 residue of the segment, if PDB is 339 the reference. 340 * @return idbnsEnd insertion code 341 * @see #setIdbnsEnd(char) 342 */ 343 public char getIdbnsEnd() { 344 return idbnsEnd; 345 } 346 347 348 /** Insertion code of the ending 349 residue of the segment, if PDB is 350 the reference. 351 * @param idbnsEnd the insertion code 352 * @see #setIdbnsEnd(char) 353 */ 354 public void setIdbnsEnd(char idbnsEnd) { 355 this.idbnsEnd = idbnsEnd; 356 } 357 358 /** Initial insertion code of the PDB sequence segment. 359 * 360 * @return insertBegin 361 * @see #setInsertBegin(char) 362 */ 363 364 public char getInsertBegin() { 365 return insertBegin; 366 } 367 368 /** Initial insertion code of the PDB sequence segment. 369 * 370 * @param insertBegin 371 * @see #getInsertBegin() 372 */ 373 374 public void setInsertBegin(char insertBegin) { 375 this.insertBegin = insertBegin; 376 } 377 378 /** Ending insertion code of the PDB sequence segment. 379 * 380 * @return insertEnd insertion code 381 * @see #setInsertEnd(char) 382 */ 383 public char getInsertEnd() { 384 return insertEnd; 385 } 386 387 /** Ending insertion code of the PDB sequence segment. 388 * 389 * @param insertEnd insertEnd 390 * @see #getInsertEnd() 391 * 392 */ 393 public void setInsertEnd(char insertEnd) { 394 this.insertEnd = insertEnd; 395 } 396 397 /** Initial sequence number of the PDB sequence segment. 398 * 399 * @return start seq. position 400 * @see #setSeqBegin 401 */ 402 public int getSeqBegin() { 403 return seqbegin; 404 } 405 406 /** Initial sequence number of the PDB sequence segment. 407 * 408 * @param seqbegin start seq. position 409 * @see #getSeqBegin() 410 */ 411 public void setSeqBegin(int seqbegin) { 412 this.seqbegin = seqbegin; 413 } 414 415 /**Ending sequence number of the PDB sequence segment. 416 * 417 * @return sequence end position 418 * @see #getSeqEnd() 419 */ 420 public int getSeqEnd() { 421 return seqEnd; 422 } 423 424 /**Ending sequence number of the PDB sequence segment. 425 * 426 * @param seqEnd sequence end position 427 * @see #setSeqEnd(int) 428 * 429 */ 430 public void setSeqEnd(int seqEnd) { 431 this.seqEnd = seqEnd; 432 } 433 434}