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