Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pcm32 committed Oct 24, 2024
1 parent c969cc5 commit 7b1f0f1
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions run_galaxy_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,35 @@
"""

import argparse
from os import path, remove
import logging
from collections.abc import Mapping
from sys import exit
from bioblend.galaxy import GalaxyInstance

from bioblend import ConnectionError
from bioblend.galaxy import GalaxyInstance

from wfexecutor import (
ExecutionState,
completion_state,
download_results,
export_results_to_data_library,
get_instance,
get_workflow_from_file,
get_workflow_id,
load_input_files,
process_allowed_errors,
produce_versions_file,
read_json_file,
read_yaml_file,
set_params,
validate_dataset_id_exists,
validate_file_exists,
validate_input_labels,
validate_labels,
)

from wfexecutor import *
# Exit status:
# 3 - history deletion problem
#from wfexecutor import download_results, set_params, load_input_files, validate_labels, validate_input_labels, \
# validate_file_exists, validate_dataset_id_exists, completion_state, process_allowed_errors, produce_versions_file


def get_args():
Expand Down Expand Up @@ -81,12 +100,16 @@ def get_args():
arg_parser.add_argument('-l', '--library-name',
required=False,
default=None,
help="Upload results to data library with the name specified. Results will not be downoaded locally."
help=("Upload results to data library with the name specified. "
"Results will not be downloaded locally.")
)
arg_parser.add_argument('--publish', action='store_true',
default=False, help="Keep result history and make it public/accesible.")
default=False,
help="Keep result history and make it public/accesible.")
arg_parser.add_argument('--accessible', action='store_true',
default=False, help="Keep result history and make it accessible via link only.")
default=False,
help="Keep result history and make it accessible "
"via link only.")
args = arg_parser.parse_args()
return args

Expand All @@ -106,14 +129,19 @@ def main():
# Load workflows, inputs and parameters
wf_from_json = read_json_file(args.workflow)
if args.parameters:
param_data = read_yaml_file(args.parameters) if args.parameters_yaml else read_json_file(args.parameters)
param_data = (
read_yaml_file(args.parameters)
if args.parameters_yaml
else read_json_file(args.parameters)
)
else:
param_data = dict()
inputs_data = read_yaml_file(args.yaml_inputs_path)
allowed_error_states = {'tools': {}, 'datasets': set()}
if args.allowed_errors is not None:
allowed_error_states = \
process_allowed_errors(read_yaml_file(args.allowed_errors), wf_from_json)
process_allowed_errors(read_yaml_file(args.allowed_errors),
wf_from_json)

# Move any simple parameters from parameters to inputs
params_to_move = []
Expand Down Expand Up @@ -184,22 +212,28 @@ def main():
if state.results is None:
try:
logging.info('Running workflow {}...'.format(show_wf['name']))
results = gi.workflows.invoke_workflow(workflow_id=workflow_id,
inputs=datamap,
params=params,
history_name=(args.history + '_results'))
results = gi.workflows.invoke_workflow(
workflow_id=workflow_id,
inputs=datamap,
params=params,
history_name=(args.history + '_results')
)
state.results = results
state.save_state()
except Exception as ce:
logging.error("Failure when invoking invoke workflows: {}".format(str(ce)))
logging.error(
"Failure when invoking invoke workflows: {}".format(str(ce))
)
raise ce
else:
logging.info("Invocation result present in state, resuming that invocation")
results = state.results

# Produce tool versions file
produce_versions_file(gi=gi, workflow_from_json=wf_from_json,
table_path="{}/software_versions_galaxy.txt".format(args.output_dir))
table_path=(
"{}/software_versions_galaxy.txt".format(args.output_dir)
))

# wait for a little while and check if the status is ok
logging.info("Waiting for results to be available...")
Expand Down Expand Up @@ -265,7 +299,7 @@ def main():
if lib_id:
export_results_to_data_library(gi=gi, history_id=results['history_id'], lib_id=lib_id, allowed_error_states=allowed_error_states)
else:
logging.error('Library {} not found, results not uploaded to library'.args.library_name)
logging.error(f'Library {args.library_name} not found, results not uploaded to library')

else:
# If library name not specied then Download results
Expand Down Expand Up @@ -324,4 +358,3 @@ def main():

if __name__ == '__main__':
main()

0 comments on commit 7b1f0f1

Please sign in to comment.