Skip to content

Commit

Permalink
Multi study ingest & export (#152)
Browse files Browse the repository at this point in the history
* create multiple studies

* improve ingest error reporting in the terminal

* cleaned up imports

* updated export test output with accession id nested json

* added try catch & logging function to all attempts at creating models

* updated logger name and fixed classes being passed through to logging
  • Loading branch information
sherwoodf authored Aug 20, 2024
1 parent 897014a commit 03e74ca
Show file tree
Hide file tree
Showing 20 changed files with 513 additions and 344 deletions.
10 changes: 6 additions & 4 deletions bia-export/bia_export/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from rich.logging import RichHandler
from typing_extensions import Annotated
from pathlib import Path
from .website_conversion import create_study
from .website_conversion import create_studies
from typing import List
import json

logging.basicConfig(
level="NOTSET", format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
Expand All @@ -15,17 +17,17 @@

@app.command()
def website_study(
accession_id: Annotated[str, typer.Argument(help="Accession ID of the study to export")],
accession_id_list: Annotated[List[str], typer.Argument(help="Accession IDs of the studies to export")],
root_directory: Annotated[Path, typer.Option("--root", "-r", help="If root directory specified then use files there, rather than calling API")] = None,
output_filename: Annotated[Path, typer.Option("--out_file", "-o",)] = Path("bia-images-export.json")
):

abs_root = root_directory.resolve()
study = create_study(accession_id, abs_root)
studies_map = create_studies(accession_id_list, abs_root)

logging.info(f"Writing study info to {output_filename.absolute()}")
with open(output_filename, "w") as output:
output.write(study.model_dump_json(indent=4))
output.write(json.dumps(studies_map, indent=4))


@app.command()
Expand Down
10 changes: 9 additions & 1 deletion bia-export/bia_export/website_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def find_associated_objects(
return linked_object


def create_studies(accession_id_list: str, root_directory: Path) -> dict:
study_map = {}
for accession_id in accession_id_list:
study = create_study(accession_id, root_directory)
study_map[accession_id] = study.model_dump(mode='json')
return study_map


def create_study(accession_id: str, root_directory: Path) -> Study:

if root_directory:
Expand Down Expand Up @@ -171,7 +179,7 @@ def process_details_section(
eid_dict["specimen_growth_protocol"] = process_details_section(
root_directory,
accession_id,
detail_map[BioSample],
detail_map[SpecimenGrowthProtocol],
association_by_type["specimen"],
)
eid_dict["acquisition_process"] = process_details_section(
Expand Down
Loading

0 comments on commit 03e74ca

Please sign in to comment.