When I look at a peptide sequence, I see a string of characters with a very specific order.
That might sound like an obvious observation to a developer. But when you're handling research-compound records, the distinction between a sequence and a collection of amino-acid codes matters.
Two strings can contain exactly the same characters, in exactly the same quantities, and still represent different peptide sequences.
BPC-157 gives us a straightforward example. Its listed sequence is 15 characters long, which makes it useful for demonstrating a few basic data-validation rules.
I'll walk through how I'd handle that sequence in code, what I'd validate, and where I'd draw the line between a listing specification and evidence about a physical sample.
Start with the source record
Peppy Canada's BPC-157 listing includes a Molecular profile with four relevant fields:
| Field | Listing specification |
|---|---|
| Class | Pentadecapeptide — 15 amino acids |
| Sequence | GEPPPGKPADDAGLV |
| Origin | Partial sequence of a compound isolated from human gastric juice; the article supplied is synthetic |
| Supplied as | Lyophilised powder, sealed vial |
These are listing specifications. They tell us how the item is described in the source record.
For this exercise, I'm interested in the sequence field:
GEPPPGKPADDAGLV
It's short enough to inspect manually, but I wouldn't want manual inspection to be the validation method in a production data pipeline.
I'd rather define the rules and have the computer apply them consistently.
1. Treat amino-acid codes as a defined alphabet
A peptide sequence uses one-letter amino-acid codes. These are defined by the IUPAC-IUB convention, rather than being arbitrary letters assigned by a supplier.
For the 20 standard amino acids, the alphabet is:
ACDEFGHIKLMNPQRSTVWY
That gives us a useful first validation rule.
Every character in the sequence should belong to the permitted alphabet.
For example, G, E, and P are valid one-letter amino-acid codes. A digit, a space, or an unrelated punctuation mark isn't part of that alphabet.
This is a basic input-validation problem.
If I were building a database import process, I'd reject unexpected characters rather than quietly remove them. Removing characters could change the sequence without anyone noticing.
I'd also distinguish between checking the alphabet and confirming the identity of a compound.
An alphabet check establishes that a string uses permitted symbols. It doesn't establish that the string is the correct specification for a particular record.
Those are separate questions.
2. Check the expected length
The next rule is equally straightforward.
BPC-157 is classified in the listing as a pentadecapeptide, meaning 15 amino-acid residues.
The listed sequence should therefore contain exactly 15 characters.
For our example:
GEPPPGKPADDAGLV
Counting gives us 15.
In Python, that is simply:
len(sequence) == 15
This catches missing or additional characters.
It doesn't catch every possible error, though.
A sequence with 15 valid letters could still have the wrong letters or the wrong order.
That's why length validation should be treated as one check, not a complete identity check.
3. Order matters more than matching the contents
Here's the distinction I think is most important for developers working with sequence records.
Consider the listed sequence:
GEPPPGKPADDAGLV
Now reverse it:
VLGADDAPKGPPPEG
Both strings contain the same 15 characters. Both use valid amino-acid codes. Both have the same number of occurrences of every letter.
But they are not the same sequence.
In programming terms, these are ordered strings, not unordered collections.
If I sort both strings and compare the results, they'll match. If I count the characters in each string, those counts will match too.
Neither comparison is sufficient to establish sequence equality.
For that, I need an exact, position-by-position comparison.
This is similar to handling other ordered data. A database field containing a date, a version number, or a cryptographic input can't always be rearranged without changing its meaning.
The same principle applies here.
A peptide sequence is defined by which residue appears at each position, not just which residues are present.
4. A short Python validation example
Here's how I'd demonstrate the distinction in a small Python script.
from collections import Counter
ALPHABET = set("ACDEFGHIKLMNPQRSTVWY")
EXPECTED_LENGTH = 15
sequence = "GEPPPGKPADDAGLV"
reversed_sequence = sequence[::-1]
def valid_sequence(value):
return (
len(value) == EXPECTED_LENGTH
and all(letter in ALPHABET for letter in value)
)
print("Valid alphabet and length:", valid_sequence(sequence))
print("Sequence length:", len(sequence))
print("Exact ordered equality:",
sequence == reversed_sequence)
print("Composition equality:",
Counter(sequence) == Counter(reversed_sequence))
print("Reversed sequence:", reversed_sequence)
The important output is:
Valid alphabet and length: True
Sequence length: 15
Exact ordered equality: False
Composition equality: True
Reversed sequence: VLGADDAPKGPPPEG
This is the behaviour I want.
The reversed string passes the alphabet and length checks, and it has the same composition.
But it fails exact sequence equality.
In a real application, I'd keep those validation results separate. That way, a record can pass basic formatting checks without being incorrectly marked as an exact match.
5. Composition is useful, but it's derived data
Let's look at the composition of the listed BPC-157 sequence.
There are eight distinct one-letter codes occupying 15 positions.
| Code | Count |
|---|---|
| A | 2 |
| D | 2 |
| E | 1 |
| G | 3 |
| K | 1 |
| L | 1 |
| P | 4 |
| V | 1 |
| Total | 15 |
Proline, represented by P, appears four times.
That's useful information if you're building a searchable dataset, generating summaries, or checking whether two records share the same amino-acid composition.
But composition is a derived field.
I can calculate it from the sequence. I cannot reliably reconstruct the original sequence from those counts alone.
Multiple different ordered strings can produce the same composition.
That's a one-way relationship worth preserving in a data model.
I'd store the canonical sequence as the primary field and calculate composition when needed, or cache it as a derived attribute with a clear relationship to the source sequence.
I wouldn't use composition as a unique identifier.
6. Direction is part of the specification
There's another convention that developers need to account for.
Peptide sequences are conventionally written from the N-terminus to the C-terminus.
That means the first character represents the first residue at the N-terminal end, and the final character represents the last residue at the C-terminal end.
For the listed BPC-157 sequence:
Residue 1 is G.
Residue 15 is V.
This matters because reversing a string doesn't just change its presentation.
It changes which residue occupies each position.
If I were designing an API or schema for peptide records, I'd document the sequence direction explicitly rather than assume every downstream system interprets it correctly.
A field named sequence is helpful. A field specification stating that sequences are stored N-to-C is better.
It removes an avoidable ambiguity.
7. Keep provenance attached to the field
There's one final distinction I'd make before treating this as a reliable data record.
Where did the sequence come from?
In this example, the answer is Peppy Canada's BPC-157 listing.
So the provenance for the sequence field is:
source: listing
That is different from a laboratory measurement.
The listing provides a specification for the item. It doesn't establish that the contents of any particular vial or batch have been independently identified as that sequence.
No amount of string validation changes that.
A program can confirm that GEPPPGKPADDAGLV contains valid symbols, has 15 characters, and matches the stored listing sequence exactly.
It cannot establish the molecular identity of a physical sample from that information alone.
For a research-compound data system, I'd keep listing specifications, batch identifiers, and analytical evidence as separate record types or clearly distinguished fields.
I wouldn't allow a successful sequence-validation check to automatically become a claim about sample identity.
That separation makes the database easier to audit and prevents a software result from being interpreted as something it never established.
The takeaway
I like this example because the code is simple, but the data-modelling lesson is useful.
When handling peptide sequences, I'd apply a few straightforward principles: validate against the defined amino-acid alphabet, check the expected length, preserve the original N-to-C order, and use exact ordered comparison when checking sequence equality.
Composition counts can be useful derived metadata, but they aren't a substitute for the sequence itself.
And provenance needs to travel with the field. A sequence copied from a product listing remains a listing specification, even after every software validation check passes.
For developers building research-compound catalogues, import pipelines, or record-validation tools, those distinctions are worth getting right from the beginning.
For research use only. Not for human or veterinary use.
Top comments (0)