changeset 3:b31f1fcb203c draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_gatk_picard_index_builder commit 8652f36a3a3838dca989426961561e81432acf4f
author iuc
date Tue, 04 Apr 2017 18:08:38 -0400
parents 700f2df51eb0
children 6287d0ee459e
files data_manager/data_manager_gatk_picard_index_builder.py data_manager/data_manager_gatk_picard_index_builder.xml
diffstat 2 files changed, 51 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager/data_manager_gatk_picard_index_builder.py	Fri May 08 17:06:38 2015 -0400
+++ b/data_manager/data_manager_gatk_picard_index_builder.py	Tue Apr 04 18:08:38 2017 -0400
@@ -11,15 +11,15 @@
 import tempfile
 
 CHUNK_SIZE = 2**20
-
 DEFAULT_DATA_TABLE_NAME = "fasta_indexes"
 
+
 def get_id_name( params, dbkey, fasta_description=None):
-    #TODO: ensure sequence_id is unique and does not already appear in location file
+    # 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
@@ -27,6 +27,7 @@
             sequence_name = dbkey
     return sequence_id, sequence_name
 
+
 def build_picard_index( data_manager_dict, fasta_filename, target_directory, dbkey, sequence_id, sequence_name, jar, data_table_name=DEFAULT_DATA_TABLE_NAME ):
     fasta_base_name = os.path.split( fasta_filename )[-1]
     gatk_sorted_fasta_filename = os.path.join( target_directory, fasta_base_name )
@@ -41,8 +42,9 @@
     data_table_entry = dict( value=sequence_id, dbkey=dbkey, name=sequence_name, path=fasta_base_name )
     _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry )
 
+
 def _run_command( command, target_directory ):
-    tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-gatk_picard_index_builder-stderr" )
+    tmp_stderr = tempfile.NamedTemporaryFile( prefix="tmp-data-manager-gatk_picard_index_builder-stderr" )
     proc = subprocess.Popen( args=command, shell=False, cwd=target_directory, stderr=tmp_stderr.fileno() )
     return_code = proc.wait()
     if return_code:
@@ -57,12 +59,14 @@
         sys.exit( return_code )
     tmp_stderr.close()
 
+
 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 _move_and_index_fasta_for_sorting( fasta_filename ):
     unsorted_filename = tempfile.NamedTemporaryFile().name
     shutil.move( fasta_filename, unsorted_filename )
@@ -77,13 +81,14 @@
             line = line.split( None, 1 )[0][1:]
             fasta_offsets[ line ] = offset
     unsorted_fh.close()
-    current_order = map( lambda x: x[1], sorted( map( lambda x: ( x[1], x[0] ), fasta_offsets.items() ) ) )
+    current_order = [x[1] for x in sorted( ( x[1], x[0] ) for x in fasta_offsets.items() )]
     return ( unsorted_filename, fasta_offsets, current_order )
 
+
 def _write_sorted_fasta( sorted_names, fasta_offsets, sorted_fasta_filename, unsorted_fasta_filename ):
     unsorted_fh = open( unsorted_fasta_filename )
     sorted_fh = open( sorted_fasta_filename, 'wb+' )
-    
+
     for name in sorted_names:
         offset = fasta_offsets[ name ]
         unsorted_fh.seek( offset )
@@ -96,11 +101,12 @@
     unsorted_fh.close()
     sorted_fh.close()
 
+
 def _int_to_roman( integer ):
     if not isinstance( integer, int ):
-        raise TypeError, "expected integer, got %s" % type( integer )
+        raise TypeError("expected integer, got %s" % type( integer ))
     if not 0 < integer < 4000:
