Mercurial > repos > simonl > agile_wrapper
comparison Users/oconnorlab/Desktop/agile/agile_wrapper.py @ 0:d6a426afaa46 default tip
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
| author | simonl |
|---|---|
| date | Tue, 07 Jun 2011 16:22:51 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d6a426afaa46 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import os, sys, tempfile | |
| 4 | |
| 5 assert sys.version_info[:2] >= (2.4) | |
| 6 | |
| 7 def stop_err( msg ): | |
| 8 sys.stderr.write( "%s\n" % msg ) | |
| 9 sys.exit() | |
| 10 | |
| 11 def check_nib_file( dbkey, GALAXY_DATA_INDEX_DIR ): | |
| 12 nib_file = "%s/alignseq.loc" % GALAXY_DATA_INDEX_DIR | |
| 13 nib_path = '' | |
| 14 nibs = {} | |
| 15 for i, line in enumerate( file( nib_file ) ): | |
| 16 line = line.rstrip( '\r\n' ) | |
| 17 if line and not line.startswith( "#" ): | |
| 18 fields = line.split( '\t' ) | |
| 19 if len( fields ) < 3: | |
| 20 continue | |
| 21 if fields[0] == 'seq': | |
| 22 nibs[( fields[1] )] = fields[2] | |
| 23 if nibs.has_key( dbkey ): | |
| 24 nib_path = nibs[( dbkey )] | |
| 25 return nib_path | |
| 26 | |
| 27 def check_twobit_file( dbkey, GALAXY_DATA_INDEX_DIR ): | |
| 28 twobit_file = "%s/twobit.loc" % GALAXY_DATA_INDEX_DIR | |
| 29 twobit_path = '' | |
| 30 twobits = {} | |
| 31 for i, line in enumerate( file( twobit_file ) ): | |
| 32 line = line.rstrip( '\r\n' ) | |
| 33 if line and not line.startswith( "#" ): | |
| 34 fields = line.split( '\t' ) | |
| 35 if len( fields ) < 2: | |
| 36 continue | |
| 37 twobits[( fields[0] )] = fields[1] | |
| 38 if twobits.has_key( dbkey ): | |
| 39 twobit_path = twobits[( dbkey )] | |
| 40 return twobit_path | |
| 41 | |
| 42 def __main__(): | |
| 43 # I/O | |
| 44 source_format = sys.argv[1] # 0: dbkey; 1: upload file | |
| 45 target_file = sys.argv[2] | |
| 46 query_file = sys.argv[3] | |
| 47 output_file = sys.argv[4] | |
| 48 max_sims = sys.argv[5] | |
| 49 tile_size = sys.argv[6] | |
| 50 max_freq = sys.argv[7] | |
| 51 out_type = sys.argv[8] | |
| 52 all_match = sys.argv[9] | |
| 53 | |
| 54 GALAXY_DATA_INDEX_DIR = sys.argv[10] | |
| 55 | |
| 56 all_files = [] | |
| 57 if source_format == '0': | |
| 58 # check target genome | |
| 59 dbkey = target_file | |
| 60 nib_path = check_nib_file( dbkey, GALAXY_DATA_INDEX_DIR ) | |
| 61 twobit_path = check_twobit_file( dbkey, GALAXY_DATA_INDEX_DIR ) | |
| 62 if not os.path.exists( nib_path ) and not os.path.exists( twobit_path ): | |
| 63 stop_err("No sequences are available for %s, request them by reporting this error." % dbkey) | |
| 64 | |
| 65 # check the query file, see whether all of them are legitimate sequence | |
| 66 if nib_path and os.path.isdir( nib_path ): | |
| 67 compress_files = os.listdir(nib_path) | |
| 68 target_path = nib_path | |
| 69 elif twobit_path: | |
| 70 compress_files = [twobit_path] | |
| 71 target_path = "" | |
| 72 else: | |
| 73 stop_err("Requested genome build has no available sequence.") | |
| 74 | |
| 75 for file in compress_files: | |
| 76 file = "%s/%s" % ( target_path, file ) | |
| 77 file = os.path.normpath(file) | |
| 78 all_files.append(file) | |
| 79 else: | |
| 80 all_files = [target_file] | |
| 81 | |
| 82 for detail_file_path in all_files: | |
| 83 output_tempfile = tempfile.NamedTemporaryFile().name | |
| 84 if all_match == "true": | |
| 85 command = "agile %s %s -maxSIMs=%s -tileSize=%s -maxFreq=%s -out=%s -all %s 2>&1" % ( detail_file_path, query_file, max_sims, tile_size, max_freq, out_type, output_tempfile ) | |
| 86 else: | |
| 87 command = "agile %s %s -maxSIMs=%s -tileSize=%s -maxFreq=%s -out=%s %s 2>&1" % ( detail_file_path, query_file, max_sims, tile_size, max_freq, out_type, output_tempfile ) | |
| 88 | |
| 89 os.system( command ) | |
| 90 os.system( 'cat %s >> %s' % ( output_tempfile, output_file ) ) | |
| 91 os.remove( output_tempfile ) | |
| 92 | |
| 93 if __name__ == '__main__': __main__() |
