Mercurial > repos > iuc > bamtools_split_ref
diff bamtools_split_ref.xml @ 1:9dbf707bebb0 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tool_collections/bamtools/bamtools_split_ref commit a14db40361bcb2ee608bccd9222e1654aaea3324-dirty
author | iuc |
---|---|
date | Wed, 11 Jan 2023 12:03:53 +0000 |
parents | 09470ab960f1 |
children | 9b520009db81 |
line wrap: on
line diff
--- a/bamtools_split_ref.xml Sat Nov 27 10:03:33 2021 +0000 +++ b/bamtools_split_ref.xml Wed Jan 11 12:03:53 2023 +0000 @@ -1,32 +1,50 @@ -<tool id="bamtools_split_ref" name="Split BAM by Reference" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@"> +<tool id="bamtools_split_ref" name="Split BAM by Reference" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.09"> <description>into dataset list collection</description> <macros> <import>macros.xml</import> </macros> - <expand macro="requirements" /> - <command> - <![CDATA[ - ln -s '${input_bam}' 'localbam.bam' && - ln -s '${input_bam.metadata.bam_index}' 'localbam.bam.bai' && - bamtools split -reference - -in localbam.bam - -stub split_bam - ## Preserve order from metadata in the output collection - #import re - #set $name = $re.sub('\W','_',$re.sub('\.bam$','',$input_bam.name)) - #if str($refs) != 'None': - #set $ref_list = ' '.join(str($refs).split(",")) - #else - #set $ref_list = ' '.join([$re.sub('^.*__sq__(.+)__sq__.*$','\\1',n) if n.find('__sq__') >= 0 else n for n in str($input_bam.metadata.reference_names).split(',')]) - #end if - && mkdir -p outputs - && (export I=0; - for i in $ref_list; - do I=\$((++I)); SN=`printf "split_bam.REF_%s.bam" "\$i"`; - if [ -e \$SN ]; then FN=`printf "outputs/split_bam%05d%s.%s.bam" \$((I)) '$name' "\$i"`; mv \$SN \$FN; fi; - done) - ]]> - </command> + <expand macro="requirements"> + <requirement type="package" version="1.16.1">samtools</requirement> + </expand> + <command><![CDATA[ + ln -s '${input_bam}' localbam.bam && + ln -s '${input_bam.metadata.bam_index}' 'localbam.bam.bai' && + samtools view -bH localbam.bam --no-PG -o header.bam && + bamtools split -reference + -in localbam.bam + -stub split_bam + && (IFS=','; + for i in \$REFS_FROM_BAM_METADATA; + do FN=`printf "split_bam.REF_%s.bam" "\$i"`; + if [ ! -f \$FN ]; then cp header.bam "\$FN"; fi; + done) + && cp '$c1' galaxy.json + ]]></command> + <environment_variables> + <environment_variable name="REFS_FROM_BAM_METADATA">#import re +## need to extract ref names from Galaxy's safe string representation +#set $ref_list = [$re.sub('^.*__sq__(.+)__sq__.*$','\\1',n) if n.find('__sq__') >= 0 else n for n in str($input_bam.metadata.reference_names).split(',')] +#if str($refs) != 'None' +#set $refs_selected = set(str($refs).split(",")) +## sort the selected refs by their order in the bam metadata +#echo ','.join([r for r in $ref_list if r in refs_selected]) +#else +#echo ','.join($ref_list) +#end if +</environment_variable> + </environment_variables> + <configfiles> + <configfile name="c1">#import re +## need to extract ref names from Galaxy's safe string representation +#set $ref_list = [$re.sub('^.*__sq__(.+)__sq__.*$','\\1',n) if n.find('__sq__') >= 0 else n for n in str($input_bam.metadata.reference_names).split(',')] +#if str($refs) != 'None' +#set $refs_selected = set(str($refs).split(",")) +#set $ref_list = [r for r in $ref_list if r in refs_selected] +#end if +#set $elems = [{'name': '%s: %s' % ($input_bam.name, r), 'filename': 'split_bam.REF_%s.bam' % r, 'dbkey': str($input_bam.dbkey)} for r in $ref_list] +#import json +#echo json.dumps({'output_bams': {'elements': $elems}})</configfile> + </configfiles> <inputs> <param name="input_bam" type="data" format="bam" label="BAM dataset to split by reference"/> <param name="refs" type="select" optional="True" multiple="True" label="Select references (chromosomes and contigs) you would like to restrict bam to" > @@ -39,40 +57,44 @@ </param> </inputs> <outputs> - <collection name="output_bams" type="list" label="${input_bam.name} Split List"> - <discover_datasets pattern="split_bam\d*(?P<designation>.+)\.bam" ext="bam" directory="outputs" visible="false"/> + <collection name="output_bams" type="list"> + <discover_datasets from_provided_metadata="true" ext="bam" visible="false" /> </collection> </outputs> <tests> <test> - <param name="input_bam" ftype="bam" value="bamtools-input2.bam"/> - <output_collection name="output_bams" type="list"> - <element name="bamtools_input2.chr1" file="bamtools_input2.chr1" compare="sim_size" delta="500" /> + <param name="input_bam" ftype="bam" value="bamtools-input2.bam" /> + <output_collection name="output_bams" type="list" count="25"> + <element name="bamtools-input2.bam: chrM" file="bamtools_input2.header.bam" ftype="bam" /> + <element name="bamtools-input2.bam: chr1" file="bamtools_input2.chr1" ftype="bam" /> + <element name="bamtools-input2.bam: chr21" file="bamtools_input2.chr21.bam" ftype="bam" /> + </output_collection> + </test> + <test> + <param name="input_bam" ftype="bam" value="bamtools-input2.bam" /> + <param name="refs" value="chrM,chr1,chr21" /> + <output_collection name="output_bams" type="list" count="3"> + <element name="bamtools-input2.bam: chrM" file="bamtools_input2.header.bam" ftype="bam" /> + <element name="bamtools-input2.bam: chr1" file="bamtools_input2.chr1" ftype="bam" /> + <element name="bamtools-input2.bam: chr21" file="bamtools_input2.chr21.bam" ftype="bam" /> </output_collection> </test> </tests> <help> **What is does** -BAMTools split is a utility for splitting BAM files. It is based on BAMtools suite of tools by Derek Barnett (https://github.com/pezmaster31/bamtools). - ------ - -.. class:: warningmark - -**DANGER: Multiple Outputs** - -As described below, splitting a BAM dataset(s) on reference name or a tag value can produce very large numbers of outputs. Read below and know what you are doing. +BAMTools split is a utility for splitting BAM files. It is based on the BAMtools suite of tools by Derek Barnett (https://github.com/pezmaster31/bamtools). ----- **How it works** -Split alignments by reference name into a dataset list collection. The collection will be in the same order as the input BAM references. +Split alignments by reference name into a dataset list collection. The collection will be in the same order as the input BAM references and will consist of as many elements as there are references selected or listed in the input BAM header. -In cases of unfinished genomes with very large number of reference sequences (scaffolds) -it can generate thousands (if not millions) of output datasets. +.. class:: warningmark + In cases of unfinished genomes with very large number of reference sequences (scaffolds) + this could generate thousands (if not millions) of output datasets. -----