# HG changeset patch # User Dave Bouvier # Date 1386784472 18000 # Node ID 93f2e3337a33d8f8829752985581d592be8dcc2b # Parent 30fdbaccb96bedd8ff6a2126569d4169d889d730 Update sam_to_bam to use the fasta_indexes data table. diff -r 30fdbaccb96b -r 93f2e3337a33 sam_to_bam.py --- a/sam_to_bam.py Mon Aug 26 14:22:00 2013 -0400 +++ b/sam_to_bam.py Wed Dec 11 12:54:32 2013 -0500 @@ -3,43 +3,25 @@ Converts SAM data to sorted BAM data. usage: sam_to_bam.py [options] --input1: SAM file to be converted - --dbkey: dbkey value + --index: path of the indexed reference genome --ref_file: Reference file if choosing from history --output1: output dataset in bam format - --index_dir: GALAXY_DATA_INDEX_DIR """ -import optparse, os, sys, subprocess, tempfile, shutil, gzip -from galaxy import eggs -import pkg_resources; pkg_resources.require( "bx-python" ) -from bx.cookbook import doc_optparse -from galaxy import util +import optparse, os, sys, subprocess, tempfile, shutil def stop_err( msg ): sys.stderr.write( '%s\n' % msg ) sys.exit() -def check_seq_file( dbkey, cached_seqs_pointer_file ): - seq_path = '' - for line in open( cached_seqs_pointer_file ): - line = line.rstrip( '\r\n' ) - if line and not line.startswith( '#' ) and line.startswith( 'index' ): - fields = line.split( '\t' ) - if len( fields ) < 3: - continue - if fields[1] == dbkey: - seq_path = fields[2].strip() - break - return seq_path - def __main__(): #Parse Command Line parser = optparse.OptionParser() parser.add_option( '', '--input1', dest='input1', help='The input SAM dataset' ) - parser.add_option( '', '--dbkey', dest='dbkey', help='The build of the reference dataset' ) + + parser.add_option( '', '--index', dest='index', help='The path of the indexed reference genome' ) parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) parser.add_option( '', '--output1', dest='output1', help='The output BAM dataset' ) - parser.add_option( '', '--index_dir', dest='index_dir', help='GALAXY_DATA_INDEX_DIR' ) ( options, args ) = parser.parse_args() # output version # of tool @@ -61,24 +43,18 @@ except: sys.stdout.write( 'Could not determine Samtools version\n' ) - cached_seqs_pointer_file = '%s/sam_fa_indices.loc' % options.index_dir - if not os.path.exists( cached_seqs_pointer_file ): - stop_err( 'The required file (%s) does not exist.' % cached_seqs_pointer_file ) - # If found for the dbkey, seq_path will look something like /galaxy/data/equCab2/sam_index/equCab2.fa, - # and the equCab2.fa file will contain fasta sequences. - seq_path = check_seq_file( options.dbkey, cached_seqs_pointer_file ) tmp_dir = tempfile.mkdtemp( dir='.' ) if not options.ref_file or options.ref_file == 'None': # We're using locally cached reference sequences( e.g., /galaxy/data/equCab2/sam_index/equCab2.fa ). # The indexes for /galaxy/data/equCab2/sam_index/equCab2.fa will be contained in # a file named /galaxy/data/equCab2/sam_index/equCab2.fa.fai fai_index_file_base = seq_path - fai_index_file_path = '%s.fai' % seq_path + fai_index_file_path = '%s.fai' % options.index if not os.path.exists( fai_index_file_path ): #clean up temp files if os.path.exists( tmp_dir ): shutil.rmtree( tmp_dir ) - stop_err( 'No sequences are available for build (%s), request them by reporting this error.' % options.dbkey ) + stop_err( 'Indexed genome %s not present, request it by reporting this error.' % options.index ) else: try: # Create indexes for history reference ( e.g., ~/database/files/000/dataset_1.dat ) using samtools faidx, which will: diff -r 30fdbaccb96b -r 93f2e3337a33 sam_to_bam.xml --- a/sam_to_bam.xml Mon Aug 26 14:22:00 2013 -0400 +++ b/sam_to_bam.xml Wed Dec 11 12:54:32 2013 -0500 @@ -1,4 +1,4 @@ - + converts SAM format to BAM format samtools @@ -7,13 +7,11 @@ sam_to_bam.py --input1=$source.input1 #if $source.index_source == "history": - --dbkey=${ref_file.metadata.dbkey} --ref_file=$source.ref_file #else - --dbkey=${input1.metadata.dbkey} + --index=${source.index.fields.path} #end if --output1=$output1 - --index_dir=${GALAXY_DATA_INDEX_DIR} @@ -22,13 +20,19 @@ - - - + + + + + + + + + - + @@ -76,6 +80,7 @@ --> + diff -r 30fdbaccb96b -r 93f2e3337a33 tool-data/fasta_indexes.loc.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool-data/fasta_indexes.loc.sample Wed Dec 11 12:54:32 2013 -0500 @@ -0,0 +1,29 @@ +#This is a sample file distributed with Galaxy that enables tools +#to use a directory of Samtools indexed sequences data files. You will need +#to create these data files and then create a sam_fa_new_indices.loc file +#similar to this one (store it in this directory) that points to +#the directories in which those files are stored. The sam_fa_new_indices.loc +#file has this format (white space characters are TAB characters): +# +# +# +#So, for example, if you had hg19 Canonical indexed stored in +# +# /depot/data2/galaxy/hg19/sam/, +# +#then the sam_fa_new_indices.loc entry would look like this: +# +#hg19canon hg19 Human (Homo sapiens): hg19 Canonical /depot/data2/galaxy/hg19/sam/hg19canon.fa +# +#and your /depot/data2/galaxy/hg19/sam/ directory +#would contain hg19canon.fa and hg19canon.fa.fai files. +# +#Your sam_fa_new_indices.loc file should include an entry per line for +#each index set you have stored. The file in the path does actually +#exist, but it should never be directly used. Instead, the name serves +#as a prefix for the index file. For example: +# +#hg18canon hg18 Human (Homo sapiens): hg18 Canonical /depot/data2/galaxy/hg18/sam/hg18canon.fa +#hg18full hg18 Human (Homo sapiens): hg18 Full /depot/data2/galaxy/hg18/sam/hg18full.fa +#hg19canon hg19 Human (Homo sapiens): hg19 Canonical /depot/data2/galaxy/hg19/sam/hg19canon.fa +#hg19full hg19 Human (Homo sapiens): hg19 Full /depot/data2/galaxy/hg19/sam/hg19full.fa diff -r 30fdbaccb96b -r 93f2e3337a33 tool-data/sam_fa_indices.loc.sample --- a/tool-data/sam_fa_indices.loc.sample Mon Aug 26 14:22:00 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#This is a sample file distributed with Galaxy that enables tools -#to use a directory of Samtools indexed sequences data files. You will need -#to create these data files and then create a sam_fa_indices.loc file -#similar to this one (store it in this directory) that points to -#the directories in which those files are stored. The sam_fa_indices.loc -#file has this format (white space characters are TAB characters): -# -#index -# -#So, for example, if you had hg18 indexed stored in -#/depot/data2/galaxy/sam/, -#then the sam_fa_indices.loc entry would look like this: -# -#index hg18 /depot/data2/galaxy/sam/hg18.fa -# -#and your /depot/data2/galaxy/sam/ directory -#would contain hg18.fa and hg18.fa.fai files: -# -#-rw-r--r-- 1 james universe 830134 2005-09-13 10:12 hg18.fa -#-rw-r--r-- 1 james universe 527388 2005-09-13 10:12 hg18.fa.fai -# -#Your sam_fa_indices.loc file should include an entry per line for -#each index set you have stored. The file in the path does actually -#exist, but it should never be directly used. Instead, the name serves -#as a prefix for the index file. For example: -# -#index hg18 /depot/data2/galaxy/sam/hg18.fa -#index hg19 /depot/data2/galaxy/sam/hg19.fa diff -r 30fdbaccb96b -r 93f2e3337a33 tool-data/tool_data_table_conf.xml.sample --- a/tool-data/tool_data_table_conf.xml.sample Mon Aug 26 14:22:00 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - line_type, value, path - -
-
\ No newline at end of file diff -r 30fdbaccb96b -r 93f2e3337a33 tool_data_table_conf.xml.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_data_table_conf.xml.sample Wed Dec 11 12:54:32 2013 -0500 @@ -0,0 +1,7 @@ + + + + value, dbkey, name, path + +
+