feat: add required_features() and missing-data validation#212
Open
marcbal77 wants to merge 6 commits into
Open
feat: add required_features() and missing-data validation#212marcbal77 wants to merge 6 commits into
marcbal77 wants to merge 6 commits into
Conversation
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.
Summary
Adds a public, stable
required_features()method to every model plus a generic input-validation step so clocks raise a clear, actionable error when aGeoDatalacks the markers or metadata they need. This is the consumer side of the clinical-clock work, split out of #203 per review.API (stable at 1.0)
New
biolearn.featuresmodule:RequiredFeatures(layer, features, metadata): a frozen dataclass that is also aMapping, so it behaves as the documented{"layer", "features", "metadata"}dict and as an object with.layer/.features/.metadata. All three keys are always present.MissingFeaturesError(ValueError): raised on missing inputs. SubclassesValueError, so existingexcept ValueErrorhandlers keep working while callers can catch this specific case.validate_required_features(model, geo_data): the single validator.Every model gains
required_features():Validation scope
Hard-fail validation is wired only where a missing feature corrupts the result:
LinearMethylationModel(the exact linear combination, which previously carried its own private check). Clocks that tolerate partial inputs by design keep their current behavior and exposerequired_features()for introspection only:PCLinearTransformationModel(intersect and center-fill),LinearTranscriptomicModel(inner join),MiAge,EpiTOC2,AltumAge,Deconvolution,GPAge, and the proteomic clock.GrimageModelandHurdleAPIModelkeep their existing bespoke checks.The validator encodes the one axis asymmetry between layers in a single place (
_LAYER_FRAME):dnam/rna/proteinare features-as-rows (features in.index);clinicalis samples-as-rows (biomarkers in.columns), matching metadata.Tests
New
test_features.py:RequiredFeaturesdict and object behavior; all three keys always present.ValueError.EpiTOC2) still runs when a required CpG is missing.RequiredFeatures, including forwarding throughImputationDecorator.Full suite: 221 passed, 5 skipped.