From cb911d8e2331e4f9e2375e895cf7b9996ec42d6c Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Thu, 26 Sep 2024 09:50:23 -0400 Subject: [PATCH 1/2] Add bwa-mem2 data manager --- .../.shed.yml | 14 ++++ .../data_manager/bwa_mem2_index_builder.py | 83 +++++++++++++++++++ .../data_manager/bwa_mem2_index_builder.xml | 48 +++++++++++ .../data_manager_conf.xml | 20 +++++ .../test-data/all_fasta.loc | 19 +++++ .../test-data/bwa_mem2_data_manager.json | 1 + .../test-data/bwa_mem2_index.loc | 0 .../test-data/phiX174.fasta | 79 ++++++++++++++++++ .../tool-data/all_fasta.loc.sample | 18 ++++ .../tool-data/bwa_mem2_index.loc.sample | 38 +++++++++ .../tool_data_table_conf.xml.sample | 8 ++ .../tool_data_table_conf.xml.test | 12 +++ 12 files changed, 340 insertions(+) create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/.shed.yml create 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/data_manager/bwa_mem2_index_builder.xml create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/data_manager_conf.xml create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/all_fasta.loc create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_index.loc create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/test-data/phiX174.fasta create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/tool-data/all_fasta.loc.sample create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/tool-data/bwa_mem2_index.loc.sample create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.sample create mode 100644 data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.test diff --git a/data_managers/data_manager_bwa_mem2_index_builder/.shed.yml b/data_managers/data_manager_bwa_mem2_index_builder/.shed.yml new file mode 100644 index 00000000000..f1c429c613a --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/.shed.yml @@ -0,0 +1,14 @@ +categories: +- Data Managers +description: Bwa-mem2 is the next version of the bwa-mem algorithm in bwa. +homepage_url: https://github.com/bwa-mem2/bwa-mem2 +long_description: | + Bwa-mem2 is the next version of the bwa-mem algorithm in bwa. It produces + alignment identical to bwa and is ~1.3-3.1x faster depending on the use-case, + dataset and the running machine. Bwa-mem2 uses a different index format that + is efficient on disk space and runtime memory but requires larger amounts of + memory (roughly 27x the reference) when building. +name: data_manager_bwa_mem2_index_builder +owner: iuc +remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bwa_mem2_index_builder +type: unrestricted 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 new file mode 100644 index 00000000000..79444e63809 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.py @@ -0,0 +1,83 @@ +#!/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 new file mode 100644 index 00000000000..69145e91fe2 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/data_manager/bwa_mem2_index_builder.xml @@ -0,0 +1,48 @@ + + builder + + bwa-mem2 + python + + + + + + + + + + + + + + + + + + + + + + + + 10.1038/nmeth.3317 + + diff --git a/data_managers/data_manager_bwa_mem2_index_builder/data_manager_conf.xml b/data_managers/data_manager_bwa_mem2_index_builder/data_manager_conf.xml new file mode 100644 index 00000000000..a757b4094d1 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/data_manager_conf.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + ${dbkey}/bwa_mem2_index/${value} + + ${GALAXY_DATA_MANAGER_DATA_PATH}/${dbkey}/bwa_mem2_index/${value}/${path} + abspath + + + + + diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/all_fasta.loc b/data_managers/data_manager_bwa_mem2_index_builder/test-data/all_fasta.loc new file mode 100644 index 00000000000..c8b25f3f801 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/test-data/all_fasta.loc @@ -0,0 +1,19 @@ +#This file lists the locations and dbkeys of all the fasta files +#under the "genome" directory (a directory that contains a directory +#for each build). The script extract_fasta.py will generate the file +#all_fasta.loc. This file has the format (white space characters are +#TAB characters): +# +# +# +#So, all_fasta.loc could look something like this: +# +#apiMel3 apiMel3 Honeybee (Apis mellifera): apiMel3 /path/to/genome/apiMel3/apiMel3.fa +#hg19canon hg19 Human (Homo sapiens): hg19 Canonical /path/to/genome/hg19/hg19canon.fa +#hg19full hg19 Human (Homo sapiens): hg19 Full /path/to/genome/hg19/hg19full.fa +# +#Your all_fasta.loc file should contain an entry for each individual +#fasta file. So there will be multiple fasta files for each build, +#such as with hg19 above. +# +phiX174 phiX174 phiX174 ${__HERE__}/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 new file mode 100644 index 00000000000..413fb8c3992 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_data_manager.json @@ -0,0 +1 @@ +{"data_tables": {"bwa_mem2_indexes": [{"dbkey": "phiX174", "name": "phiX174", "path": "phiX174.fasta", "value": "phiX174"}]}} \ No newline at end of file diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_index.loc b/data_managers/data_manager_bwa_mem2_index_builder/test-data/bwa_mem2_index.loc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/data_managers/data_manager_bwa_mem2_index_builder/test-data/phiX174.fasta b/data_managers/data_manager_bwa_mem2_index_builder/test-data/phiX174.fasta new file mode 100644 index 00000000000..53df885dc48 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/test-data/phiX174.fasta @@ -0,0 +1,79 @@ +>phiX174 +GAGTTTTATCGCTTCCATGACGCAGAAGTTAACACTTTCGGATATTTCTGATGAGTCGAAAAATTATCTT +GATAAAGCAGGAATTACTACTGCTTGTTTACGAATTAAATCGAAGTGGACTGCTGGCGGAAAATGAGAAA +ATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCTTTCGCCATCAACTAACGATTCTG +TCAAAAACTGACGCGTTGGATGAGGAGAAGTGGCTTAATATGCTTGGCACGTTCGTCAAGGACTGGTTTA +GATATGAGTCACATTTTGTTCATGGTAGAGATTCTCTTGTTGACATTTTAAAAGAGCGTGGATTACTATC +TGAGTCCGATGCTGTTCAACCACTAATAGGTAAGAAATCATGAGTCAAGTTACTGAACAATCCGTACGTT +TCCAGACCGCTTTGGCCTCTATTAAGCTCATTCAGGCTTCTGCCGTTTTGGATTTAACCGAAGATGATTT +CGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCGCTGCGTTGAGGCT +TGCGTTTATGGTACGCTGGACTTTGTGGGATACCCTCGCTTTCCTGCTCCTGTTGAGTTTATTGCTGCCG +TCATTGCTTATTATGTTCATCCCGTCAACATTCAAACGGCCTGTCTCATCATGGAAGGCGCTGAATTTAC +GGAAAACATTATTAATGGCGTCGAGCGTCCGGTTAAAGCCGCTGAATTGTTCGCGTTTACCTTGCGTGTA +CGCGCAGGAAACACTGACGTTCTTACTGACGCAGAAGAAAACGTGCGTCAAAAATTACGTGCAGAAGGAG +TGATGTAATGTCTAAAGGTAAAAAACGTTCTGGCGCTCGCCCTGGTCGTCCGCAGCCGTTGCGAGGTACT +AAAGGCAAGCGTAAAGGCGCTCGTCTTTGGTATGTAGGTGGTCAACAATTTTAATTGCAGGGGCTTCGGC +CCCTTACTTGAGGATAAATTATGTCTAATATTCAAACTGGCGCCGAGCGTATGCCGCATGACCTTTCCCA +TCTTGGCTTCCTTGCTGGTCAGATTGGTCGTCTTATTACCATTTCAACTACTCCGGTTATCGCTGGCGAC +TCCTTCGAGATGGACGCCGTTGGCGCTCTCCGTCTTTCTCCATTGCGTCGTGGCCTTGCTATTGACTCTA +CTGTAGACATTTTTACTTTTTATGTCCCTCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAA +GGATGGTGTTAATGCCACTCCTCTCCCGACTGTTAACACTACTGGTTATATTGACCATGCCGCTTTTCTT +GGCACGATTAACCCTGATACCAATAAAATCCCTAAGCATTTGTTTCAGGGTTATTTGAATATCTATAACA +ACTATTTTAAAGCGCCGTGGATGCCTGACCGTACCGAGGCTAACCCTAATGAGCTTAATCAAGATGATGC +TCGTTATGGTTTCCGTTGCTGCCATCTCAAAAACATTTGGACTGCTCCGCTTCCTCCTGAGACTGAGCTT +TCTCGCCAAATGACGACTTCTACCACATCTATTGACATTATGGGTCTGCAAGCTGCTTATGCTAATTTGC +ATACTGACCAAGAACGTGATTACTTCATGCAGCGTTACCGTGATGTTATTTCTTCATTTGGAGGTAAAAC +CTCTTATGACGCTGACAACCGTCCTTTACTTGTCATGCGCTCTAATCTCTGGGCATCTGGCTATGATGTT +GATGGAACTGACCAAACGTCGTTAGGCCAGTTTTCTGGTCGTGTTCAACAGACCTATAAACATTCTGTGC +CGCGTTTCTTTGTTCCTGAGCATGGCACTATGTTTACTCTTGCGCTTGTTCGTTTTCCGCCTACTGCGAC +TAAAGAGATTCAGTACCTTAACGCTAAAGGTGCTTTGACTTATACCGATATTGCTGGCGACCCTGTTTTG +TATGGCAACTTGCCGCCGCGTGAAATTTCTATGAAGGATGTTTTCCGTTCTGGTGATTCGTCTAAGAAGT +TTAAGATTGCTGAGGGTCAGTGGTATCGTTATGCGCCTTCGTATGTTTCTCCTGCTTATCACCTTCTTGA +AGGCTTCCCATTCATTCAGGAACCGCCTTCTGGTGATTTGCAAGAACGCGTACTTATTCGCCACCATGAT +TATGACCAGTGTTTCCAGTCCGTTCAGTTGTTGCAGTGGAATAGTCAGGTTAAATTTAATGTGACCGTTT +ATCGCAATCTGCCGACCACTCGCGATTCAATCATGACTTCGTGATAAAAGATTGAGTGTGAGGTTATAAC +GCCGAAGCGGTAAAAATTTTAATTTTTGCCGCTGAGGGGTTGACCAAGCGAAGCGCGGTAGGTTTTCTGC +TTAGGAGTTTAATCATGTTTCAGACTTTTATTTCTCGCCATAATTCAAACTTTTTTTCTGATAAGCTGGT +TCTCACTTCTGTTACTCCAGCTTCTTCGGCACCTGTTTTACAGACACCTAAAGCTACATCGTCAACGTTA +TATTTTGATAGTTTGACGGTTAATGCTGGTAATGGTGGTTTTCTTCATTGCATTCAGATGGATACATCTG +TCAACGCCGCTAATCAGGTTGTTTCTGTTGGTGCTGATATTGCTTTTGATGCCGACCCTAAATTTTTTGC +CTGTTTGGTTCGCTTTGAGTCTTCTTCGGTTCCGACTACCCTCCCGACTGCCTATGATGTTTATCCTTTG +AATGGTCGCCATGATGGTGGTTATTATACCGTCAAGGACTGTGTGACTATTGACGTCCTTCCCCGTACGC +CGGGCAATAATGTTTATGTTGGTTTCATGGTTTGGTCTAACTTTACCGCTACTAAATGCCGCGGATTGGT +TTCGCTGAATCAGGTTATTAAAGAGATTATTTGTCTCCAGCCACTTAAGTGAGGTGATTTATGTTTGGTG +CTATTGCTGGCGGTATTGCTTCTGCTCTTGCTGGTGGCGCCATGTCTAAATTGTTTGGAGGCGGTCAAAA +AGCCGCCTCCGGTGGCATTCAAGGTGATGTGCTTGCTACCGATAACAATACTGTAGGCATGGGTGATGCT +GGTATTAAATCTGCCATTCAAGGCTCTAATGTTCCTAACCCTGATGAGGCCGCCCCTAGTTTTGTTTCTG +GTGCTATGGCTAAAGCTGGTAAAGGACTTCTTGAAGGTACGTTGCAGGCTGGCACTTCTGCCGTTTCTGA +TAAGTTGCTTGATTTGGTTGGACTTGGTGGCAAGTCTGCCGCTGATAAAGGAAAGGATACTCGTGATTAT +CTTGCTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGG +TTGACGCCGGATTTGAGAATCAAAAAGAGCTTACTAAAATGCAACTGGACAATCAGAAAGAGATTGCCGA +GATGCAAAATGAGACTCAAAAAGAGATTGCTGGCATTCAGTCGGCGACTTCACGCCAGAATACGAAAGAC +CAGGTATATGCACAAAATGAGATGCTTGCTTATCAACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTA +TGGAAAACACCAATCTTTCCAAGCAACAGCAGGTTTCCGAGATTATGCGCCAAATGCTTACTCAAGCTCA +AACGGCTGGTCAGTATTTTACCAATGACCAAATCAAAGAAATGACTCGCAAGGTTAGTGCTGAGGTTGAC +TTAGTTCATCAGCAAACGCAGAATCAGCGGTATGGCTCTTCTCATATTGGCGCTACTGCAAAGGATATTT +CTAATGTCGTCACTGATGCTGCTTCTGGTGTGGTTGATATTTTTCATGGTATTGATAAAGCTGTTGCCGA +TACTTGGAACAATTTCTGGAAAGACGGTAAAGCTGATGGTATTGGCTCTAATTTGTCTAGGAAATAACCG +TCAGGATTGACACCCTCCCAATTGTATGTTTTCATGCCTCCAAATCTTGGAGGCTTTTTTATGGTTCGTT +CTTATTACCCTTCTGAATGTCACGCTGATTATTTTGACTTTGAGCGTATCGAGGCTCTTAAACCTGCTAT +TGAGGCTTGTGGCATTTCTACTCTTTCTCAATCCCCAATGCTTGGCTTCCATAAGCAGATGGATAACCGC +ATCAAGCTCTTGGAAGAGATTCTGTCTTTTCGTATGCAGGGCGTTGAGTTCGATAATGGTGATATGTATG +TTGACGGCCATAAGGCTGCTTCTGACGTTCGTGATGAGTTTGTATCTGTTACTGAGAAGTTAATGGATGA +ATTGGCACAATGCTACAATGTGCTCCCCCAACTTGATATTAATAACACTATAGACCACCGCCCCGAAGGG +GACGAAAAATGGTTTTTAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGCTGAACGCC +CTCTTAAGGATATTCGCGATGAGTATAATTACCCCAAAAAGAAAGGTATTAAGGATGAGTGTTCAAGATT +GCTGGAGGCCTCCACTATGAAATCGCGTAGAGGCTTTACTATTCAGCGTTTGATGAATGCAATGCGACAG +GCTCATGCTGATGGTTGGTTTATCGTTTTTGACACTCTCACGTTGGCTGACGACCGATTAGAGGCGTTTT +ATGATAATCCCAATGCTTTGCGTGACTATTTTCGTGATATTGGTCGTATGGTTCTTGCTGCCGAGGGTCG +CAAGGCTAATGATTCACACGCCGACTGCTATCAGTATTTTTGTGTGCCTGAGTATGGTACAGCTAATGGC +CGTCTTCATTTCCATGCGGTGCATTTTATGCGGACACTTCCTACAGGTAGCGTTGACCCTAATTTTGGTC +GTCGGGTACGCAATCGCCGCCAGTTAAATAGCTTGCAAAATACGTGGCCTTATGGTTACAGTATGCCCAT +CGCAGTTCGCTACACGCAGGACGCTTTTTCACGTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAG +CCGCTTAAAGCTACCAGTTATATGGCTGTTGGTTTCTATGTGGCTAAATACGTTAACAAAAAGTCAGATA +TGGACCTTGCTGCTAAAGGTCTAGGAGCTAAAGAATGGAACAACTCACTAAAAACCAAGCTGTCGCTACT +TCCCAAGAAGCTGTTCAGAATCAGAATGAGCCGCAACTTCGGGATGAAAATGCTCACAATGACAAATCTG +TCCACGGAGTGCTTAATCCAACTTACCAAGCTGGGTTACGACGCGACGCCGTTCAACCAGATATTGAAGC +AGAACGCAAAAAGAGAGATGAGATTGAGGCTGGGAAAAGTTACTGTAGCCGACGTTTTGGCGGCGCAACC +TGTGACGACAAATCTGCTCAAATTTATGCGCGCTTCGATAAAAATGATTGGCGTATCCAACCTGCA + diff --git a/data_managers/data_manager_bwa_mem2_index_builder/tool-data/all_fasta.loc.sample b/data_managers/data_manager_bwa_mem2_index_builder/tool-data/all_fasta.loc.sample new file mode 100644 index 00000000000..1a5a28d5e3f --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/tool-data/all_fasta.loc.sample @@ -0,0 +1,18 @@ +#This file lists the locations and dbkeys of all the fasta files +#under the "genome" directory (a directory that contains a directory +#for each build). The script extract_fasta.py will generate the file +#all_fasta.loc. This file has the format (white space characters are +#TAB characters): +# +# +# +#So, all_fasta.loc could look something like this: +# +#apiMel3 apiMel3 Honeybee (Apis mellifera): apiMel3 /path/to/genome/apiMel3/apiMel3.fa +#hg19canon hg19 Human (Homo sapiens): hg19 Canonical /path/to/genome/hg19/hg19canon.fa +#hg19full hg19 Human (Homo sapiens): hg19 Full /path/to/genome/hg19/hg19full.fa +# +#Your all_fasta.loc file should contain an entry for each individual +#fasta file. So there will be multiple fasta files for each build, +#such as with hg19 above. +# diff --git a/data_managers/data_manager_bwa_mem2_index_builder/tool-data/bwa_mem2_index.loc.sample b/data_managers/data_manager_bwa_mem2_index_builder/tool-data/bwa_mem2_index.loc.sample new file mode 100644 index 00000000000..d4c10ceadcd --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/tool-data/bwa_mem2_index.loc.sample @@ -0,0 +1,38 @@ +#This is a sample file distributed with Galaxy that enables tools +#to use a directory of BWA indexed sequences data files. You will need +#to create these data files and then create a bwa_index.loc file +#similar to this one (store it in this directory) that points to +#the directories in which those files are stored. The bwa_index.loc +#file has this format (longer white space characters are TAB characters): +# +# +# +#So, for example, if you had phiX indexed stored in +#/depot/data2/galaxy/phiX/base/, +#then the bwa_index.loc entry would look like this: +# +#phiX174 phiX phiX Pretty /depot/data2/galaxy/phiX/base/phiX.fa +# +#and your /depot/data2/galaxy/phiX/base/ directory +#would contain phiX.fa.* files: +# +#-rw-r--r-- 1 james universe 830134 2005-09-13 10:12 phiX.fa.amb +#-rw-r--r-- 1 james universe 527388 2005-09-13 10:12 phiX.fa.ann +#-rw-r--r-- 1 james universe 269808 2005-09-13 10:12 phiX.fa.bwt +#...etc... +# +#Your bwa_index.loc file should include an entry per line for each +#index set you have stored. The "file" in the path does not actually +#exist, but it is the prefix for the actual index files. For example: +# +#phiX174 phiX phiX174 /depot/data2/galaxy/phiX/base/phiX.fa +#hg18canon hg18 hg18 Canonical /depot/data2/galaxy/hg18/base/hg18canon.fa +#hg18full hg18 hg18 Full /depot/data2/galaxy/hg18/base/hg18full.fa +#/orig/path/hg19.fa hg19 hg19 /depot/data2/galaxy/hg19/base/hg19.fa +#...etc... +# +#Note that for backwards compatibility with workflows, the unique ID of +#an entry must be the path that was in the original loc file, because that +#is the value stored in the workflow for that parameter. That is why the +#hg19 entry above looks odd. New genomes can be better-looking. +# diff --git a/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.sample b/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.sample new file mode 100644 index 00000000000..48d0b020104 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.sample @@ -0,0 +1,8 @@ + + + + + value, dbkey, name, path + +
+
diff --git a/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.test b/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.test new file mode 100644 index 00000000000..75c253c2999 --- /dev/null +++ b/data_managers/data_manager_bwa_mem2_index_builder/tool_data_table_conf.xml.test @@ -0,0 +1,12 @@ + + + + value, dbkey, name, path + +
+ + + value, dbkey, name, path + +
+
From beafe2c099b6cbd7b6b9d5f25f7923862f4c5990 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Fri, 27 Sep 2024 11:34:50 -0400 Subject: [PATCH 2/2] 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