-
Notifications
You must be signed in to change notification settings - Fork 3
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
Model updates, and some conversion logic #123
Changes from 2 commits
eb05833
687b69d
76ed1ea
5bc4daa
2f5c33c
204c804
0dc3088
a513a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import List, Any, Dict | ||
from .utils import ( | ||
dicts_to_api_models, | ||
find_sections_recursive, | ||
dict_to_uuid, | ||
persist | ||
) | ||
from ..biostudies import ( | ||
Submission, | ||
attributes_to_dict, | ||
) | ||
from ..config import settings | ||
from src.bia_models import bia_data_model, semantic_models | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def get_image_acquisition( | ||
submission: Submission, persist_artefacts=False | ||
) -> List[bia_data_model.Specimen]: | ||
sherwoodf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
image_acquisition_model_dicts = extract_image_acquisition_dicts(submission) | ||
image_acquisitions = dicts_to_api_models(image_acquisition_model_dicts, bia_data_model.ImageAcquisition) | ||
|
||
if persist_artefacts and image_acquisitions: | ||
persist(image_acquisitions, "specimen_growth_protocol", submission.accno) | ||
sherwoodf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return image_acquisitions | ||
|
||
|
||
def extract_image_acquisition_dicts(submission: Submission) -> List[Dict[str, Any]]: | ||
acquisition_sections = find_sections_recursive(submission.section, ["Image acquisition"], []) | ||
|
||
key_mapping = [ | ||
("title_id", "Title", ""), | ||
("protocol_description", "Image acquisition parameters", ""), | ||
("imaging_instrument_description", "Imaging instrument", ""), | ||
("imaging_method_name", "Imaging method", ""), | ||
] | ||
|
||
model_dicts = [] | ||
for section in acquisition_sections: | ||
attr_dict = attributes_to_dict(section.attributes) | ||
|
||
model_dict = {k: attr_dict.get(v, default) for k, v, default in key_mapping} | ||
|
||
# TODO: change template / create logic to lookup the fbbi ID | ||
model_dict["fbbi_id"] = [] | ||
|
||
model_dict["accno"] = section.__dict__.get("accno", "") | ||
model_dict["accession_id"] = submission.accno | ||
model_dict["uuid"] = generate_image_acquisition_uuid(model_dict) | ||
model_dicts.append(model_dict) | ||
|
||
return model_dicts | ||
|
||
|
||
def generate_image_acquisition_uuid(protocol_dict: Dict[str, Any]) -> str: | ||
attributes_to_consider = [ | ||
"accession_id", | ||
"accno", | ||
"title_id", | ||
"protocol_description", | ||
"imaging_instrument_description", | ||
"imaging_method_name", | ||
"fbbi_id" | ||
] | ||
return dict_to_uuid(protocol_dict, attributes_to_consider) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import List, Any, Dict | ||
from .utils import ( | ||
dicts_to_api_models, | ||
find_sections_recursive, | ||
dict_to_uuid, | ||
persist | ||
) | ||
from ..biostudies import ( | ||
Submission, | ||
attributes_to_dict, | ||
) | ||
from ..config import settings | ||
from src.bia_models import bia_data_model, semantic_models | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def get_specimen_growth_protocol( | ||
submission: Submission, persist_artefacts=False | ||
) -> List[bia_data_model.Specimen]: | ||
sherwoodf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
specimen_growth_protocol_model_dicts = extract_specimen_growth_protocol_dicts(submission) | ||
specimen_growth_protocols = dicts_to_api_models(specimen_growth_protocol_model_dicts, bia_data_model.SpecimenGrowthProtocol) | ||
|
||
if persist_artefacts and specimen_growth_protocols: | ||
persist(specimen_growth_protocols, "specimen_growth_protocol", submission.accno) | ||
|
||
return specimen_growth_protocols | ||
|
||
|
||
def extract_specimen_growth_protocol_dicts(submission: Submission) -> List[Dict[str, Any]]: | ||
specimen_sections = find_sections_recursive(submission.section, ["Specimen"], []) | ||
|
||
key_mapping = [ | ||
("title_id", "Title", ""), | ||
("protocol_description", "Growth protocol", ""), | ||
] | ||
|
||
model_dicts = [] | ||
for section in specimen_sections: | ||
attr_dict = attributes_to_dict(section.attributes) | ||
|
||
model_dict = {k: attr_dict.get(v, default) for k, v, default in key_mapping} | ||
|
||
model_dict["accno"] = section.__dict__.get("accno", "") | ||
model_dict["accession_id"] = submission.accno | ||
model_dict["uuid"] = generate_specimen_growth_protocol_uuid(model_dict) | ||
model_dicts.append(model_dict) | ||
|
||
return model_dicts | ||
|
||
|
||
def generate_specimen_growth_protocol_uuid(protocol_dict: Dict[str, Any]) -> str: | ||
attributes_to_consider = [ | ||
"accession_id", | ||
"accno", | ||
"title_id", | ||
"protocol_description", | ||
] | ||
return dict_to_uuid(protocol_dict, attributes_to_consider) |
kbab marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import List, Any, Dict | ||
from .utils import ( | ||
dicts_to_api_models, | ||
find_sections_recursive, | ||
dict_to_uuid, | ||
persist | ||
) | ||
from ..biostudies import ( | ||
Submission, | ||
attributes_to_dict, | ||
) | ||
from ..config import settings | ||
from src.bia_models import bia_data_model, semantic_models | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
def get_specimen_preparation_protocol( | ||
submission: Submission, persist_artefacts=False | ||
) -> List[bia_data_model.Specimen]: | ||
sherwoodf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
specimen_preparation_protocol_model_dicts = extract_specimen_preparation_protocol_dicts(submission) | ||
specimen_preparation_protocols = dicts_to_api_models(specimen_preparation_protocol_model_dicts, bia_data_model.SpecimenPrepartionProtocol) | ||
|
||
if persist_artefacts and specimen_preparation_protocols: | ||
persist(specimen_preparation_protocols, "specimen_imaging_protocol", submission.accno) | ||
|
||
return specimen_preparation_protocols | ||
|
||
|
||
def extract_specimen_preparation_protocol_dicts(submission: Submission) -> List[Dict[str, Any]]: | ||
specimen_sections = find_sections_recursive(submission.section, ["Specimen"], []) | ||
|
||
key_mapping = [ | ||
("title_id", "Title", ""), | ||
("protocol_description", "Sample preparation protocol", ""), | ||
] | ||
|
||
model_dicts = [] | ||
for section in specimen_sections: | ||
attr_dict = attributes_to_dict(section.attributes) | ||
|
||
model_dict = {k: attr_dict.get(v, default) for k, v, default in key_mapping} | ||
|
||
# Currently generates empty list as we need to change the submission template | ||
model_dict["signal_channel_information"] = [] | ||
|
||
model_dict["accno"] = section.__dict__.get("accno", "") | ||
model_dict["accession_id"] = submission.accno | ||
model_dict["uuid"] = generate_specimen_preparation_uuid(model_dict) | ||
model_dicts.append(model_dict) | ||
|
||
return model_dicts | ||
|
||
|
||
def generate_specimen_preparation_uuid(protocol_dict: Dict[str, Any]) -> str: | ||
attributes_to_consider = [ | ||
"accession_id", | ||
"accno", | ||
"title_id", | ||
"protocol_description", | ||
] | ||
return dict_to_uuid(protocol_dict, attributes_to_consider) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think re module is used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But i guess we've changed the enums now, so we don't need that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed this - no I think we still need it! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
get_generic_section_as_dict, | ||
mattributes_to_dict, | ||
dict_to_uuid, | ||
find_sections_recursive | ||
find_sections_recursive, | ||
persist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't end up using this - so should remove the unused import (will do it in this PR if other changes are needed) |
||
) | ||
import bia_ingest_sm.conversion.experimental_imaging_dataset as eid_conversion | ||
from ..biostudies import ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to revisit the logic of this file in light of the fact that we are not storing the list of file_references anymore. We may have to trigger the generation of file_references after obtaining the uuid for the experimental dataset, so we can pass this to the function that creates file_references, allowing them to point to their parent expermental imaging dataset.