-        raise ValueError, "Argument must be between 1 and 3999, got %s" % str( integer )   
+        raise ValueError("Argument must be between 1 and 3999, got %s" % str( integer ))
     ints = ( 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 )
     nums = ( 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' )
     result = ""
@@ -110,39 +116,40 @@
         integer -= ints[ i ] * count
     return result
 
+
 def _sort_fasta_gatk( fasta_filename ):
     ( unsorted_filename, fasta_offsets, current_order ) = _move_and_index_fasta_for_sorting( fasta_filename )
-    sorted_names = map( str, range( 1, 100 ) ) + map( _int_to_roman, range( 1, 100 ) ) + [ 'X', 'Y', 'M' ]
-    #detect if we have chrN, or just N
+    sorted_names = list(map( str, range( 1, 100 ) )) + list(map( _int_to_roman, range( 1, 100 ) )) + [ 'X', 'Y', 'M' ]
+    # detect if we have chrN, or just N
     has_chr = False
     for chrom in sorted_names:
         if "chr%s" % chrom in current_order:
             has_chr = True
             break
-    
+
     if has_chr:
-        sorted_names = map( lambda x: "chr%s" % x, sorted_names)
+        sorted_names = ["chr%s" % x for x in sorted_names]
     else:
         sorted_names.insert( 0, "MT" )
-    sorted_names.extend( map( lambda x: "%s_random" % x, sorted_names ) )
-    
+    sorted_names.extend( "%s_random" % x for x in sorted_names )
+
     existing_sorted_names = []
     for name in sorted_names:
         # Append each chromosome only once.
         if name in current_order and name not in existing_sorted_names:
             existing_sorted_names.append( name )
     for name in current_order:
-        #TODO: confirm that non-canonical names do not need to be sorted specially
+        # TODO: confirm that non-canonical names do not need to be sorted specially
         if name not in existing_sorted_names:
             existing_sorted_names.append( name )
-    
+
     if existing_sorted_names == current_order:
         shutil.move( unsorted_filename, fasta_filename )
     else:
         _write_sorted_fasta( existing_sorted_names, fasta_offsets, fasta_filename, unsorted_filename )
 
+
 def main():
-    #Parse Command Line
     parser = optparse.OptionParser()
     parser.add_option( '-f', '--fasta_filename', dest='fasta_filename', action='store', type="string", default=None, help='fasta_filename' )
     parser.add_option( '-d', '--fasta_dbkey', dest='fasta_dbkey', action='store', type="string", default=None, help='fasta_dbkey' )
@@ -150,30 +157,32 @@
     parser.add_option( '-n', '--data_table_name', dest='data_table_name', action='store', type="string", default=None, help='data_table_name' )
     parser.add_option( '-j', '--jar', dest='jar', action='store', type="string", default=None, help='GATK .jar file' )
     (options, args) = parser.parse_args()
-    
+
     filename = args[0]
-    
+
     params = json.loads( open( filename ).read() )
     target_directory = params[ 'output_data' ][0]['extra_files_path']
     os.mkdir( target_directory )
     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_picard_index( data_manager_dict, 
-                        options.fasta_filename, 
-                        target_directory, 
-                        options.fasta_dbkey, 
-                        sequence_id, 
-                        sequence_name, 
-                        options.jar, 
+
+    # build the index
+    build_picard_index( data_manager_dict,
+                        options.fasta_filename,
+                        target_directory,
+                        options.fasta_dbkey,
+                        sequence_id,
+                        sequence_name,
+                        options.jar,
                         data_table_name=options.data_table_name or DEFAULT_DATA_TABLE_NAME )
-    
-    #save info to json file
+
+    # save info to json file
     open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )
-        
-if __name__ == "__main__": main()
+
+
+if __name__ == "__main__":
+    main()
--- a/data_manager/data_manager_gatk_picard_index_builder.xml	Fri May 08 17:06:38 2015 -0400
+++ b/data_manager/data_manager_gatk_picard_index_builder.xml	Tue Apr 04 18:08:38 2017 -0400
@@ -4,30 +4,28 @@
         <requirement type="package" version="0.1.18">samtools</requirement>
         <requirement type="package" version="1.56.0">picard</requirement>
     </requirements>
-    <command interpreter="python">
-        data_manager_gatk_picard_index_builder.py "${out_file}"
+    <command detect_errors="exit_code">
+        python '$__tool_directory__/data_manager_gatk_picard_index_builder.py' '${out_file}'
             --jar "\$JAVA_JAR_PATH/CreateSequenceDictionary.jar"
-            --fasta_filename "${all_fasta_source.fields.path}"
-            --fasta_dbkey "${all_fasta_source.fields.dbkey}"
-            --fasta_description "${all_fasta_source.fields.name}"
-            --data_table_name "gatk_picard_indexes"
+            --fasta_filename '${all_fasta_source.fields.path}'
+            --fasta_dbkey '${all_fasta_source.fields.dbkey}'
+            --fasta_description '${all_fasta_source.fields.name}'
+            --data_table_name gatk_picard_indexes
     </command>
     <inputs>
         <param name="all_fasta_source" type="select" label="Source FASTA Sequence">
             <options from_data_table="all_fasta"/>
         </param>
-        <param type="text" name="sequence_name" value="" label="Name of sequence" />
-        <param type="text" name="sequence_id" value="" label="ID for sequence" />
+        <param name="sequence_name" type="text" value="" label="Name of sequence" />
+        <param name="sequence_id" type="text" value="" label="ID for sequence" />
     </inputs>
     <outputs>
         <data name="out_file" format="data_manager_json"/>
     </outputs>
 
     <help>
-
 .. class:: infomark
 
 **Notice:** If you leave name, description, or id blank, it will be generated automatically. 
-
     </help>
 </tool>