Skip to content

Load Obos first and fallback#474

Merged
SmartMonkey-git merged 14 commits into
mainfrom
rr/better-ontology-factory
Apr 14, 2026
Merged

Load Obos first and fallback#474
SmartMonkey-git merged 14 commits into
mainfrom
rr/better-ontology-factory

Conversation

@SmartMonkey-git

Copy link
Copy Markdown
Collaborator

No description provided.

@psnairne psnairne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only one important comment which is the question about the repeated logic

Comment thread phenoxtract/src/config/resource_config_factory.rs Outdated
Comment thread phenoxtract/src/ontology/ontology_factory.rs Outdated
Comment thread phenoxtract/src/ontology/ontology_factory.rs Outdated
Comment thread phenoxtract/src/ontology/ontology_factory.rs Outdated
Comment thread phenoxtract/src/ontology/ontology_factory.rs Outdated
Comment thread phenoxtract/src/ontology/ontology_factory.rs
Comment on lines 203 to +223
if let Some(onto) = self.get_cached_ontology(ontology_ref) {
return Ok(onto.ontology.clone());
}

for r in self.registry.list()? {
if r.version().to_string() == ontology_ref.version()
&& r.ontology_id().to_lowercase() == ontology_ref.prefix_id().to_lowercase()
{
return match r.file_type() {
FileType::Json => self.build_ontolius_ontology(ontology_ref),
FileType::Obo => self.build_obodoc_ontology(ontology_ref),
FileType::Owl => Err(FactoryError::CantBuild {
reason: format!(
"OWL files are not supported. Got a configuration for {}",
r
),
}),
};
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but this seems to be doing the same thing twice? Was there a problem with the logic in the get_cached_ontology function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Its not doing the same thing twice. get_cached_ontology looks into memory, while this logic looks on the hard drive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah I see. So I suppose adding this logic allows for the hypothetical situation where

ontology_metadata.json_file_location.is_some()
           || ontology_metadata.obo_file_location.is_some()

becomes False, but we still have the file on our system. I suppose it's more robust that's true!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, its here to not download unloadable obos over and over again.

ontology_ref.as_version(),
FileType::Json,
);
self.registry.unregister(reg_key)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this necessary?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So, that you do not keep unloadable ontologies in your registry.

if ontology_metadata.json_file_location.is_some()
|| ontology_metadata.obo_file_location.is_some()
{
if let Ok(ontology) = self.build_obodoc_ontology(ontology_ref) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The only issue with this logic is that if obodoc build is failing for some other reason, e.g. an error with our build Ontology from obodoc code, we won't know, and will just get a JSON instead.

I think I slightly prefer the previous logic - if there is an obo file in the metadata then we should be able to build the ontology from the obo file. But also I don't mind too much

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The only issue with this logic is that if obodoc build is failing for some other reason, e.g. an error with our build Ontology from obodoc code, we won't know, and will just get a JSON instead.

But that was the whole point of this PR.
If we can not build an obo ontology, we try to build it from a json. Why is that a problem?

I think I slightly prefer the previous logic - if there is an obo file in the metadata then we should be able to build the ontology from the obo file. But also I don't mind too much

And why do you prefer that logic?
It makes less ontologies accessible and fully relies on FastObos ability to build an ontology, if Json and obo are available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Advantage of your way = more robust
Advantage of previous way = errors with OBO or JSON parsing are made clear.

Anyway, I think it's fine both ways!

@psnairne psnairne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@SmartMonkey-git
SmartMonkey-git merged commit bc06eee into main Apr 14, 2026
4 checks passed
@SmartMonkey-git
SmartMonkey-git deleted the rr/better-ontology-factory branch April 14, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants