|
| 1 | +package org.biojava.nbio.aaproperties; |
| 2 | + |
| 3 | +import java.util.Set; |
| 4 | +import java.util.stream.Collectors; |
| 5 | +import java.util.stream.Stream; |
| 6 | + |
| 7 | +/** |
| 8 | + * This class provides the protein properties at the level of individual amino acids. |
| 9 | + * |
| 10 | + * @author Yana Valasatava |
| 11 | + */ |
| 12 | +public class AminoAcidProperties { |
| 13 | + |
| 14 | + private static final Set<String> negChargedAAs = Stream.of("D", "E", "K", "R", "H").collect(Collectors.toSet()); |
| 15 | + private static final Set<String> posChargedAAs = Stream.of("D", "E", "K", "R", "H").collect(Collectors.toSet()); |
| 16 | + private static final Set<String> polarAAs = Stream.of("D", "E", "K", "R", "H", "N", "Q", "S", "T", "Y") |
| 17 | + .collect(Collectors.toSet()); |
| 18 | + |
| 19 | + /** |
| 20 | + * At pH=7, two are negative charged: aspartic acid (Asp, D) and glutamic acid (Glu, E) (acidic side chains), |
| 21 | + * and three are positive charged: lysine (Lys, K), arginine (Arg, R) and histidine (His, H) (basic side chains). |
| 22 | + * |
| 23 | + * @param aa The one-letter amino acid code |
| 24 | + * |
| 25 | + * @return true if amino acid is charged |
| 26 | + */ |
| 27 | + public static final boolean isCharged(char aa) { |
| 28 | + if (negChargedAAs.contains(aa)) { |
| 29 | + return true; |
| 30 | + } |
| 31 | + else if (posChargedAAs.contains(aa)) { |
| 32 | + return true; |
| 33 | + } |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns the charge of amino acid. At pH=7, two are negative charged: aspartic acid (Asp, D) and glutamic acid (Glu, E) (acidic side chains), |
| 39 | + * and three are positive charged: lysine (Lys, K), arginine (Arg, R) and histidine (His, H) (basic side chains). |
| 40 | + * |
| 41 | + * @param aa The one-letter amino acid code |
| 42 | + * |
| 43 | + * @return the charge of amino acid (1 if positively charged, -1 if negatively charged, 0 if not charged) |
| 44 | + */ |
| 45 | + public static final int getChargeOfAminoAcid(char aa) { |
| 46 | + if (negChargedAAs.contains(aa)) { |
| 47 | + return -1; |
| 48 | + } |
| 49 | + else if (posChargedAAs.contains(aa)) { |
| 50 | + return 1; |
| 51 | + } |
| 52 | + return 0; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the array of charges of each amino acid in a protein. At pH=7, two are negative charged: aspartic acid (Asp, D) and glutamic acid (Glu, E) (acidic side chains), |
| 57 | + * and three are positive charged: lysine (Lys, K), arginine (Arg, R) and histidine (His, H) (basic side chains). |
| 58 | + * |
| 59 | + * @param aa The one-letter amino acid code |
| 60 | + * |
| 61 | + * @return the array of charges of amino acids in the protein (1 if amino acid is positively charged, |
| 62 | + * -1 if negatively charged, 0 if not charged) |
| 63 | + */ |
| 64 | + public static final int[] getChargesOfAminoAcidsInProtein(String protein) { |
| 65 | + |
| 66 | + int[] charges = new int[protein.length()]; |
| 67 | + for ( int i=0; i < protein.length(); i++ ) { |
| 68 | + char aa = protein.toCharArray()[i]; |
| 69 | + charges[i] = getChargeOfAminoAcid(aa); |
| 70 | + } |
| 71 | + return charges; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * There are 10 polar amino acids: D, E, H, K, R, N, Q, S, T, Y, that are polar. |
| 76 | + * |
| 77 | + * @param aa The one-letter amino acid code |
| 78 | + * |
| 79 | + * @return true if amino acid is polar |
| 80 | + */ |
| 81 | + public static final boolean isPolar(char aa) { |
| 82 | + if (polarAAs.contains(aa)) { |
| 83 | + return true; |
| 84 | + } |
| 85 | + return false; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * There are 10 polar amino acids: D, E, H, K, R, N, Q, S, T, Y, that are polar. |
| 90 | + * |
| 91 | + * @param aa The one-letter amino acid code |
| 92 | + * |
| 93 | + * @return the polarity of amino acid (1 if polar, 0 if not polar) |
| 94 | + */ |
| 95 | + public static final int getPolarityOfAminoAcid(char aa) { |
| 96 | + if (polarAAs.contains(aa)) { |
| 97 | + return 1; |
| 98 | + } |
| 99 | + return 0; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Returns the array of polarity of each amino acid in a protein. |
| 104 | + * |
| 105 | + * @param aa The one-letter amino acid code |
| 106 | + * |
| 107 | + * @return the array of polarity of amino acids in the protein (1 if amino acid is polar, 0 if not) |
| 108 | + */ |
| 109 | + public static final int[] getPolarityOfAminoAcidsInProtein(String protein) { |
| 110 | + |
| 111 | + int[] polarity = new int[protein.length()]; |
| 112 | + for ( int i=0; i < protein.length(); i++ ) { |
| 113 | + char aa = protein.toCharArray()[i]; |
| 114 | + polarity[i] = getPolarityOfAminoAcid(aa); |
| 115 | + } |
| 116 | + return polarity; |
| 117 | + } |
| 118 | +} |
0 commit comments