comparison SMART/Java/Python/WrappPlotCoverage.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
children
comparison
equal deleted inserted replaced
5:ea3082881bf8 6:769e306b7933
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 = "%s/SMART" % 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
24 if __name__ == "__main__":
25
26 # parse command line
27 description = "Plot Coverage v1.0.1: Plot the coverage of the first data with respect to the second one. [Category: Visualization]"
28
29 parser = OptionParser(description = description)
30 parser.add_option("-i", "--input1", dest="inputFileName1", action="store", type="string", help="input file 1 [compulsory] [format: file in transcript format given by -f]")
31 parser.add_option("-f", "--inputFormat1", dest="inputFormat1", action="store", type="string", help="format of input file 1 [compulsory] [format: transcript file format]")
32 parser.add_option("-j", "--input2", dest="inputFileName2", action="store", type="string", help="input file 2 [compulsory] [format: file in transcript format given by -g]")
33 parser.add_option("-g", "--inputFormat2", dest="inputFormat2", action="store", type="string", help="format of input file 2 [compulsory] [format: transcript file format]")
34 parser.add_option("-q", "--sequence", dest="inputSequence", action="store", default=None, type="string", help="input sequence file [format: file in FASTA format] [default: None]")
35 parser.add_option("-o", "--output", dest="outTarFileName", action="store", type="string", help="output file [compulsory] [format: output file in zip format]")
36 parser.add_option("-w", "--width", dest="width", action="store", default=1500, type="int", help="width of the plots (in px) [format: int] [default: 1500]")
37 parser.add_option("-e", "--height", dest="height", action="store", default=1000, type="int", help="height of the plots (in px) [format: int] [default: 1000]")
38 parser.add_option("-t", "--title", dest="title", action="store", default="", type="string", help="title of the plots [format: string]")
39 parser.add_option("-x", "--xlab", dest="xLabel", action="store", default="", type="string", help="label on the x-axis [format: string]")
40 parser.add_option("-y", "--ylab", dest="yLabel", action="store", default="", type="string", help="label on the y-axis [format: string]")
41 parser.add_option("-p", "--plusColor", dest="plusColor", action="store", default="red", type="string", help="color for the elements on the plus strand [format: string] [default: red]")
42 parser.add_option("-m", "--minusColor", dest="minusColor", action="store", default="blue", type="string", help="color for the elements on the minus strand [format: string] [default: blue]")
43 parser.add_option("-s", "--sumColor", dest="sumColor", action="store", default="black", type="string", help="color for 2 strands coverage line [format: string] [default: black]")
44 parser.add_option("-l", "--lineColor", dest="lineColor", action="store", default="black", type="string", help="color for the lines [format: string] [default: black]")
45 parser.add_option("-1", "--merge", dest="merge", action="store_true", default=False, help="merge the 2 plots in 1 [format: boolean] [default: false]")
46 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
47 (options, args) = parser.parse_args()
48
49 absPath = os.getcwd()
50 directory = "/tmp/wrappPlotCov"
51 if not os.path.exists(directory):
52 os.makedirs(directory)
53 os.chdir(directory)
54 if options.inputFileName1 != None and options.inputFormat1 != None and options.inputFileName2 != None and options.inputFormat2 != None and options.outTarFileName != None:
55 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
56 print 'outputfile is :', outputFileName
57 cmd = "python %s/Java/Python/plotCoverage.py -i %s -f %s -j %s -g %s -o %s -D %s" % (SMART_PATH, options.inputFileName1, options.inputFormat1, options.inputFileName2, options.inputFormat2, outputFileName, directory)
58 if options.inputSequence!= None:
59 cmd += " -q %s" % options.inputSequence
60 if options.width != None:
61 cmd += " -w %s" % options.width
62 if options.height != None:
63 cmd += " -e %s" % options.height
64 if options.title != None:
65 cmd += " -t %s" % options.title
66 if options.xLabel != None:
67 cmd += " -x %s" % options.xLabel
68 if options.yLabel != None:
69 cmd += " -y %s" % options.yLabel
70 if options.plusColor != None:
71 cmd += " -p %s" % options.plusColor
72 if options.minusColor != None:
73 cmd += " -m %s" % options.minusColor
74 if options.sumColor != None:
75 cmd += " -s %s" % options.sumColor
76 if options.lineColor != None:
77 cmd += " -l %s" % options.lineColor
78 if options.merge:
79 cmd += " -1"
80 status = subprocess.call(cmd, shell=True)
81 if status != 0:
82 raise Exception("Problem with the execution of command!")
83 toTar(options.outTarFileName, directory)
84 shutil.rmtree(directory)
85
86
87
88
89