SIB

Recipe 1.4 - Creating Protein

Problem

You want to make an instance of Protein.

Solution

There are mainly 2 ways to build a protein: Either build it from our Protein class or from Sequence biojava object thanks to our ProteinFactory class.

The first solution is simpler but if you need to create a protein from a Uniprot accession number or simply if you already use BioJava objects, the second one has the advantage of passing the torch with ease. Creating a Protein from an identifier and an amino-acid sequence string


Protein protein = new Protein("Prot1", "PROTEIN");

AminoAcid aa = protein.getSymbol(1);
int length = protein.size();

Assert.assertEquals(AminoAcid.R, aa);
Assert.assertEquals(7, length);

Creating a Protein from an identifier and an array of AminoAcids


Protein protein = new Protein("Prot1", AminoAcid.P, AminoAcid.R, AminoAcid.O,AminoAcid.T, AminoAcid.E,AminoAcid.I, AminoAcid.N);

Creating a Protein from a biojava Sequence


// an instance of ProteinSequence coming from biojava
ProteinSequence sequence = new ProteinSequence("PROTEIN");

// ProteinFactory provides a adapter static factory method to build a Protein from a Sequence<AminoAcidCompound>
Protein protein = ProteinFactory.newProtein(sequence);

Creating a Protein from a UniProt accession number


try {
    // this factory method delegates to BioJava objects
    Protein protein = ProteinFactory.newUniprotProtein("P26663");

    Assert.assertEquals(3010, protein.size());
} catch (Exception e) {

    throw new IllegalStateException("cannot access this number!");
}

Discussion

See also