CCPEM Pipeliner
Guide

Python API: Managing Jobs and Job Files

PipelinerProject methods for finding, renaming, deleting and updating jobs, and the api_utils job-file helpers


Overview

This page is the API reference for finding, inspecting, renaming, deleting, and updating jobs inside a pipeliner project, together with the job-file helper functions in pipeliner.api.api_utils. You will use these methods any time you need to query or manipulate existing jobs programmatically — for example, when building automation scripts that track job state, compare parameters across runs, or tidy up a project after processing. All project methods live on PipelinerProject, which you import from pipeliner.api.manage_project; the file helpers are imported from pipeliner.api.api_utils.


Usage

Import PipelinerProject from pipeliner.api.manage_project and instantiate it in the directory that contains your project's default_pipeline.star file. All methods operate on the current working directory.

import os
os.chdir("/path/to/my/project")

from pipeliner.api.manage_project import PipelinerProject
proj = PipelinerProject()

PipelinerProject is not a context manager — instantiate it directly and call methods on the resulting object. Every method that accepts a job name expects a full name such as 'MotionCorr/job002/' (trailing slash is optional) or a full alias such as 'MotionCorr/my_alias/'. Short forms like 'job002' or '2' are not resolved by PipelinerProject methods directly; call parse_procname() first to convert them.

Resolving ambiguous job names

# Resolve a short form before passing to other methods
full_name = proj.parse_procname("2")
# full_name -> e.g. 'MotionCorr/job002/'

Job-file helpers (api_utils)

The functions in pipeliner.api.api_utils let you generate template parameter files for any registered job type, then edit them before scheduling a job.

from pipeliner.api.api_utils import (
    write_default_jobstar,
    write_default_runjob,
    edit_jobstar,
    job_default_parameters_dict,
    get_job_info,
    validate_starfile,
)
  • write_default_jobstar(jobtype) — creates a STAR-format job.star template. Use this as input to edit_jobstar().
  • write_default_runjob(jobtype) — creates a human-readable run.job template (lines in <label> == <value> format). Use this with pipeliner --run_job or pass the filename to run_job().
  • edit_jobstar(fn_template, params_to_change, out_fn) — modifies one or more parameters in a job.star file. The fn_template argument must be a STAR file (e.g. produced by write_default_jobstar); passing a run.job file raises ValueError("File <name> is not a valid STAR file. ..."), because a run.job file can't be parsed as STAR.
  • job_default_parameters_dict(jobtype) — returns a dict of all parameters with string values, including _rlnJobTypeLabel, _rlnJobIsContinue, and _rlnJobIsTomo keys. Suitable for direct use with run_job().

Updating job status

update_job_status(job, new_status) accepts 'Succeeded', 'Failed', 'Aborted', 'Running', or 'Scheduled' (capitalised). Lowercase values raise ValueError. Note that you cannot use this method to set a Running job to 'Aborted'; use abort_job() instead.

Deleting and restoring jobs

Deleted jobs are moved to the Trash/ directory. Cleanup moves removed files into Trash/Cleanup/. Both operations can be reversed.

# Move a job to Trash
proj.delete_job("MotionCorr/job002/")

# Restore it
proj.undelete_job("MotionCorr/job002/")

# Empty Trash permanently (no confirmation prompt in the API)
PipelinerProject.empty_trash()

Cleanup

run_cleanup(jobs, harsh=False) requires full job names; short forms are not resolved and the method logs 'Could not find job' and returns False.

proj.run_cleanup(["MotionCorr/job002/"], harsh=False)
proj.cleanup_all(harsh=True)
proj.restore_from_cleanup("MotionCorr/job002/")

Examples

Resolve a job number to a full name

import os
os.chdir("/path/to/my/project")

from pipeliner.api.manage_project import PipelinerProject
proj = PipelinerProject()

full_name = proj.parse_procname("3")

Resolve several job identifiers at once

full_names = proj.parse_proclist(["1", "job002", "CtfFind/job003/"])

Look up a job object by its full name

job = proj.get_job("MotionCorr/job002/")
# job.output_dir contains the job's directory

