A catalog search can return the right name and still return the wrong record.

Consider a search for bpc157. The catalog stores the name as BPC-157. A straightforward string comparison fails, even though both strings refer to the same catalog entry. Normalising the input solves that problem.

But what happens when someone searches for thymosin beta-4 and the catalog contains TB-500? Should the search return that listing because the names are related?

I would argue that it should not.

There is an important distinction between correcting the representation of a name and changing what that name identifies. The former is a string-processing problem. The latter requires an explicit decision about the relationship between two named compounds.

In this article, I want to demonstrate a small catalog lookup system that handles both problems while introducing another requirement: the returned record must match the requested material specification.

Defining what a successful lookup means

Peppy Canada's research catalog contains six peptide listings alongside laboratory supplies. I'll use four peptide records to illustrate the lookup logic.

Rather than treating a catalog search as a conventional keyword search, I want to define a more restrictive contract.

A successful lookup requires:

  • A recognised compound name or explicitly accepted alias.
  • No conflicting name relationship.
  • A match against the requested material specification.
  • An identifiable source for each returned specification field.

If these conditions cannot be satisfied, the system returns no match.

That last requirement matters. A catalog search does not need to return something for every query. Returning a loosely related record may be useful in a discovery interface, but it is inappropriate when the function is intended to identify a specific catalog entry.

I would keep discovery and specification matching as separate operations.

Normalising names without changing their meaning

Name normalisation handles predictable differences in how people enter text.

For BPC-157, the following inputs can resolve to the same canonical catalog name:

Input Canonical name
bpc157 BPC-157
BPC 157 BPC-157
bpc-157 BPC-157
BPC157 BPC-157

These variations differ in capitalisation, spacing and hyphenation.

A normalisation function can remove those differences when constructing a lookup key. The canonical name remains unchanged in the stored record and returned result.

I would not extend this function to remove arbitrary words, chemical modifiers or other meaningful parts of a compound name. Nor would I use a similarity threshold to automatically decide that two different names identify the same compound.

The normalised key is an indexing convenience, not a chemical identifier.

An alias table needs negative relationships too

Alias tables typically document which names resolve to a particular record. I find it useful to also document which names must not resolve to that record.

For example:

Name or input Catalog record Relationship
BPC157 BPC-157 Accepted alias
BPC 157 BPC-157 Accepted alias
TB500 TB-500 Accepted alias
Thymosin beta-4 TB-500 Not a synonym
MOTS C MOTS-C Accepted alias
GHK CU GHK-Cu Accepted alias

TB-500 and thymosin beta-4 are related names in the research literature, but they are not interchangeable identifiers for the material described in the TB-500 listing.

Recording that distinction explicitly makes it harder for a future search implementation to introduce an incorrect mapping.

It also gives developers something concrete to test. If a later change introduces fuzzy matching or automated synonym expansion, the negative relationship can serve as a regression test.

Treating material specifications as structured fields

A name identifies the candidate record. The specification determines whether that candidate satisfies the request.

Here are four examples using stated listing information.

Catalog name Stated class Stated sequence
BPC-157 Pentadecapeptide — 15 amino acids GEPPPGKPADDAGLV
TB-500 Heptapeptide — 7 amino acids Ac-LKKTETQ (N-terminally acetylated)
MOTS-C Mitochondrial-derived peptide — 16 amino acids MRWQEMGYIFYPRKLR
GHK-Cu Copper(II) complex of a tripeptide Not included in this example

All four listings state the supplied form as Lyophilised powder, sealed vial.

I would store class, sequence and supplied form independently rather than combining them into a single searchable description.

This allows a caller to specify which fields must match. It also prevents a matching name from overriding a conflicting material specification.

For GHK-Cu, I have deliberately omitted the sequence field from this example dataset. A missing field should remain missing rather than being populated through inference.

Implementing a strict lookup in Python

The following example uses standard Python without external dependencies.

It separates name normalisation, relationship resolution, specification filtering and field-level provenance.

