CCPEM Pipeliner
Guide

Python API: Cleanup, Reports, Archives and Depositions

PipelinerProject methods for cleanup, metadata and reference reports, archives and depositions


Overview

This page documents the PipelinerProject methods for cleaning up intermediate files, restoring cleaned files, generating metadata and reference reports, creating project archives, and preparing deposition packages for EMPIAR and OneDep. These operations are typically performed after one or more pipeline jobs have succeeded, and they operate on the current working directory as the project root. Import PipelinerProject from pipeliner.api.manage_project.


Usage

All methods are called on an instantiated PipelinerProject. Import it from its canonical module and change into your project directory before constructing the object:

import os
from pipeliner.api.manage_project import PipelinerProject

os.chdir("/data/my_project")
proj = PipelinerProject()

PipelinerProject is not a context manager; instantiate it directly and call methods on the returned object.


Cleanup

Cleanup moves non-essential intermediate files into Trash/Cleanup/ inside the project root. A timestamped entry is appended to .CCPEM_pipeliner_cleanup each time cleanup runs. run_cleanup() requires full job names (e.g., 'MotionCorr/job002/'); short forms such as 'job002' or '2' are not resolved by this method and will log 'Could not find job' and return False. Use parse_procname() first when you only have a short name.

run_cleanup(jobs, harsh=False) -> bool

Cleans up a specific list of jobs. Each job class defines which files are considered non-essential via prepare_clean_up_lists(do_harsh). Pass harsh=True to also move files that a normal cleanup preserves into Trash/Cleanup/.

# Clean a single job — full name required
success = proj.run_cleanup(["MotionCorr/job002/"])

# Harsh cleanup of several jobs
proj.run_cleanup(["Class2D/job005/", "Class3D/job006/"], harsh=True)

Returns True on success, False if any job was not found. Only jobs with status Succeeded are cleaned; any other job is skipped with a note in .CCPEM_pipeliner_cleanup, and the method still returns True.

cleanup_all(harsh=False) -> None

Runs cleanup on every Succeeded job in the project in one call.

proj.cleanup_all()
# or with harsh mode
proj.cleanup_all(harsh=True)

restore_from_cleanup(job: str) -> None

Restores files that were previously moved to Trash/Cleanup/ back into the job directory. The job parameter should be a full job name, including the trailing slash.

proj.restore_from_cleanup("MotionCorr/job002/")

restore_all_cleaned_up_files() -> None

Restores cleaned-up files for all jobs in the project.

proj.restore_all_cleaned_up_files()

empty_trash() -> bool (staticmethod)

Permanently deletes the Trash/ directory and everything in it. Returns True on success, False with a warning if Trash/ is empty or absent. There is no confirmation prompt when called from Python (unlike the CLI, which prompts).

PipelinerProject.empty_trash()

Reports

prepare_metadata_report(jobname: str) -> Tuple[str, int]

Generates a JSON metadata report for all jobs up to and including the named terminal job. The report is written to MetadataReports/. Returns a tuple (output_file, njobs) where output_file is the path to the generated report (relative to the project directory) and njobs is the number of jobs included. Returns ('', 0) if the job is not found.

output_file, njobs = proj.prepare_metadata_report("Refine3D/job010/")
print(f"Report covers {njobs} jobs: {output_file}")

create_reference_report(terminal_job: str) -> Tuple[str, int]

Generates a literature-reference report for all jobs up to and including the named terminal job. The report is written to ReferenceReports/ as a JSON file. Returns (output_file, njobs).

ref_file, njobs = proj.create_reference_report("PostProcess/job011/")

Archives

create_archive(job: str, full: bool = False, tar: bool = True) -> str

Creates a project archive rooted at the named terminal job. By default (full=False) a simple archive is created, which includes only the job parameter files and a script (run_project.py) needed to reproduce the workflow. Pass full=True to include all upstream job output files as well.

The archive is written under ProjectArchives/ and the filename is a date-time-tagged string such as 20240315143022_project_archive.tar.gz. The method returns the path including the directory (e.g. ProjectArchives/20240315143022_project_archive.tar.gz; with tar=False, the archive directory without .tar.gz), or an empty string '' if the terminal job is not found.

# Simple archive (job parameter files + rerun script only)
archive_path = proj.create_archive("PostProcess/job011/")

# Full archive (all upstream outputs included)
full_path = proj.create_archive("PostProcess/job011/", full=True)

Failed and Aborted jobs in the upstream graph are permitted. Running or Scheduled jobs cause the archive to be rejected with ValueError.


Depositions

Both deposition methods are staticmethods. They prepare local deposition packages but do not submit them; submission must be completed separately.

prepare_project_empiar_deposition(terminal_job, jobstar_file=None, empiar_do_mov=True, empiar_do_mics=True, empiar_do_parts=True, empiar_do_rparts=True) -> str

Prepares an EMPIAR deposition package for the specified terminal job. The empiar_do_* flags control which data types are included (movies, micrographs, particles, corrected particles). All four types are included by default.

The output is written to EMPIAR/<datetime>_EMPIAR.json (CLI / staticmethod route) when no jobstar_file is given; with a jobstar_file, it is written to deposition_data_EMPIAR.json in that file's directory. Returns the path to the generated JSON file.

# Prepare all data types
empiar_json = PipelinerProject.prepare_project_empiar_deposition(
    "Refine3D/job010/"
)

# Particles only
empiar_json = PipelinerProject.prepare_project_empiar_deposition(
    "Refine3D/job010/",
    empiar_do_mov=False,
    empiar_do_mics=False,
    empiar_do_rparts=False,
)

