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