import re def normalise(name): return re.sub(r"[\s-]+", "", name.casefold()) def listing_field(value): return {"value": value, "source": "listing"} def record(compound_class, sequence=None): fields = { "class": listing_field(compound_class), "supplied_as": listing_field( "Lyophilised powder, sealed vial" ), } if sequence is not None: fields["sequence"] = listing_field(sequence) return fields catalog = { "BPC-157": record( "Pentadecapeptide — 15 amino acids", "GEPPPGKPADDAGLV", ), "TB-500": record( "Heptapeptide — 7 amino acids", "Ac-LKKTETQ (N-terminally acetylated)", ), "MOTS-C": record( "Mitochondrial-derived peptide — 16 amino acids", "MRWQEMGYIFYPRKLR", ), "GHK-Cu": record( "Copper(II) complex of a tripeptide", ), } # Positive and negative name relationships. aliases = [ ("BPC157", "BPC-157", "alias"), ("BPC 157", "BPC-157", "alias"), ("TB500", "TB-500", "alias"), ("thymosin beta-4", "TB-500", "not_synonym"), ("MOTS C", "MOTS-C", "alias"), ("GHK CU", "GHK-Cu", "alias"), ] name_index = {} def register(name, canonical): key = normalise(name) if key in name_index and name_index[key] != canonical: raise ValueError(f"Ambiguous name: {name}") name_index[key] = canonical for name in catalog: register(name, name) blocked_pairs = set() for alias, canonical, relationship in aliases: if relationship == "not_synonym": blocked_pairs.add((normalise(alias), canonical)) else: register(alias, canonical) def lookup(name, **required_spec): if not required_spec: return None key = normalise(name) canonical = name_index.get(key) if canonical is None: return None if (key, canonical) in blocked_pairs: return None fields = catalog[canonical] for field, expected in required_spec.items(): if field not in fields: return None if fields[field]["value"] != expected: return None return {"name": canonical, "fields": fields} def show(result): return result["name"] if result else "No match" print(show(lookup( "bpc157", supplied_as="Lyophilised powder, sealed vial", ))) # BPC-157 print(show(lookup( "BPC 157", class_="Pentadecapeptide — 15 amino acids", ))) # No match: class_ is not a defined field. print(show(lookup( "BPC 157", **{"class": "Pentadecapeptide — 15 amino acids"}, ))) # BPC-157 print(show(lookup( "TB500", **{"class": "Pentadecapeptide — 15 amino acids"}, ))) # No match: conflicting specification. print(show(lookup( "thymosin beta-4", supplied_as="Lyophilised powder, sealed vial", ))) # No match: no accepted name mapping. print(show(lookup( "GHK CU", **{"class": "Copper(II) complex of a tripeptide"}, ))) # GHK-Cu 

The implementation intentionally avoids approximate matching. It also rejects name-only requests because the lookup contract requires at least one specification filter.

The collision check prevents two different catalog records from silently acquiring the same normalised name key.

Understanding the different reasons for no match

The example returns None for unsuccessful lookups, but several distinct conditions can produce that result.

Condition Interpretation
Unrecognised name No accepted catalog identifier
Prohibited name relationship Records must not be treated as interchangeable
Conflicting specification Candidate record does not satisfy the request
Missing specification field Match cannot be established
Unknown filter Requested field is not defined
No specification supplied Lookup request is incomplete

In a production implementation, I would return structured reason codes instead of a single None value.

That would allow the interface to distinguish an unrecognised name from a specification conflict without suggesting that an alternative compound is an equivalent replacement.

It would also make unsuccessful searches more useful for debugging catalog data and identifying gaps in documentation.

Keeping provenance attached to individual fields

Every specification field in the example carries a source attribute with the value listing.

This is deliberately limited provenance. It identifies where the recorded information came from, not whether that information has been independently established.

Field-level provenance is useful because different attributes may eventually originate from different documents. Keeping their sources separate avoids presenting an entire record as though every field has the same evidentiary basis.

There is another boundary worth making explicit: a listing specification describes the catalog entry. It says nothing about the independently established identity, composition or condition of any particular vial.

A catalog record and a physical sample are different entities. I would not allow a successful catalog lookup to stand in for sample-level verification.

What I would test before expanding the catalog

Before adding more records, I would establish regression tests covering accepted spelling variations, normalisation collisions, prohibited synonym relationships, conflicting specifications and missing fields.

I would also test that every returned specification retains its source.

These tests protect the lookup contract as the catalog grows. Adding more aliases should improve name recognition without weakening the conditions required for a successful match.

The objective is not to maximise the number of successful searches. It is to make successful searches mean something specific.

When matching a research catalog record, a recognised name is the starting point. A matching stated specification is the next requirement. When either is missing, no match is a perfectly valid result.

For research use only. Not for human or veterinary use.