See the Depositions (OneDep/EMDB and EMPIAR) page for background on the deposition system.

prepare_project_onedep_deposition(model='', primary_map='', additional_maps=None, sequences=None, masks=None, halfmaps=None, depo_id='deposition') -> Tuple[str, List[ValidationError]]

Prepares an OneDep SPA deposition package from explicit file paths. model must be a path to an atomic model in mmCIF format (defaults to empty string). Returns a tuple (output_file, validation_errors) where output_file is the path to the generated deposition mmCIF file (EMDB/deposition_data_<depo_id>.cif) and validation_errors is a list of any mmCIF ValidationError objects found during preparation.

To submit, use the OneDep web interface, or run a pipeliner.deposition.onedep job (which assembles its own deposition from the project) and continue it with submit_to_onedep set to Yes.

from pipeliner.api.manage_project import PipelinerProject

onedep_cif, errors = PipelinerProject.prepare_project_onedep_deposition(
    model="PostProcess/job011/refined.mmcif",
    primary_map="PostProcess/job011/postprocess.mrc",
    halfmaps=[
        "Refine3D/job010/run_half1_class001_unfil.mrc",
        "Refine3D/job010/run_half2_class001_unfil.mrc",
    ],
    sequences=["sequence.fasta"],
    depo_id="my_deposition",
)
if errors:
    for err in errors:
        print(err)

OneDep credentials must be configured before submission. Credentials are stored at ~/.config/ccpem/pipeliner/onedep/config.toml on Linux (or ~/Library/Application Support/ccpem/pipeliner/onedep/config.toml on macOS) and can be set up with pipeliner.setup_onedep_credentials. See the Depositions (OneDep/EMDB and EMPIAR) page for full details.


Examples

Partial cleanup of specific jobs

from pipeliner.api.manage_project import PipelinerProject

proj = PipelinerProject()

# Pass full job names; short forms are NOT resolved by run_cleanup()
proj.run_cleanup(["MotionCorr/job002/", "CtfFind/job003/"])

Harsh cleanup of a single job

proj.run_cleanup(["Class2D/job005/"], harsh=True)

Clean up every job in the project

proj.cleanup_all(harsh=False)

Restore files cleaned from a job

proj.restore_from_cleanup("MotionCorr/job002/")

Restore cleaned files from every job at once

proj.restore_all_cleaned_up_files()

Delete a job (move to Trash)

success = proj.delete_job("Select/job007/")

Returns True on success, False on failure. The job directory is moved to Trash/ regardless of its status.


Recover a deleted job

success = proj.undelete_job("Select/job007/")

Permanently empty the trash

# staticmethod — no instance required, but you can call it on the instance
PipelinerProject.empty_trash()

Returns True if Trash/ was found and deleted, False if the trash was already empty. There is no confirmation prompt when called from Python (the Y/N prompt exists only in the CLI).


Create a simple archive up to a terminal job

archive_file = proj.create_archive(job="Refine3D/job010/")
# archive_file is a path like 'ProjectArchives/20240315120000_project_archive.tar.gz'

Create a full archive including all upstream outputs

archive_file = proj.create_archive(job="Refine3D/job010/", full=True)

Returns '' if the terminal job is not found in the pipeline.


Generate a metadata report

output_file, njobs = proj.prepare_metadata_report(jobname="PostProcess/job011/")
# output_file -> path inside MetadataReports/, e.g. 'MetadataReports/20240315120000_metadata_report.json'
# njobs -> number of jobs included in the report

Returns ('', 0) if the named job is not found.


Generate a reference report

output_file, njobs = proj.create_reference_report(terminal_job="PostProcess/job011/")
# output_file -> path inside ReferenceReports/, e.g. 'ReferenceReports/20240315120001_reference_report.json'

Prepare an EMPIAR deposition package

prepare_project_empiar_deposition is a staticmethod. Pass the terminal job and choose which data types to include using the empiar_do_* boolean flags (all default to True).

output_json = PipelinerProject.prepare_project_empiar_deposition(
    terminal_job="PostProcess/job011/",
    empiar_do_mov=True,
    empiar_do_mics=True,
    empiar_do_parts=True,
    empiar_do_rparts=True,
)
# output_json -> e.g. 'EMPIAR/20240315120002_EMPIAR.json'

The file is written to EMPIAR/<datetime>_EMPIAR.json. Submission to the EMPIAR portal must be completed manually.


Prepare an OneDep deposition package

prepare_project_onedep_deposition is also a staticmethod. Provide explicit file paths for the atomic model (mmCIF format), primary map, and any optional supplementary files.

from pipeliner.api.manage_project import PipelinerProject

output_file, validation_errors = PipelinerProject.prepare_project_onedep_deposition(
    model="PostProcess/job011/refined.mmcif",
    primary_map="PostProcess/job011/postprocess.mrc",
    halfmaps=[
        "Refine3D/job010/run_half1_class001_unfil.mrc",
        "Refine3D/job010/run_half2_class001_unfil.mrc",
    ],
    sequences=["sequence.fasta"],
    masks=["MaskCreate/job009/mask.mrc"],
    depo_id="my_deposition",
)
# output_file -> path to the prepared deposition data file
# validation_errors -> list of ValidationError objects (empty if no issues)

This method does not submit the deposition; use the OneDep web interface or the pipeliner.deposition.onedep job type for submission.


Resolve a short job name before passing to a method

When you only have a short form such as 'job005' or '5', resolve it first:

full_name = proj.parse_procname("5")
proj.run_cleanup([full_name])