Mercurial > repos > cmonjeau > commet
comparison commet.py @ 3:d085f995d556
remove prepare_commet and change/add packages
author | cmonjeau |
---|---|
date | Thu, 10 Sep 2015 13:38:21 +0000 |
parents | a6beb4d4c417 |
children | a53ce9294c0a |
comparison
equal
deleted
inserted
replaced
2:1478d48df8c7 | 3:d085f995d556 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 import sys, tempfile, subprocess, glob | 2 import sys, tempfile, subprocess, glob |
3 import os, re, shutil, optparse | 3 import os, re, shutil, argparse |
4 import zipfile, tarfile, gzip | 4 import zipfile, tarfile, gzip |
5 from os.path import basename | 5 from os.path import basename |
6 | 6 |
7 """ | 7 """ |
8 WARNING : | 8 WARNING : |
11 | 11 |
12 commet is available after compiling sources : | 12 commet is available after compiling sources : |
13 | 13 |
14 http://github.com/pierrepeterlongo/commet | 14 http://github.com/pierrepeterlongo/commet |
15 | 15 |
16 or with the galaxy_commet package in the GenOuest toolshed (coming soon) | 16 or with the package_commet package in the GenOuest toolshed and the main toolshed |
17 | 17 |
18 NOTE : | 18 NOTE : |
19 | 19 |
20 please add the line #!/usr/bin/env python in top of the Commet.py file if you've a bash error. | 20 please add the line #!/usr/bin/env python in top of the Commet.py file if you've a bash error. |
21 | 21 |
23 """ | 23 """ |
24 | 24 |
25 def __main__(): | 25 def __main__(): |
26 | 26 |
27 # arguments recuperation | 27 # arguments recuperation |
28 parser = optparse.OptionParser() | 28 parser = argparse.ArgumentParser() |
29 parser.add_option("--input", dest="input") | |
30 parser.add_option("-k", dest="kmer") | |
31 parser.add_option("-t", dest="minsharedkmer") | |
32 parser.add_option("-l", dest="minlengthread") | |
33 parser.add_option("-n", dest="maxn") | |
34 parser.add_option("-e", dest="minshannonindex") | |
35 parser.add_option("-m", dest="maxreads") | |
36 | 29 |
37 parser.add_option("--output") | 30 parser.add_argument("--set", dest="set", action='append') |
38 parser.add_option("--output_vectors") | 31 parser.add_argument("-k", dest="kmer") |
39 parser.add_option("--output_dendro") | 32 parser.add_argument("-t", dest="minsharedkmer") |
40 parser.add_option("--output_logs") | 33 parser.add_argument("-l", dest="minlengthread") |
41 parser.add_option("--output_matrix") | 34 parser.add_argument("-n", dest="maxn") |
42 parser.add_option("--output_heatmap1") | 35 parser.add_argument("-e", dest="minshannonindex") |
43 parser.add_option("--output_heatmap2") | 36 parser.add_argument("-m", dest="maxreads") |
44 parser.add_option("--output_heatmap3") | |
45 | 37 |
46 (options, args) = parser.parse_args() | 38 parser.add_argument("--output") |
39 parser.add_argument("--output_vectors") | |
40 parser.add_argument("--output_dendro") | |
41 parser.add_argument("--output_matrix") | |
42 parser.add_argument("--output_heatmap1") | |
43 parser.add_argument("--output_heatmap2") | |
44 parser.add_argument("--output_heatmap3") | |
47 | 45 |
46 options = parser.parse_args() | |
48 | 47 |
49 # copy R script into the current dir | 48 # copy R script into the current dir |
50 shutil.copy(os.environ['RSCRIPTS']+"/heatmap.r", os.getcwd()) | 49 shutil.copy(os.environ['RSCRIPTS']+"/heatmap.r", os.getcwd()) |
51 shutil.copy(os.environ['RSCRIPTS']+"/dendro.R", os.getcwd()) | 50 shutil.copy(os.environ['RSCRIPTS']+"/dendro.R", os.getcwd()) |
52 | 51 |
53 # remove the first line of the input file | 52 # prepare input file |
54 commet_file = open(options.input, "r") | 53 commet_file=open('commet_config_file', 'w') |
55 commet_file_clean = open("commet_clean_file", "w") | 54 |
56 | 55 for set in options.set: |
57 # delete the first line | 56 clean_set=set.replace(',', ';').replace('::', ':') |
58 commet_file.readline() | 57 commet_file.write(clean_set+"\n") |
59 for line in commet_file: | 58 commet_file.close() |
60 commet_file_clean.write(line) | |
61 | |
62 # close files | |
63 commet_file.close() | |
64 commet_file_clean.close() | |
65 | 59 |
66 # edit the command line | 60 # edit the command line |
67 cmd_line=[] | 61 cmd_line=[] |
68 cmd_line.append("Commet.py") | 62 cmd_line.append("Commet.py") |
69 cmd_line.extend(["commet_clean_file","-b",os.environ['BINARIES'],"-k",options.kmer,"-t",options.minsharedkmer,"-l",options.minlengthread,"-e",options.minshannonindex]) | 63 cmd_line.extend(["commet_config_file","-b",os.environ['BINARIES'],"-k",options.kmer,"-t",options.minsharedkmer,"-l",options.minlengthread,"-e",options.minshannonindex]) |
70 | 64 |
71 # add options | 65 # add options |
72 if options.maxn: | 66 if options.maxn: |
73 | |
74 #cmd_line += ' -n '+options.maxn+' -m '+options.maxreads+' > '+options.output+' 2>>'+options.output | |
75 cmd_line.extend(["-n",options.maxn,"-m",options.maxreads]) | 67 cmd_line.extend(["-n",options.maxn,"-m",options.maxreads]) |
76 #else: | |
77 #cmd_line += ' > '+options.output+' 2>>'+options.output | |
78 | 68 |
79 # execute job | 69 # execute job |
80 p=subprocess.Popen(cmd_line, | 70 p=subprocess.call(cmd_line) |
81 stdout=subprocess.PIPE,stderr=subprocess.PIPE) | |
82 | 71 |
83 stdoutput, stderror = p.communicate() | 72 print "[COMMAND LINE]"+' '.join(cmd_line) |
84 | |
85 # log file | |
86 logfile=open(options.output, "w") | |
87 logfile.write("[COMMAND LINE]"+' '.join(cmd_line)+"\n\n") | |
88 logfile.write(str(stdoutput)) | |
89 logfile.write(str(stderror)) | |
90 logfile.close() | |
91 | 73 |
92 # copy .bv files inside a .bv archive | 74 # copy .bv files inside a .bv archive |
93 tmp_output_dir=os.getcwd()+"/output_commet/" | 75 tmp_output_dir=os.getcwd()+"/output_commet/" |
94 os.chdir(tmp_output_dir) | 76 os.chdir(tmp_output_dir) |
95 | 77 |
118 shutil.move(tmp_output_dir+'bv.zip.temp', options.output_vectors) | 100 shutil.move(tmp_output_dir+'bv.zip.temp', options.output_vectors) |
119 shutil.move(tmp_output_dir+'log.zip.temp', options.output_logs) | 101 shutil.move(tmp_output_dir+'log.zip.temp', options.output_logs) |
120 shutil.move(tmp_output_dir+'matrix.zip.temp', options.output_matrix) | 102 shutil.move(tmp_output_dir+'matrix.zip.temp', options.output_matrix) |
121 | 103 |
122 # outputs | 104 # outputs |
123 shutil.move(tmp_output_dir+'dendrogram_normalized.png', options.output_dendro) | 105 try: |
124 shutil.move(tmp_output_dir+'heatmap_normalized.png', options.output_heatmap1) | 106 shutil.move(tmp_output_dir+'dendrogram_normalized.png', options.output_dendro) |
125 shutil.move(tmp_output_dir+'heatmap_percentage.png', options.output_heatmap2) | 107 shutil.move(tmp_output_dir+'heatmap_percentage.png', options.output_heatmap2) |
126 shutil.move(tmp_output_dir+'heatmap_plain.png', options.output_heatmap3) | 108 shutil.move(tmp_output_dir+'heatmap_normalized.png', options.output_heatmap1) |
109 shutil.move(tmp_output_dir+'heatmap_plain.png', options.output_heatmap3) | |
110 except: | |
111 print "There is a problem with gplots execution" | |
127 | 112 |
128 if __name__ == "__main__": __main__() | 113 if __name__ == "__main__": __main__() |
129 | 114 |