001    package org.jaga.individualRepresentation.proteinLocation;
002    
003    import org.jaga.definitions.GAParameterSet;
004    import org.jaga.definitions.RandomGenerator;
005    import java.util.HashMap;
006    
007    /**
008     * TODO: Complete these comments.
009     *
010     * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
011     *
012     * <p><u>Company:</u> University College London and JAGA.Org
013     *    (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
014     * </p>
015     *
016     * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
017     *    This program is free software; you can redistribute it and/or modify
018     *    it under the terms of the GNU General Public License as published by
019     *    the Free Software Foundation, ONLY if you include a note of the original
020     *    author(s) in any redistributed/modified copy.<br/>
021     *    This program is distributed in the hope that it will be useful,
022     *    but WITHOUT ANY WARRANTY; without even the implied warranty of
023     *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
024     *    GNU General Public License for more details.<br/>
025     *    You should have received a copy of the GNU General Public License
026     *    along with this program; if not, write to the Free Software
027     *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
028     *    or see http://www.gnu.org/licenses/gpl.html</p>
029     *
030     * @author Greg Paperin (greg@jaga.org)
031     *
032     * @version JAGA public release 1.0 beta
033     */
034    
035    public class AminoAcidFactory {
036    
037            private static HashMap aminoAcids = new HashMap();
038            private static AminoAcid [] allAminoAcids = null;
039            private static AminoAcid [] smallAminoAcids = null;
040            private static AminoAcid [] hydrophobicAminoAcids = null;
041            private static AminoAcid [] polarAminoAcids = null;
042            private static AminoAcid [] positiveAminoAcids = null;
043            private static AminoAcid [] negativeAminoAcids = null;
044            private static AminoAcid [] tinyAminoAcids = null;
045            private static AminoAcid [] aliphaticAminoAcids = null;
046            private static AminoAcid [] aromaticAminoAcids = null;
047    
048            static {
049    
050                    AminoAcid I = new AminoAcid("Isoleukine", "I",
051                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Aliphatic);
052    
053                    AminoAcid L = new AminoAcid("Leucine", "L",
054                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Aliphatic);
055    
056                    AminoAcid M = new AminoAcid("Methionine", "M",
057                                               AminoAcidProperty.Hydrophobic);
058    
059                    AminoAcid F = new AminoAcid("Phelylalanine", "F",
060                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Aromatic);
061    
062                    AminoAcid A = new AminoAcid("Alanine", "A",
063                                                    AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Tiny);
064    
065                    AminoAcid C = new AminoAcid("Cysteine", "C",
066                                                    AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small);
067    
068                    AminoAcid V = new AminoAcid("Valine", "V",
069                                                    AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Aliphatic);
070    
071                    AminoAcid T = new AminoAcid("Threonine", "T",
072                                                    AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Polar);
073    
074                    AminoAcid W = new AminoAcid("Tryptophan", "W",
075                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Aromatic);
076    
077                    AminoAcid Y = new AminoAcid("Tyrosine", "Y",
078                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Aromatic);
079    
080                    AminoAcid H = new AminoAcid("Histidine", "H",
081                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Polar | AminoAcidProperty.Positive | AminoAcidProperty.Aromatic);
082    
083                    AminoAcid K = new AminoAcid("Lysine", "K",
084                                               AminoAcidProperty.Hydrophobic | AminoAcidProperty.Polar | AminoAcidProperty.Positive);
085    
086                    AminoAcid R = new AminoAcid("Arginine", "R",
087                                               AminoAcidProperty.Polar | AminoAcidProperty.Positive);
088    
089                    AminoAcid E = new AminoAcid("Glutamic Acid", "E",
090                                               AminoAcidProperty.Polar | AminoAcidProperty.Negative);
091    
092                    AminoAcid D = new AminoAcid("Aspatic Acid", "D",
093                                                    AminoAcidProperty.Small | AminoAcidProperty.Polar | AminoAcidProperty.Positive);
094    
095                    AminoAcid N = new AminoAcid("Asparagine", "N",
096                                                    AminoAcidProperty.Small | AminoAcidProperty.Polar);
097    
098                    AminoAcid G = new AminoAcid("Glycine", "G",
099                                                    AminoAcidProperty.Hydrophobic | AminoAcidProperty.Small | AminoAcidProperty.Tiny);
100    
101                    AminoAcid S = new AminoAcid("Serine", "S",
102                                                    AminoAcidProperty.Polar | AminoAcidProperty.Small | AminoAcidProperty.Tiny);
103    
104                    AminoAcid Q = new AminoAcid("Glutamine", "Q",
105                                               AminoAcidProperty.Polar);
106    
107                    AminoAcid P = new AminoAcid("Proline", "P",
108                                                    AminoAcidProperty.Small);
109    
110    
111                    aminoAcids.put("I", I);
112                    aminoAcids.put("L", L);
113                    aminoAcids.put("M", M);
114                    aminoAcids.put("F", F);
115                    aminoAcids.put("A", A);
116                    aminoAcids.put("C", C);
117                    aminoAcids.put("V", V);
118                    aminoAcids.put("T", T);
119                    aminoAcids.put("W", W);
120                    aminoAcids.put("Y", Y);
121                    aminoAcids.put("H", H);
122                    aminoAcids.put("K", K);
123                    aminoAcids.put("R", R);
124                    aminoAcids.put("E", E);
125                    aminoAcids.put("D", D);
126                    aminoAcids.put("N", N);
127                    aminoAcids.put("G", G);
128                    aminoAcids.put("S", S);
129                    aminoAcids.put("Q", Q);
130                    aminoAcids.put("P", P);
131    
132                    allAminoAcids = new AminoAcid [] {I, L, M, F, A, C, V, T, W, Y, H, K, R, E, D, N, G, S, Q, P};
133                    smallAminoAcids = new AminoAcid [] {P, N, D, T, V, C, G, A, S};
134                    hydrophobicAminoAcids = new AminoAcid [] {K, H, Y, W, F, M, L, V, I, C, T, A, G};
135                    polarAminoAcids = new AminoAcid [] {Y, W, H, R, K, T, D, E, S, N, Q};
136                    positiveAminoAcids = new AminoAcid [] {K, R, H};
137                    negativeAminoAcids = new AminoAcid [] {D, E};
138                    tinyAminoAcids = new AminoAcid [] {S, A, G};
139                    aliphaticAminoAcids = new AminoAcid [] {V, L, I};
140                    aromaticAminoAcids = new AminoAcid [] {F, Y, W, H};
141            }
142    
143            public static AminoAcid getResidueByCode(String code) {
144                    Object aa = aminoAcids.get(code);
145                    if (null == aa)
146                            throw new RuntimeException("There is no amino acid with the code '" + code + "'.");
147                    return (AminoAcid) aa;
148            }
149    
150            public static AminoAcid getRandomResidueByProperty(int property, GAParameterSet params) {
151                    switch(property) {
152                            case AminoAcidProperty.Small:
153                                    return getRandomAcid(smallAminoAcids, params.getRandomGenerator());
154                            case AminoAcidProperty.Hydrophobic:
155                                    return getRandomAcid(hydrophobicAminoAcids, params.getRandomGenerator());
156                            case AminoAcidProperty.Polar:
157                                    return getRandomAcid(polarAminoAcids, params.getRandomGenerator());
158                            case AminoAcidProperty.Positive:
159                                    return getRandomAcid(positiveAminoAcids, params.getRandomGenerator());
160                            case AminoAcidProperty.Negative:
161                                    return getRandomAcid(negativeAminoAcids, params.getRandomGenerator());
162                            case AminoAcidProperty.Tiny:
163                                    return getRandomAcid(tinyAminoAcids, params.getRandomGenerator());
164                            case AminoAcidProperty.Aliphatic:
165                                    return getRandomAcid(aliphaticAminoAcids, params.getRandomGenerator());
166                            case AminoAcidProperty.Aromatic:
167                                    return getRandomAcid(aromaticAminoAcids, params.getRandomGenerator());
168                            default:
169                                    throw new Error("Cannot have property code " + property);
170                    }
171            }
172    
173            public static AminoAcid getRandomResidue(GAParameterSet params) {
174                    return getRandomAcid(allAminoAcids, params.getRandomGenerator());
175            }
176    
177            private static AminoAcid getRandomAcid(AminoAcid [] list, RandomGenerator rnd) {
178                    int dice = rnd.nextInt(0, list.length);
179                    return list[dice];
180            }
181    
182            public AminoAcidFactory() {}
183    
184    }