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