001    /**
002     * Copyright (C) 2010 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003     *
004     * This file is part of the Ensembl Java API demonstration project developed by the
005     * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006     * Veterinary Studies, University of Edinburgh.
007     *
008     * This is free software: you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (version 3) as published by
010     * the Free Software Foundation.
011     *
012     * This software is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015     * GNU General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * in this software distribution. If not, see <http://www.gnu.org/licenses/gpl-3.0.html/>.
019     */
020    package uk.ac.roslin.ensembl.model.compara;
021    
022    import java.io.ObjectStreamException;
023    import java.util.Collection;
024    import java.util.HashMap;
025    import uk.ac.roslin.ensembl.model.relationship.RelationshipType;
026    
027    public class HomologyType extends RelationshipType {
028    
029        private static HashMap<String, HomologyType> typeHash;
030    
031        /**
032         * A private constructor for making HomologyType objects. Should only be
033         * accessed from within the class - and then only the first time that
034         * the class is accessed when the list of acceptable types is constructed.
035         * @param typeName The name of this HomologyType object
036         */
037        private HomologyType(String typeName) {
038            super(typeName);
039        }
040        
041        /**
042         * two homologous objects derived by speciation
043         * Ensembl pipeline annotates as ortholog_one2one
044         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
045         */
046        public static final HomologyType ORTHOLOG_ONE2ONE = HomologyType.makeHomologyType("ortholog_one2one");
047        /**
048         * two homologous objects derived by speciation
049         * Ensembl pipeline annotates as ortholog_one2many
050         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
051         */
052        public static final HomologyType ORTHOLOG_ONE2MANY = HomologyType.makeHomologyType("ortholog_one2many");
053        /**
054         * two homologous objects derived by speciation
055         * Ensembl pipeline annotates as ortholog_many2many
056         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
057         */
058        public static final HomologyType ORTHOLOG_MANY2MANY = HomologyType.makeHomologyType("ortholog_many2many");
059        /**
060         * two homologous objects derived by speciation
061         * Ensembl pipeline annotates as apparent_ortholog_one2one
062         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
063         */
064        public static final HomologyType APPARENT_ORTHOLOG_ONE2ONE = HomologyType.makeHomologyType("apparent_ortholog_one2one");
065        /**
066         * two homologous objects derived by speciation
067         * Ensembl pipeline annotates as possible_ortholog
068         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
069         */
070        public static final HomologyType POSSIBLE_ORTHOLOG = HomologyType.makeHomologyType("possible_ortholog");
071    
072        /**
073         * two homologous objects derived by duplication
074         * Ensembl pipeline annotates as within_species_paralog
075         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
076         */
077        public static final HomologyType WITHIN_SPECIES_PARALOG = HomologyType.makeHomologyType("within_species_paralog");
078        /**
079         * two homologous objects derived by duplication
080         * Ensembl pipeline annotates as between_species_paralog
081         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
082         */
083        public static final HomologyType BETWEEN_SPECIES_PARALOG = HomologyType.makeHomologyType("between_species_paralog");
084        /**
085         * two homologous objects derived by duplication
086         * Ensembl pipeline annotates as other_paralog
087         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
088         */
089        public static final HomologyType OTHER_PARALOG = HomologyType.makeHomologyType("other_paralog");
090        /**
091         * two homologous objects derived by duplication
092         * Ensembl pipeline annotates as contiguous_gene_split
093         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
094         */
095        public static final HomologyType CONTIGUOUS_GENE_SPLIT = HomologyType.makeHomologyType("contiguous_gene_split");
096        /**
097         * two homologous objects derived by duplication
098         * Ensembl pipeline annotates as putative_gene_split
099         * see http://Nov2010.archive.ensembl.org/info/docs/compara/homology_method.html
100         */
101        public static final HomologyType PUTATIVE_GENE_SPLIT = HomologyType.makeHomologyType("putative_gene_split");
102    
103        /**
104         * Ensure Singleton class
105         */
106        private Object readResolve() throws ObjectStreamException {
107            return this;
108        }
109    
110        /**
111         * A private accessor to make a HomologyType object for a given string name.
112         * This implements a singleton pattern against each name.
113         * @param typeName The name of the HomologyType object to be generated
114         * @return HomologyType
115         */
116        private static final HomologyType makeHomologyType(String typeName) {
117    
118            if (HomologyType.typeHash == null) {
119                HomologyType.typeHash = new HashMap<String, HomologyType>();
120            }
121    
122            HomologyType ht = getHomologyTypeByName(typeName);
123    
124            if (ht == null) {
125                ht = new HomologyType(typeName);
126                HomologyType.typeHash.put(typeName, ht);
127            }
128            return ht;
129        }
130    
131        /**
132         * Checks to see if the supplied type is the name of a valid HomologyType
133         * and returns the corresponding HomologyType object if it is.
134         * @param typeName
135         * @return HomologyType - the HomologyType object corresponding to the name supplied
136         */
137        public static final HomologyType getHomologyTypeByName(String typeName) {
138            return typeHash.get(typeName);
139        }
140    
141        //remember to "override" static methods from the parent!
142        public static HomologyType getRelationshipType(String value) {
143            return typeHash.get(value);
144        }
145    
146        //remember to "override" static methods from the parent!
147        public static Collection<HomologyType> getAllTypes() {
148            return typeHash.values();
149        }
150    }