annotate SMART/Java/Python/WrappPlotCoverage.py @ 9:1eb55963fe39

Updated CompareOverlappingSmall*.py
author m-zytnicki
date Thu, 14 Mar 2013 05:23:05 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #! /usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 from optparse import OptionParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import tarfile
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 import re
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 import shutil
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 import subprocess
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 SMART_PATH = "%s/SMART" % os.environ["REPET_PATH"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 def toTar(tarFileName, directory):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 fileName = os.path.splitext(tarFileName)[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 fileNameBaseName = os.path.basename(fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 tfile = tarfile.open(fileName + ".tmp.tar", "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 list = os.listdir(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 for file in list:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 if re.search(str(fileNameBaseName), file):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 tfile.add(file)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 os.system("mv %s %s" % (fileName + ".tmp.tar", options.outTarFileName))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 tfile.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # parse command line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 description = "Plot Coverage v1.0.1: Plot the coverage of the first data with respect to the second one. [Category: Visualization]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 parser = OptionParser(description = description)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 parser.add_option("-f", "--inputFormat1", dest="inputFormat1", action="store", type="string", help="format of input file 1 [compulsory] [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 parser.add_option("-g", "--inputFormat2", dest="inputFormat2", action="store", type="string", help="format of input file 2 [compulsory] [format: transcript file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 parser.add_option("-o", "--output", dest="outTarFileName", action="store", type="string", help="output file [compulsory] [format: output file in zip format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 parser.add_option("-t", "--title", dest="title", action="store", default="", type="string", help="title of the plots [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 parser.add_option("-x", "--xlab", dest="xLabel", action="store", default="", type="string", help="label on the x-axis [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 parser.add_option("-y", "--ylab", dest="yLabel", action="store", default="", type="string", help="label on the y-axis [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 parser.add_option("-l", "--lineColor", dest="lineColor", action="store", default="black", type="string", help="color for the lines [format: string] [default: black]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 parser.add_option("-1", "--merge", dest="merge", action="store_true", default=False, help="merge the 2 plots in 1 [format: boolean] [default: false]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 absPath = os.getcwd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 directory = "/tmp/wrappPlotCov"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 if not os.path.exists(directory):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 os.makedirs(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 os.chdir(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 if options.inputFileName1 != None and options.inputFormat1 != None and options.inputFileName2 != None and options.inputFormat2 != None and options.outTarFileName != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 print 'outputfile is :', outputFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 if options.inputSequence!= None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 cmd += " -q %s" % options.inputSequence
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 if options.width != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 cmd += " -w %s" % options.width
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 if options.height != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 cmd += " -e %s" % options.height
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 if options.title != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 cmd += " -t %s" % options.title
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 if options.xLabel != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 cmd += " -x %s" % options.xLabel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 if options.yLabel != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 cmd += " -y %s" % options.yLabel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 if options.plusColor != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 cmd += " -p %s" % options.plusColor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 if options.minusColor != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 cmd += " -m %s" % options.minusColor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 if options.sumColor != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 cmd += " -s %s" % options.sumColor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 if options.lineColor != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 cmd += " -l %s" % options.lineColor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 if options.merge:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 cmd += " -1"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 status = subprocess.call(cmd, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 raise Exception("Problem with the execution of command!")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 toTar(options.outTarFileName, directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 shutil.rmtree(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89