Skip to content

Deduplicate template hits by sequence - #348

Open
etowahadams wants to merge 7 commits into
mainfrom
etowahadams/template_dedup
Open

Deduplicate template hits by sequence #348
etowahadams wants to merge 7 commits into
mainfrom
etowahadams/template_dedup

Conversation

@etowahadams

Copy link
Copy Markdown
Contributor

During inference, we allow for templates to have the same sequence. This is different from the behavior in AF3, where template hits with the same sequence are filtered out, such that the templates all have different sequences. This PR implements those changes.

@jandom jandom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, thank you @etowahadams – there are some minor linting problems

Comment on lines +2087 to +2101
# A2. Deduplicate by ungapped hit sequence, keeping the first
# (highest-ranked) occurrence. Without this, multiple hits that cover
# the same query region with identical residues (e.g. several crystal
# forms of the same complex) each consume a separate template slot.
if self.deduplicate_sequences:
if template.seq in seen_sequences:
if self.create_logs:
worker_logger.info(
f"{template.entry_id} {template.chain_id} is a"
" sequence duplicate of an already-accepted"
" template."
)
continue
seen_sequences.add(template.seq)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major: let's pull this out into a testable unit of code (a function) and putting under test

max_release_date: datetime | None = None
min_release_date_diff: int | None = None
max_templates: int = 20
deduplicate_sequences: bool = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: boolean flags are typically a code smell, we should probably wrap this in a configuration object – but this is out of scope for this PR

@jandom jandom self-assigned this Aug 5, 2026
Comment on lines +977 to +980
"M8Parser leaves TemplateData.seq unset, so the dedup check in "
"step A2 compares None while step H records the sequence "
"recovered by the step E realignment. The check never matches and "
"deduplicate_sequences is a no-op on the ColabFold path."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etowahadams this potentially is another bug

@jandom jandom added the safe-to-test Internal only label used to indicate PRs that are ready for automated CI testing. label Aug 5, 2026
@jandom
jandom self-requested a review August 8, 2026 18:18

@jandom jandom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After my changes i'm obviously happy with this :D

@etowahadams would be great if you could take another look?

Comment on lines +2363 to +2371
if self.deduplicate_sequences:
if template.seq in seen_sequences:
if self.create_logs:
worker_logger.info(
f"{template.entry_id} {template.chain_id} is a"
" sequence duplicate of an already-accepted template."
)
continue
seen_sequences.add(template.seq)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is moved significantly more down than it was: depending on the input (a3m, has sequence; m8 no sequence, needs to get seq from cif), the sequence is not available until this step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Internal only label used to indicate PRs that are ready for automated CI testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants