Mercurial > repos > messersc > jamm
comparison jammwrapper.py @ 1:243f75d0ed6e draft default tip
Uploaded.
Includes new release 1.0.7 with fixed optional controls.
author | messersc |
---|---|
date | Thu, 19 Feb 2015 05:39:45 -0500 |
parents | d42f4d78c85e |
children |
comparison
equal
deleted
inserted
replaced
0:d42f4d78c85e | 1:243f75d0ed6e |
---|---|
4 | 4 |
5 # This wrapper does the following things: | 5 # This wrapper does the following things: |
6 # map the files (from Galaxy history) to a directory | 6 # map the files (from Galaxy history) to a directory |
7 # pass the parameters from the GUI to JAMM.sh | 7 # pass the parameters from the GUI to JAMM.sh |
8 # call JAMM.sh | 8 # call JAMM.sh |
9 # maybe map the resulting tabular files back to history items, the XML could take care of that if output is fixed | 9 # map the resulting tabular files back to history items |
10 | 10 |
11 #import optparse | 11 #import optparse |
12 import argparse, os, shutil, subprocess, sys, tempfile | 12 import argparse, os, shutil, subprocess, sys, tempfile |
13 import shlex | 13 import shlex |
14 # importing some of the modules used, especially for symlinking, dir manipulation and tool calling. | 14 # importing some of the modules used, especially for symlinking, dir manipulation and tool calling. |
20 | 20 |
21 def main(): | 21 def main(): |
22 | 22 |
23 #Read command line arguments | 23 #Read command line arguments |
24 parser = argparse.ArgumentParser() | 24 parser = argparse.ArgumentParser() |
25 parser.add_argument('-i', dest = 'input', nargs='+') | 25 parser.add_argument('-i', dest = 'input', nargs='+') # + allows for 1 or more arguments |
26 # parser.add_argument('-c', dest = 'control', nargs='*', default=None) # allow for not supplying -c | |
27 parser.add_argument('-c', dest = 'control', action='append') # allow for not supplying -c | |
26 parser.add_argument('-g', dest = 'gsize') | 28 parser.add_argument('-g', dest = 'gsize') |
27 parser.add_argument('-z', dest = 'peakfile') | 29 parser.add_argument('-o', dest = 'peakfile') |
30 parser.add_argument('-of', dest = 'filteredpeakfile') | |
28 | 31 |
29 parser.add_argument('-m', dest = 'mode') | 32 parser.add_argument('-m', dest = 'mode') |
30 parser.add_argument('-r', dest = 'resolution') | 33 parser.add_argument('-r', dest = 'resolution') |
31 parser.add_argument('-p', dest = 'processes') | 34 parser.add_argument('-p', dest = 'processes') |
32 #parser.add_argument('-b', dest = 'binSize') | 35 parser.add_argument('-t', dest = 'type') |
36 parser.add_argument('-f', dest = 'fraglen') | |
37 parser.add_argument('-b', dest = 'binsize') | |
33 | 38 |
34 args = parser.parse_args() | 39 args = parser.parse_args() |
35 | 40 |
36 print "\n" | 41 print "################################################" |
37 print "Wrapper debugging" | 42 print "Wrapper debugging" |
38 print "Files to be used:" | 43 print "################################################" |
44 print "Sample files:" | |
39 for j in args.input: | 45 for j in args.input: |
40 print j | 46 print j |
47 if args.control is not None: | |
48 print "Control files:" | |
49 for j in args.control: | |
50 print j | |
41 | 51 |
42 print "output file:" | 52 print "output files:" |
43 print args.peakfile | 53 print args.peakfile |
54 print args.filteredpeakfile | |
55 print "current working dir:" | |
56 print os.getcwd() | |
57 print "dir with jammwrapper in it:" | |
58 path = os.path.abspath(os.path.dirname(sys.argv[0])) | |
59 print path | |
44 | 60 |
45 # depracted, can still be found in may of the example wrappers | 61 # optparse was depracted, can still be found in may of the example wrappers |
46 #parser = optparse.OptionParser() | 62 #parser = optparse.OptionParser() |
47 #parser.add_option( '-i', dest='input', help='input bed files' ) | 63 #parser.add_option( '-i', dest='input', help='input bed files' ) |
48 #parser.add_option( '-c', dest='csize', help='chr sizes' ) | 64 #parser.add_option( '-c', dest='csize', help='chr sizes' ) |
49 #(options, args) = parser.parse_args() | 65 #(options, args) = parser.parse_args() |
50 | 66 |
51 # create temp dir | 67 # create temp dir |
52 tmp_dir = tempfile.mkdtemp() | 68 tmp_dir = tempfile.mkdtemp() |
53 os.chdir(tmp_dir) | 69 os.mkdir(tmp_dir + "/sample") |
54 # symlink creation | 70 # symlink creation |
55 for file in args.input: | 71 for file in args.input: |
56 filen = tmp_dir + "/" + os.path.basename(os.path.splitext(file)[0])+".bed" | 72 filen = tmp_dir + "/sample/" + os.path.basename(os.path.splitext(file)[0])+".bed" |
73 print "input files mapped: %s" % filen | |
57 os.symlink(file, filen) | 74 os.symlink(file, filen) |
58 | 75 |
59 # in case temp files should have random names | 76 # Here comes some unnecessary repetition |
60 # ref_file = tempfile.NamedTemporaryFile( dir=tmp_dir ) | 77 # if control files are supplied, we make another tmp subdir and put those files there. |
61 # ref_file_name = ref_file.name | 78 # JAMM.sh is then called with one additional switch -c |
62 # ref_file.close() | 79 if args.control is not None: |
63 # os.symlink( file, ref_file_name ) | 80 # symlink creation |
64 | 81 os.mkdir(tmp_dir + "/control") |
65 command = ( "/home/cmesser/galaxy/tools/jamm/JAMM.sh -s %s -g %s -o results -m %s -r %s -p %s" | 82 for file in args.control: |
66 % ( tmp_dir, args.gsize, args.mode, args.resolution, args.processes ) ) | 83 filen = tmp_dir + "/control/" + os.path.basename(os.path.splitext(file)[0])+".bed" |
84 print "input files mapped: %s" % filen | |
85 os.symlink(file, filen) | |
86 command = ( "bash %s/JAMM.sh -s %s/sample -c %s/control -g %s -o results -m %s -r %s -p %s -t %s -f %s -b %s" | |
87 % ( path, tmp_dir, tmp_dir, args.gsize, args.mode, args.resolution, args.processes, \ | |
88 args.type, args.fraglen, args.binsize ) ) | |
89 else: | |
90 command = ( "bash %s/JAMM.sh -s %s/sample -g %s -o results -m %s -r %s -p %s -t %s -f %s -b %s" | |
91 % ( path, tmp_dir, args.gsize, args.mode, args.resolution, args.processes, \ | |
92 args.type, args.fraglen, args.binsize ) ) | |
93 | |
94 | |
95 print "Command called by bash:" | |
67 print command | 96 print command |
68 # depending on how your programm is called, it may be necessary to use shlex.split on the command string before | 97 # depending on how your programm is called, it may be necessary to use shlex.split on the command string before |
69 # in this case, this was actually harmful. idk why | 98 # in this case, this was actually harmful. idk why |
70 # command = shlex.split(command) | 99 # command = shlex.split(command) |
71 # Please read the docs for subprocess.Popen. You can't just pass as string as variables need to be extended | 100 # Please read the docs for subprocess.Popen. You can't just pass as string as variables need to be extended |
73 # proc = subprocess.Popen( command, executable = '/bin/bash', shell=True ) | 102 # proc = subprocess.Popen( command, executable = '/bin/bash', shell=True ) |
74 proc = subprocess.Popen( command, shell=True) | 103 proc = subprocess.Popen( command, shell=True) |
75 returncode = proc.wait() | 104 returncode = proc.wait() |
76 | 105 |
77 #mv files to a place where galaxy wrapper can find them | 106 #mv files to a place where galaxy wrapper can find them |
78 mvcommand = "mv %s/results/peaks/all.peaks.narrowPeak %s" % ( tmp_dir, args.peakfile ) | 107 # mvcommand = "mv %s/results/peaks/all.peaks.narrowPeak %s" % ( tmp_dir, args.peakfile ) |
108 mvcommand = "mv results/peaks/all.peaks.narrowPeak %s" % args.peakfile | |
109 os.system(mvcommand) | |
110 mvcommand = "mv results/peaks/filtered.peaks.narrowPeak %s" % args.filteredpeakfile | |
79 os.system(mvcommand) | 111 os.system(mvcommand) |
80 | 112 |
81 # clean up temp dir | 113 # clean up temp dir |
82 if os.path.exists( tmp_dir ): | 114 if os.path.exists( tmp_dir ): |
83 shutil.rmtree( tmp_dir ) | 115 shutil.rmtree( tmp_dir ) |
84 | |
85 | 116 |
86 if __name__ == "__main__": | 117 if __name__ == "__main__": |
87 main() | 118 main() |
88 | 119 |