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 */ 021package org.biojava.nbio.structure.scop; 022 023import javax.xml.bind.annotation.XmlAccessType; 024import javax.xml.bind.annotation.XmlAccessorType; 025import javax.xml.bind.annotation.XmlRootElement; 026import java.io.Serializable; 027 028/** Contains data from 029 * dir.des.scop.txt_1.75 030 * 031 * <p>e.g 032 * <pre> 033 * SunID Cat Class Name Description 034 * ----- --- ----- ---- ----------- 035 * 26154 px b.47.1.2 d1nrs.1 1nrs L:,H: 036 * 125030 px b.47.1.2 d1zgia1 1zgi A:1A-245 037 * </pre> 038 * 039 * @author Andreas Prlic 040 * 041 */ 042@XmlRootElement(name = "ScopDescription", namespace ="http://source.rcsb.org") 043@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) 044public class ScopDescription implements Serializable,Cloneable{ 045 046 private static final long serialVersionUID = 8579808155176839161L; 047 int sunID; 048 ScopCategory category; 049 String classificationId; 050 String name; 051 String description; 052 053 054 @Override 055 public String toString(){ 056 StringBuilder buf = new StringBuilder(); 057 058 buf.append(String.valueOf(sunID)); 059 buf.append("\t"); 060 buf.append(category); 061 buf.append("\t"); 062 buf.append(classificationId); 063 buf.append("\t"); 064 buf.append(name); 065 buf.append("\t"); 066 buf.append(description); 067 068 return buf.toString(); 069 } 070 071 072 public int getSunID() 073 { 074 return sunID; 075 } 076 public void setSunID(int sunID) 077 { 078 this.sunID = sunID; 079 } 080 public ScopCategory getCategory() 081 { 082 return category; 083 } 084 public void setCategory(ScopCategory category) 085 { 086 this.category = category; 087 } 088 public String getClassificationId() 089 { 090 return classificationId; 091 } 092 public void setClassificationId(String classificationId) 093 { 094 this.classificationId = classificationId; 095 } 096 public String getName() 097 { 098 return name; 099 } 100 public void setName(String name) 101 { 102 this.name = name; 103 } 104 public String getDescription() 105 { 106 return description; 107 } 108 public void setDescription(String description) 109 { 110 this.description = description; 111 } 112 113 // Methods to return parts of the classificationID 114 115 /** 116 * Return a portion of the classificationID corresponding to the specified 117 * category (class, fold, superfamily, family). 118 * 119 * <p>Example: for SCOP family "b.5.1.1", 120 * getClassificationId(ScopCategory.Superfamily) => "b.5.1" 121 */ 122 public String getClassificationId(ScopCategory category) { 123 if(classificationId == null || classificationId.isEmpty()) { 124 return null; 125 } 126 127 int numParts = 0; 128 switch(category) { 129 case Family: numParts++; 130 case Superfamily: numParts++; 131 case Fold: numParts++; 132 case Class: numParts++; break; 133 default: 134 throw new IllegalArgumentException("Only Class, Fold, Superfamily, and Family are supported."); 135 } 136 137 int endChar = -1; 138 for(int i = 0;i<numParts-1;i++) { 139 endChar = classificationId.indexOf('.', endChar+1); 140 if(endChar<0) { 141 // Not enough items in the classification for this category 142 return null; 143 } 144 } 145 endChar = classificationId.indexOf('.', endChar+1); 146 if(endChar<0) { 147 // category goes to the end 148 return classificationId; 149 } 150 else { 151 return classificationId.substring(0, endChar); 152 } 153 154 } 155 156 /** 157 * @return 158 * @see java.lang.Object#hashCode() 159 */ 160 @Override 161 public int hashCode() { 162 final int prime = 31; 163 int result = 1; 164 result = prime * result 165 + ((category == null) ? 0 : category.hashCode()); 166 result = prime 167 * result 168 + ((classificationId == null) ? 0 : classificationId.hashCode()); 169 result = prime * result + ((name == null) ? 0 : name.hashCode()); 170 result = prime * result + sunID; 171 return result; 172 } 173 174 175 /** 176 * Compares the fields sunID, category, classificationId, and name for equality 177 * 178 * @param obj 179 * @return 180 * @see java.lang.Object#equals(java.lang.Object) 181 */ 182 @Override 183 public boolean equals(Object obj) { 184 if (this == obj) { 185 return true; 186 } 187 if (obj == null) { 188 return false; 189 } 190 if (getClass() != obj.getClass()) { 191 return false; 192 } 193 ScopDescription other = (ScopDescription) obj; 194 if (category == null) { 195 if (other.category != null) { 196 return false; 197 } 198 } else if (!category.equals(other.category)) { 199 return false; 200 } 201 if (classificationId == null) { 202 if (other.classificationId != null) { 203 return false; 204 } 205 } else if (!classificationId.equals(other.classificationId)) { 206 return false; 207 } 208 if (name == null) { 209 if (other.name != null) { 210 return false; 211 } 212 } else if (!name.equals(other.name)) { 213 return false; 214 } 215 return sunID == other.sunID; 216 } 217 218 219 @Override 220 protected Object clone() throws CloneNotSupportedException { 221 super.clone(); 222 ScopDescription n = new ScopDescription(); 223 224 n.setCategory(getCategory()); 225 n.setClassificationId(getClassificationId()); 226 n.setDescription(getDescription()); 227 n.setName(getName()); 228 n.setSunID(getSunID()); 229 return n; 230 } 231 232 233 234}