Note: get_job() accepts full names and full aliases; resolve short forms with parse_procname() first.


Assign an alias to a job

proj.set_alias("MotionCorr/job002/", "motion_correction_pass1")
# Clear an alias by passing None
proj.set_alias("MotionCorr/job002/", None)

Update a job's status

# Mark a scheduled job as Succeeded (e.g. after external processing)
proj.update_job_status("Import/job001/", "Succeeded")

Valid values: 'Succeeded', 'Failed', 'Aborted', 'Running', 'Scheduled'. Lowercase variants raise ValueError.


Add or overwrite a comment on a job

# Append a note to the existing comment
proj.edit_comment("MotionCorr/job002/", "Rerun with updated gain reference")

# Overwrite the existing comment entirely
proj.edit_comment("MotionCorr/job002/", "Fresh start", overwrite=True)

Find jobs by comment content

# Returns List[str] of matching job names.
# Matching is disjunctive: a job is included if its comment contains ANY of the
# strings in `contains` and NONE of the strings in `not_contains`.
matches = proj.find_job_by_comment(
    contains=["gain reference"],
    not_contains=["deprecated"],
)

Delete and undelete a job

success = proj.delete_job("MotionCorr/job002/")   # -> bool
success = proj.undelete_job("MotionCorr/job002/")  # -> bool

Deleted jobs are moved to Trash/ regardless of their status.


Restore all trashed jobs

proj.undelete_all_trashed_jobs()

Empty the trash permanently

# Staticmethod — no instance required
ok = PipelinerProject.empty_trash()  # True on success, False if Trash is empty

Run cleanup on specific jobs

run_cleanup() requires full job names.

# Standard cleanup
proj.run_cleanup(["MotionCorr/job002/", "CtfFind/job003/"])

# Harsh cleanup removes even more intermediate files
proj.run_cleanup(["MotionCorr/job002/"], harsh=True)

# Clean all jobs in the project
proj.cleanup_all(harsh=False)

# Restore files cleaned from a specific job
proj.restore_from_cleanup("MotionCorr/job002/")

Compare parameters across equivalent jobs

params = proj.compare_job_parameters(
    ["CtfFind/job003/", "CtfFind/job007/"]
)
# Returns dict mapping each parameter name to a list of its values across the jobs

Raises ValueError if a job is not found or if the jobs are of different types.


Add nodes missing from the pipeline graph

new_nodes = proj.add_missing_nodes_from_all_jobs()
# Returns List[str] of newly added node names

Generate a default job.star and edit it

from pipeliner.api.api_utils import write_default_jobstar, edit_jobstar

# 1. Write a STAR template for relion.motioncorr.own
template = write_default_jobstar("relion.motioncorr.own")
# template -> 'relion_motioncorr_own_job.star'

# 2. Edit specific parameters (use option name keys, not labels)
edited = edit_jobstar(
    fn_template=template,
    params_to_change={"input_star_mics": "Import/job001/movies.star"},
    out_fn="motioncorr_edited.job.star",
)
# edited -> 'motioncorr_edited.job.star'

Passing a run.job file as fn_template raises ValueError("File <name> is not a valid STAR file. ..."), because a run.job file can't be parsed as STAR.


Generate a default run.job file

from pipeliner.api.api_utils import write_default_runjob

runjob_file = write_default_runjob("relion.motioncorr.own")
# runjob_file -> 'relion_motioncorr_own_run.job'
# Lines use format: '<option label> == <value>'

Get a job's default parameters as a dict

from pipeliner.api.api_utils import job_default_parameters_dict

params = job_default_parameters_dict("relion.import.movies")
# Returns dict with all values as strings, including '_rlnJobTypeLabel' etc.
# Suitable for direct use with proj.run_job(params)

Get job information and check availability

from pipeliner.api.api_utils import get_job_info

info = get_job_info("relion.motioncorr.own")
# info.is_available -> bool
# info.unavailable_message -> str if not available

Validate a STAR file

from pipeliner.api.api_utils import validate_starfile

validate_starfile("Import/job001/movies.star")
# Attempts to fix reserved-word issues automatically;
# saves original with '.orig' suffix if corrections are made