Recipe 1.5 - Creating Peptide


You want to create an instance of Peptide.


Peptides can be created from a String.

Peptide peptide = Peptide.parse("PEPTIDE");

Peptides with modifications can be created from a String. See Peptide.parse(String seq).

// Adding 2 modifications on Methionine 5 of peptide sequence PEPTMIDE
Peptide peptide = Peptide.parse("PEPTM(O, Phospho)IDE");

ModificationList mods = peptide.getModificationsAt(4, ModAttachment.sideChainSet);

Assert.assertEquals(2, mods.size());
Assert.assertEquals("O", mods.get(0).toString());
Assert.assertEquals("Phospho", mods.get(1).getLabel());

Peptides can be created from a list or array of AminoAcids.

// vararg AminoAcids
Peptide peptide = new Peptide(AminoAcid.P, AminoAcid.E, AminoAcid.P, AminoAcid.T, AminoAcid.I, AminoAcid.D, AminoAcid.E);

Peptides can also be created from the PeptideBuilder class.

PeptideBuilder peptideBuilder = new PeptideBuilder("PEPTIDE");

//To add a phosphorylation to the T at position 3
peptideBuilder.addModification(3, Modification.parseModification("HPO3"));

// the defined modification is added to the N-terminal of the first amino-acid
peptideBuilder.addModification(ModAttachment.N_TERM, Modification.parseModification("C2H3O"));

Peptide peptide =;

Peptide methods for handling Peptide sequence.

AminoAcid aa = peptide.getSymbol(1);
Assert.assertEquals(AminoAcid.E, aa);

int count = peptide.countAminoAcidsIn(EnumSet.of(AminoAcid.E, AminoAcid.I));
Assert.assertEquals(3, count);

int size = peptide.size();
Assert.assertEquals(7, size);

Peptide subPeptide = peptide.subSequence(1, 4);
Assert.assertEquals(Peptide.parse("EPT"), subPeptide);

int[] indices = peptide.getSymbolIndexes(AminoAcid.P);
Assert.assertArrayEquals(new int[]{0, 2}, indices);

Set<AminoAcid> ambiguousAas = Peptide.parse("PBPTIBB").getAmbiguousAminoAcids();

Peptide methods for getting Peptide mass and m/z.

AminoAcid aa = peptide.getSymbol(1);
Assert.assertEquals(AminoAcid.E, aa);

double mass = peptide.getMolecularMass();
Assert.assertEquals(799.359, mass, 0.001);

// calculate m/z at charge +2
double mz = peptide.calculateMz(2);
Assert.assertEquals(400.687, mz, 0.001);


See also