bytedance / bytedance/Protenix

JSON template negative indices silently map to trailing residues

Open Beginner friendly
#342 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.1k
Forks
310
PR merge metrics
No merged PRs in 30d

Description

## Description

Embedded JSON templates accept parallel `queryIndices` and `templateIndices` arrays. The parser checks only the upper bounds before indexing NumPy arrays and Python sequences. As a result, Python's negative-index semantics turn malformed mappings into valid-looking but incorrect template features:

- `queryIndices: [-1]` writes the mapped residue to the final query position.
- `templateIndices: [-2]` reads the second-to-last template residue.

`templateIndices: [-1]` is different: the parser explicitly treats it as the supported gap sentinel and should remain valid.

## Reproduction

Tested on current `main` at `4c355be4553512f72453ecbfb65e69f4c35d1413` with the repository's `examples/example_with_json_template/h_seq.json` mmCIF payload.

For a query of length 122 and a one-pair mapping:

```python
item["queryIndices"] = [-1]
item["templateIndices"] = [0]
result = featurizer.parse_json_templates([item], query_sequence)
```

Actual result:

```text
errors=[]
populated_query_indices=[121]
hit.indices_hit[-1]=0
```

Changing the pair to `queryIndices: [0]`, `templateIndices: [-2]` similarly returns no errors, populates query position 0 from the second-to-last template residue, and stores `-2` in `hit.indices_hit[0]`.

For comparison, the intended gap mapping `queryIndices: [0]`, `templateIndices: [-1]` leaves the query position unpopulated, and the normal mapping `0 -> 0` populates it with template residue 0.

## Expected behavior

A JSON template containing a negative query index or a template index below the `-1` gap sentinel should be rejected through `TemplateSearchResult.errors` instead of silently producing a corrupted mapping. `templateIndices == -1` should continue to represent a gap.

## Suggested fix

Validate the missing lower bounds before building or applying the mapping:

- every query index must be at least 0;
- every template index must be at least -1.

Keep the existing upper-bound behavior and add focused tests for query `-1`, template `-2`, the legal template `-1` gap, and a normal mapping.

Contributor guide

Open the contributing guide

Research direction

Start at the parse_json_templates entry point and trace where queryIndices and templateIndices are bounds-checked and applied. Add focused coverage for query -1, template -2, legal template -1 gaps, and normal 0-to-0 mappings; done means invalid lower bounds populate TemplateSearchResult.errors without changing valid behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
bioinformatics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.