/
PeptideChargeCalculator.java
86 lines (80 loc) · 2.94 KB
/
PeptideChargeCalculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
import com.google.common.collect.*;
/**
* This is a utility class that calculates the charge of a peptide.
*/
public class PeptideChargeCalculator implements Immutable
{
/** Residues containing these strings in their descriptions are positively charged by one unit. */
public static Set<String> POSITIVELY_CHARGED = ImmutableSet.of("arginine", "lysine");
/** Residues containing these strings in their descriptions are negatively charged by one unit. */
public static Set<String> NEGATIVELY_CHARGED = ImmutableSet.of("aspartate", "glutamate");
/**
* Calculates the formal charge by looking at the names of the residues.
* @param descriptions the descriptions to analyze
* @return the overall charge
*/
public static int getCharge(List<String> descriptions)
{
int totalCharge = 0;
for (String description : descriptions)
{
for (String s : POSITIVELY_CHARGED)
{
if ( description.indexOf(s) > -1 )
{
totalCharge += 1;
break;
}
}
for (String s : NEGATIVELY_CHARGED)
{
if ( description.indexOf(s) > -1 )
{
totalCharge += -1;
break;
}
}
}
return totalCharge;
}
/**
* Calculates the formal charge of a peptide that is intended for rotamer reconstitution.
* @param peptide the template
* @param rotamers the rotamers that will be used on the template
* @return the formal charge
*/
public static int getCharge(Peptide peptide, List<Rotamer> rotamers)
{
List<String> descriptions = new ArrayList<>(peptide.sequence.size());
for (Residue r : peptide.sequence)
descriptions.add(r.description);
for (Rotamer r : rotamers)
descriptions.set(r.sequenceIndex, r.description);
return getCharge(descriptions);
}
/**
* Calculates the formal charge of a peptide.
* @param peptide the peptide to analyze
* @return the formal charge
*/
public static int getCharge(Peptide peptide)
{
return getCharge(peptide, -1);
}
/**
* Calculates the formal charge of a peptide, excluding some position.
*/
public static int getCharge(Peptide peptide, int ignoreIndex)
{
List<String> descriptions = new ArrayList<>(peptide.sequence.size());
for (int i=0; i < peptide.sequence.size(); i++)
{
if ( i == ignoreIndex )
continue;
Residue r = peptide.sequence.get(i);
descriptions.add(r.description);
}
return getCharge(descriptions);
}
}