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 java.io.IOException;
024import java.io.Serializable;
025import java.util.HashSet;
026import java.util.List;
027import java.util.Set;
028
029import javax.xml.bind.annotation.XmlAccessType;
030import javax.xml.bind.annotation.XmlAccessorType;
031import javax.xml.bind.annotation.XmlRootElement;
032
033import org.biojava.nbio.structure.PdbId;
034import org.biojava.nbio.structure.ResidueRange;
035import org.biojava.nbio.structure.Structure;
036import org.biojava.nbio.structure.StructureException;
037import org.biojava.nbio.structure.StructureIdentifier;
038import org.biojava.nbio.structure.SubstructureIdentifier;
039import org.biojava.nbio.structure.align.util.AtomCache;
040
041
042/** Container for the information for a domain. Contains a line in the file
043 * dir.cla.scop.txt_1.75
044 *
045 * e.g d1dlwa_  1dlw    A:      a.1.1.1 14982   cl=46456,cf=46457,sf=46458,fa=46459,dm=46460,sp=46461,px=14982
046 *
047 * Instantiated using {@link ScopDatabase#getDomainByScopID(String)}
048 * @author Andreas Prlic
049 *
050 */
051@XmlRootElement(name = "ScopDomain", namespace ="http://source.rcsb.org")
052@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
053public class ScopDomain implements Serializable, Cloneable, StructureIdentifier {
054
055        private static final long serialVersionUID = 5890476209571654301L;
056
057        String scopId;
058        PdbId pdbId;
059        List<String> ranges;
060        String classificationId;
061        Integer sunid;
062
063        int classId;
064        int foldId;
065        int superfamilyId;
066        int familyId;
067        int domainId;
068        int speciesId;
069        int px;
070
071
072
073
074        @Override
075        public String toString() {
076                StringBuilder buf = new StringBuilder();
077                buf.append(scopId);
078                buf.append("\t") ;
079                buf.append(pdbId.getId().toLowerCase());
080                buf.append( "\t");
081
082                int rangePos = 0;
083                for (String range: ranges){
084                        rangePos++;
085
086                        buf.append(range);
087
088                        if ( ( ranges.size()> 1 ) && (rangePos < ranges.size()))
089                                buf.append(",");
090                }
091                buf.append("\t") ;
092                buf.append(classificationId);
093                buf.append("\t") ;
094                buf.append(String.valueOf(sunid));
095                buf.append("\t") ;
096
097                buf.append("cl=");
098                buf.append(String.valueOf(classId));
099                buf.append(",cf=");
100                buf.append(String.valueOf(foldId));
101                buf.append(",sf=");
102                buf.append(String.valueOf(superfamilyId));
103                buf.append(",fa=");
104                buf.append(String.valueOf(familyId));
105                buf.append(",dm=");
106                buf.append(String.valueOf(domainId));
107                buf.append(",sp=");
108                buf.append(String.valueOf(speciesId));
109                buf.append(",px=");
110                buf.append(String.valueOf(px));
111
112
113                return buf.toString();
114        }
115
116        public String getScopId() {
117                return scopId;
118        }
119        public void setScopId(String scopId) {
120                this.scopId = scopId;
121        }
122
123        /** 
124         * Gets the PDB identifier for this protein structure.
125         * Before BioJava 6.0.0, this method used to return a {@link String}.
126         *
127         * @return the {@link PdbId} PDB identifier
128         * @see #setPdbId(PdbId)
129         * @since 6.0.0
130         */
131        public PdbId getPdbId() {
132                return pdbId;
133        }
134
135        /**
136         * @param pdbId
137         * @deprecated use {@link #setPdbId(PdbId)}
138         */
139        @Deprecated
140        public void setPdbId(String pdbId) {
141                if(pdbId == null) this.pdbId = null;
142                this.pdbId = new PdbId(pdbId);
143        }
144
145        
146        /**
147         * @param pdbId
148         * @since 6.0.0
149         */
150        public void setPdbId(PdbId pdbId) {
151                this.pdbId = pdbId;
152        }
153
154        public List<String> getRanges() {
155                return ranges;
156        }
157        public void setRanges(List<String> ranges) {
158                this.ranges = ranges;
159        }
160        public String getClassificationId() {
161                return classificationId;
162        }
163        public void setClassificationId(String classificationId) {
164                this.classificationId = classificationId;
165        }
166        public Integer getSunid() {
167                return sunid;
168        }
169        public void setSunid(Integer sunid) {
170                this.sunid = sunid;
171        }
172        public int getClassId() {
173                return classId;
174        }
175        public void setClassId(int classId) {
176                this.classId = classId;
177        }
178        public int getFoldId() {
179                return foldId;
180        }
181        public void setFoldId(int foldId) {
182                this.foldId = foldId;
183        }
184        public int getSuperfamilyId() {
185                return superfamilyId;
186        }
187        public void setSuperfamilyId(int superfamilyId) {
188                this.superfamilyId = superfamilyId;
189        }
190        public int getFamilyId() {
191                return familyId;
192        }
193        public void setFamilyId(int familyId) {
194                this.familyId = familyId;
195        }
196        public int getDomainId() {
197                return domainId;
198        }
199        public void setDomainId(int domainId) {
200                this.domainId = domainId;
201        }
202        public int getSpeciesId() {
203                return speciesId;
204        }
205        public void setSpeciesId(int speciesId) {
206                this.speciesId = speciesId;
207        }
208        public int getPx() {
209                return px;
210        }
211        public void setPx(int px) {
212                this.px = px;
213        }
214
215        @Override
216        protected Object clone() throws CloneNotSupportedException {
217
218                super.clone();
219
220                ScopDomain n = new ScopDomain();
221                n.setClassId(getClassId());
222                n.setClassificationId(getClassificationId());
223                n.setDomainId(getDomainId());
224                n.setFamilyId(getFamilyId());
225                n.setFoldId(getFoldId());
226                n.setPdbId(getPdbId());
227                n.setPx(getPx());
228                n.setRanges(getRanges());
229                n.setScopId(getScopId());
230                n.setSpeciesId(getSpeciesId());
231                n.setSunid(getSunid());
232                n.setSuperfamilyId(getSuperfamilyId());
233
234
235                return n;
236
237
238        }
239
240        /**
241         * Returns the chains this domain is defined over; contains more than 1 element only if this domains is a multi-chain domain.
242         */
243        public Set<String> getChains() {
244                Set<String> chains = new HashSet<String>();
245                List<ResidueRange> rrs = ResidueRange.parseMultiple(getRanges());
246                for (ResidueRange rr : rrs) chains.add(rr.getChainName());
247                return chains;
248        }
249
250        @Override
251        public String getIdentifier() {
252                return getScopId();
253        }
254
255        public List<ResidueRange> getResidueRanges() {
256                return ResidueRange.parseMultiple(ranges);
257        }
258
259        @Override
260        public SubstructureIdentifier toCanonical() {
261                return new SubstructureIdentifier(getPdbId(), ResidueRange.parseMultiple(getRanges()));
262        }
263
264        @Override
265        public Structure reduce(Structure input) throws StructureException {
266                return toCanonical().reduce(input);
267        }
268
269        @Override
270        public Structure loadStructure(AtomCache cache) throws StructureException,
271        IOException {
272                return cache.getStructureForPdbId(pdbId);
273        }
274
275}