Repository navigation
feat: add recursive option to ga4gh_identify - #702
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
ga4gh_identify() only identifies the object it is given. Contained identifiable objects (e.g. an Allele's SequenceLocation, or the members of a CisPhasedBlock) only get their digest stored as a side effect of serializing the parent, and never get an `id`. Callers that need every object to carry its ID, such as AnyVar storing received VRS objects, had to set each nested ID by hand or round-trip the object through vrs_enref()/vrs_deref(). Add a `recursive` keyword argument (default False, so existing behavior is unchanged). When it is True, ga4gh_identify() first walks all fields of the object depth-first, through lists, custom root types and non-identifiable objects such as TraversalBlock, and identifies every GA4GH identifiable object it finds. The same `in_place` option and use_ga4gh_compute_identifier_when context apply to contained objects. References given as CURIEs are left as is. As documented, `as_version` still ignores other parameters. Update the Basic Models notebook to identify the Allele and its location with a single recursive call. The rendered output is unchanged. Closes ga4gh#596
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #596.
Problem
ga4gh_identify()only identifies the object it's given. Contained identifiable objects, such as an Allele'sSequenceLocationor the members of aCisPhasedBlock, get adigeststored as a side effect of serializing the parent, but never anid:Callers that need every object to carry its ID, such as AnyVar storing received VRS objects, had to set nested IDs by hand (as the translator and the Basic Models notebook do), or round-trip the object through
vrs_enref()/vrs_deref()and then clear and recompute the outer ID.Changes
ga4gh_identify()takes a newrecursivekeyword argument. It defaults toFalse, so existing behavior doesn't change. Withrecursive=True, every GA4GH identifiable object contained in the object is identified first, depth-first, before the object itself:Adjacencyinside aDerivativeMolecule'sTraversalBlockand its adjoinedSequenceLocations are identified. This works even when the object passed in isn't identifiable (e.g. aTraversalBlock). It still returnsNonein that case.in_placeoption anduse_ga4gh_compute_identifier_whencontext as the outer object. With"default", missing IDs are filled in and existing ones are kept."always"replaces them."never"sets no IDs.as_versionignores other parameters, includingrecursive.notebooks/getting_started/3_Basic_Models.ipynb(Step 4) now identifies the Allele and its location with a singlega4gh_identify(allele, recursive=True)call. The rendered output is unchanged. I checked this by running the notebook's code cells.This doesn't change
vrs_enref()/vrs_deref(). The unexpected Allele ID after the round trip described in the issue is a separate enref problem.Tests
New tests in
tests/test_vrs.py. They fail without the change.test_ga4gh_identify_recursive: the non-recursive default leaveslocation.idunset,recursive=Truesets it, and the test covers eachin_placeoption, theuse_ga4gh_compute_identifier_whencontext, andas_version.test_ga4gh_identify_recursive_cpb: aCisPhasedBlockwhose members are an already-identified Allele (kept as is), an unidentified Allele (it and its location get IDs) and a CURIE reference (left as is).test_ga4gh_identify_recursive_derivative_molecule: IDs are set through a non-identifiableTraversalBlock, both when it is the outer object and when it is inside aDerivativeMoleculewith aTerminus. Each ID is checked against one computed for a freshly built object.ruff check,ruff format --checkand the full test suite (pytest --vcr-record=none, 227 passed) pass locally, as do thega4gh.core.identifiersdoctests (pytest --doctest-modules src/ga4gh/core/identifiers.py).