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 Oct 12, 2011
021 * Created by Andreas Prlic
022 *
023 * @since 3.0.2
024 */
025package org.biojava.nbio.structure.scop;
026
027import java.util.HashMap;
028import java.util.Map;
029
030/**
031 * SCOPe:
032 *
033 * The Structural Classification of Proteins (extended) at Berkeley Lab and UC Berkeley
034 * (<a href="http://scop.berkeley.edu/">http://scop.berkeley.edu/</a>).
035 *
036 * <p>This provides updates to the MRC SCOP hierarchical classification.
037 */
038public class BerkeleyScopInstallation extends ScopInstallation {
039
040
041        String defaultBerkeleyDownloadURL = "http://scop.berkeley.edu/downloads/parse/";
042        String defaultBerkeleyScopVersion=ScopFactory.LATEST_VERSION;
043
044        /**
045         * A map from SCOP version names which the Berkeley server offers as a
046         * download to an array of equivalent deprecated SCOP version names.
047         */
048        public static final Map<String,String[]> EQUIVALENT_VERSIONS = new HashMap<String,String[]>();
049
050        static {
051                EQUIVALENT_VERSIONS.put("2.01", new String[] {"1.75A"});
052                EQUIVALENT_VERSIONS.put("2.02", new String[] {"1.75B"});
053                EQUIVALENT_VERSIONS.put("2.03", new String[] {"1.75C"});
054        }
055
056
057        public BerkeleyScopInstallation() {
058                super();
059                setScopVersion(defaultBerkeleyScopVersion);
060                addMirror(new BerkeleyScopMirror(defaultBerkeleyDownloadURL));
061                addMirror(new ScopMirror());
062        }
063
064        private static class BerkeleyScopMirror extends ScopMirror {
065                private String rootURL;
066                public BerkeleyScopMirror(String url) {
067                        super(url);
068                        rootURL = url;
069                }
070
071                @Override
072                public String getClaURL(String scopVersion) {
073                        return rootURL+getFilename("cla",scopVersion);
074                }
075
076                @Override
077                public String getDesURL(String scopVersion) {
078                        return rootURL+getFilename("des",scopVersion);
079                }
080
081                @Override
082                public String getHieURL(String scopVersion) {
083                        return rootURL+getFilename("hie",scopVersion);
084                }
085
086                @Override
087                public String getComURL(String scopVersion) {
088                        return rootURL+getFilename("com",scopVersion);
089                }
090
091                private String getFilename(String fileType, String version) {
092                        // Convert to canonical version number
093                        for (Map.Entry<String, String[]> entry : EQUIVALENT_VERSIONS.entrySet()) {
094                                for (String vr : entry.getValue()) {
095                                        if (version.equals(vr)) {
096                                                version = entry.getKey();
097                                                break;
098                                        }
099                                }
100                        }
101                        String[] parts = version.split("\\.");
102                        // they changed the filename schemes!
103                        if (Integer.parseInt(parts[0]) == 1) {
104                                return "dir." + fileType + ".scop." + version + ".txt";
105                        } else {
106                                return "dir." + fileType + ".scope." + version + "-stable.txt";
107                        }
108                }
109
110                @Override
111                public String toString() {
112                        return "BerkeleyScopMirror[ \"" + rootURL + " ]";
113                }
114        }
115
116}