Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,20 +594,20 @@ def prep_db_doc_for_download(self, db_doc):
elif key == "composition":
compositions = db_doc["composition"]
for comp_name, reference in compositions.items():
ref_link = reference["inherit"]
comp_doc = CompositionDoc(
comp_name,
object_key=None,
count=None,
regions={},
molarity=None,
priority=None,
)
composition_data, _ = comp_doc.get_reference_data(
ref_link, self.db
)
comp_doc.resolve_db_regions(composition_data, self.db)
compositions[comp_name] = composition_data
if ref_link := reference.get("inherit"):
comp_doc = CompositionDoc(
comp_name,
object_key=None,
count=None,
regions={},
molarity=None,
priority=None,
)
composition_data, _ = comp_doc.get_reference_data(
ref_link, self.db
)
comp_doc.resolve_db_regions(composition_data, self.db)
compositions[comp_name] = composition_data
prep_data[key] = compositions
else:
prep_data[key] = value
Expand Down Expand Up @@ -711,6 +711,16 @@ def remove_dedup_hash(data):
return [DBRecipeLoader.remove_dedup_hash(item) for item in data]
return data

def remove_empty(data):
"""Recursively removes empty values from dictionaries and lists."""
if isinstance(data, dict):
return {
k: DBRecipeLoader.remove_empty(v)
for k, v in data.items()
if v is not None and v != {}
}
return data

@staticmethod
def compile_db_recipe_data(db_recipe_data, obj_dict, grad_dict, comp_dict):
"""
Expand Down
8 changes: 5 additions & 3 deletions cellpack/autopack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,16 @@ def load_file(
db_handler = DBRecipeLoader(initialize_db)
db_handler.validate_input_recipe_path(filename)
recipe_id = file_path.split("/")[-1]
db_doc, _ = db_handler.collect_docs_by_id(collection="recipes", id=recipe_id)
collection = file_path.split("/")[0]
db_doc, _ = db_handler.collect_docs_by_id(collection=collection, id=recipe_id)
downloaded_recipe_data = db_handler.prep_db_doc_for_download(db_doc)
return downloaded_recipe_data, database_name
is_unnested_collection = collection == "recipes_edited"
return downloaded_recipe_data, database_name, is_unnested_collection
else:
local_file_path = get_local_file_location(
filename, destination=destination, cache=cache, force=force
)
return json.load(open(local_file_path, "r")), None
return json.load(open(local_file_path, "r")), None, False


def fixPath(adict): # , k, v):
Expand Down
1 change: 1 addition & 0 deletions cellpack/autopack/interface_objects/default_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
"recipes",
"results",
"configs",
"recipes_edited",
]
15 changes: 11 additions & 4 deletions cellpack/autopack/loaders/recipe_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ def _migrate_version(self, old_recipe):
)

def _read(self, resolve_inheritance=True, use_docker=False):
new_values, database_name = autopack.load_file(
new_values, database_name, is_unnested_firebase = autopack.load_file(
self.file_path, cache="recipes", use_docker=use_docker
)
if database_name == "firebase":
objects, gradients, composition = DBRecipeLoader.collect_and_sort_data(
new_values["composition"]
)
if is_unnested_firebase:
objects = new_values.get("objects", {})
gradients = new_values.get("gradients", {})
composition = DBRecipeLoader.remove_empty(
new_values.get("composition", {})
)
else:
objects, gradients, composition = DBRecipeLoader.collect_and_sort_data(
new_values["composition"]
)
new_values = DBRecipeLoader.compile_db_recipe_data(
new_values, objects, gradients, composition
)
Expand Down
Loading