6
|
1 #! /usr/bin/env python
|
|
2 from optparse import OptionParser
|
|
3 import tarfile
|
|
4 import os
|
|
5 import re
|
|
6 import shutil
|
|
7 import subprocess
|
|
8
|
|
9 SMART_PATH = "%sSMART" % os.environ["REPET_PATH"]
|
|
10
|
|
11 def toTar(tarFileName, directory):
|
|
12 fileName = os.path.splitext(tarFileName)[0]
|
|
13 fileNameBaseName = os.path.basename(fileName)
|
|
14 tfile = tarfile.open(fileName + ".tmp.tar", "w")
|
|
15 list = os.listdir(directory)
|
|
16 for file in list:
|
|
17 if re.search(str(fileNameBaseName), file):
|
|
18 tfile.add(file)
|
|
19 os.system("mv %s %s" % (fileName + ".tmp.tar", options.outTarFileName))
|
|
20 tfile.close()
|
|
21
|
|
22
|
|
23 if __name__ == "__main__":
|
|
24
|
|
25 magnifyingFactor = 1000
|
|
26
|
|
27 # parse command line
|
|
28 description = "Plot the repartition of different data on a whole genome. (This tool uses 1 input file only, the different values being stored in the tags. See documentation to know more about it.) [Category: Visualization]"
|
|
29
|
|
30
|
|
31 parser = OptionParser(description = description)
|
|
32 parser.add_option("-i", "--input",dest="inputFileName",action="store",type="string",help="input file name [compulsory] [format: file in GFF3 format]")
|
|
33 parser.add_option("-n", "--names",dest="names", action="store", type="string", help="name for the tags (separated by commas and no space) [compulsory] [format: string]")
|
|
34 parser.add_option("-o", "--output",dest="outTarFileName",action="store",type="string", help="output file [compulsory] [format: output file tar format]")
|
|
35 parser.add_option("-c", "--color",dest="colors",action="store",default=None,type="string", help="color of the lines (separated by commas and no space) [format: string]")
|
|
36 parser.add_option("-f", "--format",dest="format",action="store",default="png",type="string", help="format of the output file [format: string] [default: png]")
|
|
37 parser.add_option("-r", "--normalize",dest="normalize",action="store_true", default=False,help="normalize data (when panels are different) [format: bool] [default: false]")
|
|
38 parser.add_option("-l", "--log",dest="log",action="store",default="",type="string", help="use log on x- or y-axis (write 'x', 'y' or 'xy') [format: string]")
|
|
39 parser.add_option("-v", "--verbosity",dest="verbosity",action="store",default=1,type="int",help="trace level [format: int]")
|
|
40 (options, args) = parser.parse_args()
|
|
41
|
|
42
|
|
43 absPath = os.getcwd()
|
|
44 print "the current path is :", absPath
|
|
45 directory = "/tmp/wrappPlotRepartition"
|
|
46 print "the dir path is :", directory
|
|
47 if not os.path.exists(directory):
|
|
48 os.makedirs(directory)
|
|
49 os.chdir(directory)
|
|
50 if options.inputFileName != None and options.format != None and options.outTarFileName != None:
|
|
51 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
|
|
52 cmd = "python %s/Java/Python/plotRepartition.py -i %s -o %s -D %s" % (SMART_PATH, options.inputFileName, outputFileName, directory)
|
|
53 if options.names != None :
|
|
54 cmd += " -n %s" % options.names
|
|
55 else: print "You must choose tag names !"
|
|
56 if options.colors != None :
|
|
57 cmd += " -c %s" % options.colors
|
|
58 if options.format != None:
|
|
59 cmd += " -f %s" % options.format
|
|
60 if options.normalize :
|
|
61 cmd += " -r "
|
|
62 if options.log != "" :
|
|
63 cmd += " -l %s" % options.log
|
|
64
|
|
65 print "cmd is: ", cmd
|
|
66 status = subprocess.call(cmd, shell=True)
|
|
67 if status != 0:
|
|
68 raise Exception("Problem with the execution of command!")
|
|
69 toTar(options.outTarFileName, directory)
|
|
70 shutil.rmtree(directory)
|
|
71
|