From beafe2c099b6cbd7b6b9d5f25f7923862f4c5990 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Fri, 27 Sep 2024 11:34:50 -0400 Subject: [PATCH] Drop python wrapper --- .../data_manager/bwa_mem2_index_builder.py | 83 ------------------- .../data_manager/bwa_mem2_index_builder.xml | 49 ++++++++--- .../test-data/bwa_mem2_data_manager.1.json | 12 +++ .../test-data/bwa_mem2_data_manager.2.json | 12 +++ .../test-data/bwa_mem2_data_manager.json | 1 - 5 files changed, 62 insertions(+), 95 deletions(-) delete mode 100644 data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.py create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.1.json create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.2.json delete mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json diff --git a/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.py b/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.py deleted file mode 100644 index 79444e63809..00000000000 --- a/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -# Based heavily on the bwa-mem data manager wrapper script by Dan Blankenberg -from __future__ import print_function - -import argparse -import json -import os -import subprocess -import sys - -DEFAULT_DATA_TABLE_NAME = "bwa_mem2_indexes" - - -def get_id_name(params, dbkey, fasta_description=None): - # TODO: ensure sequence_id is unique and does not already appear in location file - sequence_id = params['param_dict']['sequence_id'] - if not sequence_id: - sequence_id = dbkey - - sequence_name = params['param_dict']['sequence_name'] - if not sequence_name: - sequence_name = fasta_description - if not sequence_name: - sequence_name = dbkey - return sequence_id, sequence_name - - -def build_bwa_mem2_index(data_manager_dict, options, params, sequence_id, sequence_name): - data_table_name = options.data_table_name or DEFAULT_DATA_TABLE_NAME - target_directory = params['output_data'][0]['extra_files_path'] - if not os.path.exists(target_directory): - os.mkdir(target_directory) - fasta_base_name = os.path.split(options.fasta_filename)[-1] - sym_linked_fasta_filename = os.path.join(target_directory, fasta_base_name) - os.symlink(options.fasta_filename, sym_linked_fasta_filename) - args = ['bwa-mem2', 'index', sym_linked_fasta_filename] - proc = subprocess.Popen(args=args, shell=False, cwd=target_directory) - return_code = proc.wait() - if return_code: - print("Error building index.", file=sys.stderr) - sys.exit(return_code) - data_table_entry = dict(value=sequence_id, dbkey=options.fasta_dbkey, name=sequence_name, path=fasta_base_name) - _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry) - - -def _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry): - data_manager_dict['data_tables'] = data_manager_dict.get('data_tables', {}) - data_manager_dict['data_tables'][data_table_name] = data_manager_dict['data_tables'].get(data_table_name, []) - data_manager_dict['data_tables'][data_table_name].append(data_table_entry) - return data_manager_dict - - -def main(): - # Parse Command Line - parser = argparse.ArgumentParser() - parser.add_argument('--output', dest='output', action='store', type=str, default=None) - parser.add_argument('--fasta_filename', dest='fasta_filename', action='store', type=str, default=None) - parser.add_argument('--fasta_dbkey', dest='fasta_dbkey', action='store', type=str, default=None) - parser.add_argument('--fasta_description', dest='fasta_description', action='store', type=str, default=None) - parser.add_argument('--data_table_name', dest='data_table_name', action='store', type=str, default='bwa_mem2_indexes') - options = parser.parse_args() - - filename = options.output - - with open(filename) as fh: - params = json.load(fh) - data_manager_dict = {} - - if options.fasta_dbkey in [None, '', '?']: - raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (options.fasta_dbkey)) - - sequence_id, sequence_name = get_id_name(params, dbkey=options.fasta_dbkey, fasta_description=options.fasta_description) - - # build the index - build_bwa_mem2_index(data_manager_dict, options, params, sequence_id, sequence_name) - - # save info to json file - with open(filename, 'w') as fh: - json.dump(data_manager_dict, fh, sort_keys=True) - - -if __name__ == "__main__": - main() diff --git a/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.xml b/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.xml index 69145e91fe2..1d7af2d5099 100644 --- a/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.xml +++ b/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.xml @@ -1,18 +1,39 @@ - - builder + + + + 2.2.1 + 0 + - bwa-mem2 - python + bwa-mem2 + + + @@ -26,7 +47,13 @@ - + + + + + + + diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.1.json b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.1.json new file mode 100644 index 00000000000..344c77f9b7e --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.1.json @@ -0,0 +1,12 @@ +{ + "data_tables":{ + "bwa_mem2_indexes":[ + { + "value": "phiX174", + "dbkey": "phiX174", + "name": "phiX174", + "path": "phiX174.fasta" + } + ] + } +} diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.2.json b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.2.json new file mode 100644 index 00000000000..259853414c6 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.2.json @@ -0,0 +1,12 @@ +{ + "data_tables":{ + "bwa_mem2_indexes":[ + { + "value": "fooBar1", + "dbkey": "phiX174", + "name": "Galeocerdo cuvier", + "path": "phiX174.fasta" + } + ] + } +} diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json deleted file mode 100644 index 413fb8c3992..00000000000 --- a/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json +++ /dev/null @@ -1 +0,0 @@ -{"data_tables": {"bwa_mem2_indexes": [{"dbkey": "phiX174", "name": "phiX174", "path": "phiX174.fasta", "value": "phiX174"}]}} \ No newline at end of file