-
Notifications
You must be signed in to change notification settings - Fork 5
Make Subject required by default in NWBFile::initialize() #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
20
commits into
main
Choose a base branch
from
copilot/make-subject-required-by-default
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
689d747
Initial plan
Copilot 54fd124
Apply remaining changes
Copilot b5575c7
Make Subject required by default in NWBFile::initialize()
Copilot b4bd01e
Added Subject type
oruebel ac90401
Merge branch 'copilot/make-subject-required-by-default' of https://gi…
oruebel d5a741e
Update unit tests
oruebel a526662
Update Changelog and fix docstring
oruebel b732aea
Add missing testSubject.cpp file
oruebel dabddc7
Fix nwb-inspector validation errors
oruebel cbd9a1f
Fix validation tests
oruebel 10de7dd
Fix nwb-inspector validation errors
oruebel bcb223e
Fix nwb-inspector validation errors
oruebel d3f1893
Fix subject metadata nwb-inspector test
oruebel 49f9ea6
Potential fix for pull request finding
oruebel b016125
Potential fix for pull request finding
oruebel 7d16947
Potential fix for pull request finding
oruebel 7bb903e
Address review comment
oruebel e6427bd
Avoid overwriting exiting subject
oruebel 5e39cd2
Prevent invalid Subject data write
oruebel 76be639
Merge branch 'main' into copilot/make-subject-required-by-default
oruebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| #include "nwb/file/Subject.hpp" | ||
|
|
||
| #include "Utils.hpp" | ||
| #include "nwb/NWBFile.hpp" | ||
|
|
||
| using namespace AQNWB::NWB; | ||
| using namespace AQNWB::IO; | ||
|
|
||
| // Initialize the static registered_ member to trigger registration | ||
| REGISTER_SUBCLASS_IMPL(Subject) | ||
|
|
||
| Subject::Subject(std::shared_ptr<IO::BaseIO> io) | ||
| : NWBContainer(mergePaths(NWBFile::GENERAL_PATH, "subject"), io) | ||
| { | ||
| } | ||
|
|
||
| // Constructor | ||
| Subject::Subject(const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io) | ||
| : NWBContainer(mergePaths(NWBFile::GENERAL_PATH, "subject"), io) | ||
| { | ||
| if (path != mergePaths(NWBFile::GENERAL_PATH, "subject")) { | ||
| std::cerr << "WARNING: Subject object path must be /general/subject. " | ||
| "Ignoring provided path." | ||
| << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize the object | ||
| Status Subject::initialize(const SubjectSpec& subjectSpec) | ||
| { | ||
| // Get the IO object` | ||
| auto ioPtr = getIO(); | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| if (!ioPtr) { | ||
| std::cerr << "Subject::initialize IO object has been deleted." << std::endl; | ||
| return Status::Failure; | ||
| } | ||
| if (!ioPtr->canModifyObjects()) { | ||
| return Status::Failure; | ||
| } | ||
|
|
||
| // Call parent initialize method. | ||
| Status initStatus = Status::Success; | ||
| Status parentInitStatus = NWBContainer::initialize(); | ||
| initStatus = initStatus && parentInitStatus; | ||
|
|
||
| // Initialize attributes, datasets, and groups | ||
| // Initialize age dataset and age/reference attribute if age is provided | ||
| if (subjectSpec.age.has_value()) { | ||
| Status ageStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "age"), subjectSpec.age.value()); | ||
| initStatus = initStatus && ageStatus; | ||
| if (!ageStatus) { | ||
| std::cerr << "Failed to create age dataset." << std::endl; | ||
| } else { | ||
| std::string ageReference = subjectSpec.ageReference.value_or("birth"); | ||
| Status ageRefStatus = ioPtr->createAttribute( | ||
| ageReference, mergePaths(this->m_path, "age"), "reference"); | ||
| initStatus = initStatus && ageRefStatus; | ||
| if (!ageRefStatus) { | ||
| std::cerr << "Failed to create age reference attribute." << std::endl; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Initialize date_of_birth dataset if date_of_birth is provided | ||
| if (subjectSpec.dateOfBirth.has_value()) { | ||
| Status dobStatus = | ||
| ioPtr->createStringDataSet(mergePaths(this->m_path, "date_of_birth"), | ||
| subjectSpec.dateOfBirth.value()); | ||
| initStatus = initStatus && dobStatus; | ||
| if (!dobStatus) { | ||
| std::cerr << "Failed to create date_of_birth dataset." << std::endl; | ||
| } | ||
| if (isISO8601Date(subjectSpec.dateOfBirth.value()) == false) { | ||
| std::cerr << "Warning: date_of_birth is not in ISO8601 format: " | ||
| << subjectSpec.dateOfBirth.value() << std::endl; | ||
| } | ||
| } | ||
|
oruebel marked this conversation as resolved.
|
||
| // Initialize description dataset if description is provided | ||
| if (subjectSpec.description.has_value()) { | ||
| Status descStatus = | ||
| ioPtr->createStringDataSet(mergePaths(this->m_path, "description"), | ||
| subjectSpec.description.value()); | ||
| initStatus = initStatus && descStatus; | ||
| if (!descStatus) { | ||
| std::cerr << "Failed to create description dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize genotype dataset if genotype is provided | ||
| if (subjectSpec.genotype.has_value()) { | ||
| Status genotypeStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "genotype"), subjectSpec.genotype.value()); | ||
| initStatus = initStatus && genotypeStatus; | ||
| if (!genotypeStatus) { | ||
| std::cerr << "Failed to create genotype dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize sex dataset if sex is provided | ||
| if (subjectSpec.sex.has_value()) { | ||
| Status sexStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "sex"), subjectSpec.sex.value()); | ||
| initStatus = initStatus && sexStatus; | ||
| if (!sexStatus) { | ||
| std::cerr << "Failed to create sex dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize species dataset if species is provided | ||
| if (subjectSpec.species.has_value()) { | ||
| Status speciesStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "species"), subjectSpec.species.value()); | ||
| initStatus = initStatus && speciesStatus; | ||
| if (!speciesStatus) { | ||
| std::cerr << "Failed to create species dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize strain dataset if strain is provided | ||
| if (subjectSpec.strain.has_value()) { | ||
| Status strainStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "strain"), subjectSpec.strain.value()); | ||
| initStatus = initStatus && strainStatus; | ||
| if (!strainStatus) { | ||
| std::cerr << "Failed to create strain dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize subject_id dataset if subject_id is provided | ||
| if (subjectSpec.subjectId.has_value()) { | ||
| Status subjectIdStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "subject_id"), subjectSpec.subjectId.value()); | ||
| initStatus = initStatus && subjectIdStatus; | ||
| if (!subjectIdStatus) { | ||
| std::cerr << "Failed to create subject_id dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Initialize weight dataset if weight is provided | ||
| if (subjectSpec.weight.has_value()) { | ||
| Status weightStatus = ioPtr->createStringDataSet( | ||
| mergePaths(this->m_path, "weight"), subjectSpec.weight.value()); | ||
| initStatus = initStatus && weightStatus; | ||
| if (!weightStatus) { | ||
| std::cerr << "Failed to create weight dataset." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| // Return the overall status of the initialization | ||
| return initStatus; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.