<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Peppy Canada</title>
    <description>The latest articles on DEV Community by Peppy Canada (@peppycanada).</description>
    <link>https://dev.to/peppycanada</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4227207%2F9096778a-8b3c-4e92-a3b7-781e9904d9c7.jpg</url>
      <title>DEV Community: Peppy Canada</title>
      <link>https://dev.to/peppycanada</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peppycanada"/>
    <language>en</language>
    <item>
      <title>A peptide sequence is an ordered string: validating BPC-157's 15 letters in code</title>
      <dc:creator>Peppy Canada</dc:creator>
      <pubDate>Mon, 23 Nov 2026 15:25:09 +0000</pubDate>
      <link>https://dev.to/peppycanada/a-peptide-sequence-is-an-ordered-string-validating-bpc-157s-15-letters-in-code-34lg</link>
      <guid>https://dev.to/peppycanada/a-peptide-sequence-is-an-ordered-string-validating-bpc-157s-15-letters-in-code-34lg</guid>
      <description>&lt;p&gt;When I look at a peptide sequence, I see a string of characters with a very specific order.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Two strings can contain exactly the same characters, in exactly the same quantities, and still represent different peptide sequences.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the source record
&lt;/h2&gt;

&lt;p&gt;Peppy Canada's BPC-157 listing includes a Molecular profile with four relevant fields:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Listing specification&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Pentadecapeptide â€” 15 amino acids&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sequence&lt;/td&gt;
&lt;td&gt;GEPPPGKPADDAGLV&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Origin&lt;/td&gt;
&lt;td&gt;Partial sequence of a compound isolated from human gastric juice; the article supplied is synthetic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Supplied as&lt;/td&gt;
&lt;td&gt;Lyophilised powder, sealed vial&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are listing specifications. They tell us how the item is described in the source record.&lt;/p&gt;

&lt;p&gt;For this exercise, I'm interested in the sequence field:&lt;/p&gt;

&lt;p&gt;GEPPPGKPADDAGLV&lt;/p&gt;

&lt;p&gt;It's short enough to inspect manually, but I wouldn't want manual inspection to be the validation method in a production data pipeline.&lt;/p&gt;

&lt;p&gt;I'd rather define the rules and have the computer apply them consistently.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Treat amino-acid codes as a defined alphabet
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;For the 20 standard amino acids, the alphabet is:&lt;/p&gt;

&lt;p&gt;ACDEFGHIKLMNPQRSTVWY&lt;/p&gt;

&lt;p&gt;That gives us a useful first validation rule.&lt;/p&gt;

&lt;p&gt;Every character in the sequence should belong to the permitted alphabet.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;This is a basic input-validation problem.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I'd also distinguish between checking the alphabet and confirming the identity of a compound.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Those are separate questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Check the expected length
&lt;/h2&gt;

&lt;p&gt;The next rule is equally straightforward.&lt;/p&gt;

&lt;p&gt;BPC-157 is classified in the listing as a pentadecapeptide, meaning 15 amino-acid residues.&lt;/p&gt;

&lt;p&gt;The listed sequence should therefore contain exactly 15 characters.&lt;/p&gt;

&lt;p&gt;For our example:&lt;/p&gt;

&lt;p&gt;GEPPPGKPADDAGLV&lt;/p&gt;

&lt;p&gt;Counting gives us 15.&lt;/p&gt;

&lt;p&gt;In Python, that is simply:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;len(sequence) == 15&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This catches missing or additional characters.&lt;/p&gt;

&lt;p&gt;It doesn't catch every possible error, though.&lt;/p&gt;

&lt;p&gt;A sequence with 15 valid letters could still have the wrong letters or the wrong order.&lt;/p&gt;

&lt;p&gt;That's why length validation should be treated as one check, not a complete identity check.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Order matters more than matching the contents
&lt;/h2&gt;

&lt;p&gt;Here's the distinction I think is most important for developers working with sequence records.&lt;/p&gt;

&lt;p&gt;Consider the listed sequence:&lt;/p&gt;

&lt;p&gt;GEPPPGKPADDAGLV&lt;/p&gt;

&lt;p&gt;Now reverse it:&lt;/p&gt;

&lt;p&gt;VLGADDAPKGPPPEG&lt;/p&gt;

&lt;p&gt;Both strings contain the same 15 characters. Both use valid amino-acid codes. Both have the same number of occurrences of every letter.&lt;/p&gt;

&lt;p&gt;But they are not the same sequence.&lt;/p&gt;

&lt;p&gt;In programming terms, these are ordered strings, not unordered collections.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Neither comparison is sufficient to establish sequence equality.&lt;/p&gt;

&lt;p&gt;For that, I need an exact, position-by-position comparison.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The same principle applies here.&lt;/p&gt;

&lt;p&gt;A peptide sequence is defined by which residue appears at each position, not just which residues are present.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. A short Python validation example
&lt;/h2&gt;

&lt;p&gt;Here's how I'd demonstrate the distinction in a small Python script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;

&lt;span class="no"&gt;ALPHABET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ACDEFGHIKLMNPQRSTVWY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;EXPECTED_LENGTH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;

&lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GEPPPGKPADDAGLV"&lt;/span&gt;
&lt;span class="n"&gt;reversed_sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;valid_sequence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;EXPECTED_LENGTH&lt;/span&gt;
        &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;ALPHABET&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Valid alphabet and length:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;valid_sequence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Sequence length:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Exact ordered equality:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;reversed_sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Composition equality:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reversed_sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Reversed sequence:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reversed_sequence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Valid alphabet and length: True
Sequence length: 15
Exact ordered equality: False
Composition equality: True
Reversed sequence: VLGADDAPKGPPPEG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the behaviour I want.&lt;/p&gt;

&lt;p&gt;The reversed string passes the alphabet and length checks, and it has the same composition.&lt;/p&gt;

&lt;p&gt;But it fails exact sequence equality.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Composition is useful, but it's derived data
&lt;/h2&gt;

&lt;p&gt;Let's look at the composition of the listed BPC-157 sequence.&lt;/p&gt;

&lt;p&gt;There are eight distinct one-letter codes occupying 15 positions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;E&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;L&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;P&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;V&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Proline, represented by P, appears four times.&lt;/p&gt;

&lt;p&gt;That's useful information if you're building a searchable dataset, generating summaries, or checking whether two records share the same amino-acid composition.&lt;/p&gt;

&lt;p&gt;But composition is a derived field.&lt;/p&gt;

&lt;p&gt;I can calculate it from the sequence. I cannot reliably reconstruct the original sequence from those counts alone.&lt;/p&gt;

&lt;p&gt;Multiple different ordered strings can produce the same composition.&lt;/p&gt;

&lt;p&gt;That's a one-way relationship worth preserving in a data model.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I wouldn't use composition as a unique identifier.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Direction is part of the specification
&lt;/h2&gt;

&lt;p&gt;There's another convention that developers need to account for.&lt;/p&gt;

&lt;p&gt;Peptide sequences are conventionally written from the N-terminus to the C-terminus.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;For the listed BPC-157 sequence:&lt;/p&gt;

&lt;p&gt;Residue 1 is G.&lt;/p&gt;

&lt;p&gt;Residue 15 is V.&lt;/p&gt;

&lt;p&gt;This matters because reversing a string doesn't just change its presentation.&lt;/p&gt;

&lt;p&gt;It changes which residue occupies each position.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;A field named sequence is helpful. A field specification stating that sequences are stored N-to-C is better.&lt;/p&gt;

&lt;p&gt;It removes an avoidable ambiguity.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Keep provenance attached to the field
&lt;/h2&gt;

&lt;p&gt;There's one final distinction I'd make before treating this as a reliable data record.&lt;/p&gt;

&lt;p&gt;Where did the sequence come from?&lt;/p&gt;

&lt;p&gt;In this example, the answer is Peppy Canada's BPC-157 listing.&lt;/p&gt;

&lt;p&gt;So the provenance for the sequence field is:&lt;/p&gt;

&lt;p&gt;source: listing&lt;/p&gt;

&lt;p&gt;That is different from a laboratory measurement.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;No amount of string validation changes that.&lt;/p&gt;

&lt;p&gt;A program can confirm that GEPPPGKPADDAGLV contains valid symbols, has 15 characters, and matches the stored listing sequence exactly.&lt;/p&gt;

&lt;p&gt;It cannot establish the molecular identity of a physical sample from that information alone.&lt;/p&gt;

&lt;p&gt;For a research-compound data system, I'd keep listing specifications, batch identifiers, and analytical evidence as separate record types or clearly distinguished fields.&lt;/p&gt;

&lt;p&gt;I wouldn't allow a successful sequence-validation check to automatically become a claim about sample identity.&lt;/p&gt;

&lt;p&gt;That separation makes the database easier to audit and prevents a software result from being interpreted as something it never established.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;I like this example because the code is simple, but the data-modelling lesson is useful.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Composition counts can be useful derived metadata, but they aren't a substitute for the sequence itself.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;For developers building research-compound catalogues, import pipelines, or record-validation tools, those distinctions are worth getting right from the beginning.&lt;/p&gt;

&lt;p&gt;For research use only. Not for human or veterinary use.&lt;/p&gt;

</description>
      <category>python</category>
      <category>database</category>
      <category>datascience</category>
      <category>science</category>
    </item>
  </channel>
</rss>
