001 package org.jaga.individualRepresentation.proteinLocation;
002
003 import org.jaga.definitions.GAParameterSet;
004 /**
005 * TODO: Complete these comments.
006 *
007 * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
008 *
009 * <p><u>Company:</u> University College London and JAGA.Org
010 * (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
011 * </p>
012 *
013 * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
014 * This program is free software; you can redistribute it and/or modify
015 * it under the terms of the GNU General Public License as published by
016 * the Free Software Foundation, ONLY if you include a note of the original
017 * author(s) in any redistributed/modified copy.<br/>
018 * This program is distributed in the hope that it will be useful,
019 * but WITHOUT ANY WARRANTY; without even the implied warranty of
020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021 * GNU General Public License for more details.<br/>
022 * You should have received a copy of the GNU General Public License
023 * along with this program; if not, write to the Free Software
024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
025 * or see http://www.gnu.org/licenses/gpl.html</p>
026 *
027 * @author Greg Paperin (greg@jaga.org)
028 *
029 * @version JAGA public release 1.0 beta
030 */
031
032 public class AminoAcidPropertyFactory {
033
034 public static final AminoAcidProperty Small = new AminoAcidProperty(AminoAcidProperty.Small);
035 public static final AminoAcidProperty Hydrophobic = new AminoAcidProperty(AminoAcidProperty.Hydrophobic);
036 public static final AminoAcidProperty Polar = new AminoAcidProperty(AminoAcidProperty.Polar);
037 public static final AminoAcidProperty Positive = new AminoAcidProperty(AminoAcidProperty.Positive);
038 public static final AminoAcidProperty Negative = new AminoAcidProperty(AminoAcidProperty.Negative);
039 public static final AminoAcidProperty Tiny = new AminoAcidProperty(AminoAcidProperty.Tiny);
040 public static final AminoAcidProperty Aliphatic = new AminoAcidProperty(AminoAcidProperty.Aliphatic);
041 public static final AminoAcidProperty Aromatic = new AminoAcidProperty(AminoAcidProperty.Aromatic);
042
043 public static AminoAcidProperty getRandomProperty(GAParameterSet params) {
044 int dice = params.getRandomGenerator().nextInt(1, 9);
045 switch(dice) {
046 case 1: return getPropertyByCode(AminoAcidProperty.Small);
047 case 2: return getPropertyByCode(AminoAcidProperty.Hydrophobic);
048 case 3: return getPropertyByCode(AminoAcidProperty.Polar);
049 case 4: return getPropertyByCode(AminoAcidProperty.Positive);
050 case 5: return getPropertyByCode(AminoAcidProperty.Negative);
051 case 6: return getPropertyByCode(AminoAcidProperty.Tiny);
052 case 7: return getPropertyByCode(AminoAcidProperty.Aliphatic);
053 case 8: return getPropertyByCode(AminoAcidProperty.Aromatic);
054 default: throw new Error("Should never come here. Have fun debugging!");
055 }
056 }
057
058 public static AminoAcidProperty getPropertyByCode(int propertyCode) {
059 switch(propertyCode) {
060 case AminoAcidProperty.Small:
061 return Small;
062 case AminoAcidProperty.Hydrophobic:
063 return Hydrophobic;
064 case AminoAcidProperty.Polar:
065 return Polar;
066 case AminoAcidProperty.Positive:
067 return Positive;
068 case AminoAcidProperty.Negative:
069 return Negative;
070 case AminoAcidProperty.Tiny:
071 return Tiny;
072 case AminoAcidProperty.Aliphatic:
073 return Aliphatic;
074 case AminoAcidProperty.Aromatic:
075 return Aromatic;
076 default:
077 throw new IllegalArgumentException("Illegal property: " + propertyCode);
078 }
079 }
080
081 public static AminoAcidProperty getPropertyByName(String name) {
082 if (name.equalsIgnoreCase("Small"))
083 return Small;
084 if (name.equalsIgnoreCase("Hydrophobic"))
085 return Hydrophobic;
086 if (name.equalsIgnoreCase("Polar"))
087 return Polar;
088 if (name.equalsIgnoreCase("Positive"))
089 return Positive;
090 if (name.equalsIgnoreCase("Negative"))
091 return Negative;
092 if (name.equalsIgnoreCase("Tiny"))
093 return Tiny;
094 if (name.equalsIgnoreCase("Aliphatic"))
095 return Aliphatic;
096 if (name.equalsIgnoreCase("Aromatic"))
097 return Aromatic;
098
099 throw new IllegalArgumentException("Illegal property: " + name);
100 }
101
102 public AminoAcidPropertyFactory() {}
103
104 }