Mercurial > repos > yufei-luo > s_mart
annotate smart_toolShed/SMART/Java/Python/WrappPlotCoverage.py @ 0:e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
| author | yufei-luo | 
|---|---|
| date | Thu, 17 Jan 2013 10:52:14 -0500 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 1 #! /usr/bin/env python | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 2 from optparse import OptionParser | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 3 import tarfile | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 4 import os | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 5 import re | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 6 import shutil | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 7 import subprocess | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 8 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 9 SMART_PATH = "%s/SMART" % os.environ["REPET_PATH"] | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 10 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 11 def toTar(tarFileName, directory): | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 12 fileName = os.path.splitext(tarFileName)[0] | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 13 fileNameBaseName = os.path.basename(fileName) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 14 tfile = tarfile.open(fileName + ".tmp.tar", "w") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 15 list = os.listdir(directory) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 16 for file in list: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 17 if re.search(str(fileNameBaseName), file): | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 18 tfile.add(file) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 19 os.system("mv %s %s" % (fileName + ".tmp.tar", options.outTarFileName)) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 20 tfile.close() | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 21 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 22 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 23 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 24 if __name__ == "__main__": | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 25 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 26 # parse command line | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]" | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 28 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 29 parser = OptionParser(description = description) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 46 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 47 (options, args) = parser.parse_args() | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 48 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 49 absPath = os.getcwd() | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 50 directory = "/tmp/wrappPlotCov" | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 51 if not os.path.exists(directory): | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 52 os.makedirs(directory) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 53 os.chdir(directory) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 55 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0] | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 56 print 'outputfile is :', outputFileName | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 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) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 58 if options.inputSequence!= None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 59 cmd += " -q %s" % options.inputSequence | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 60 if options.width != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 61 cmd += " -w %s" % options.width | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 62 if options.height != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 63 cmd += " -e %s" % options.height | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 64 if options.title != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 65 cmd += " -t %s" % options.title | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 66 if options.xLabel != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 67 cmd += " -x %s" % options.xLabel | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 68 if options.yLabel != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 69 cmd += " -y %s" % options.yLabel | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 70 if options.plusColor != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 71 cmd += " -p %s" % options.plusColor | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 72 if options.minusColor != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 73 cmd += " -m %s" % options.minusColor | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 74 if options.sumColor != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 75 cmd += " -s %s" % options.sumColor | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 76 if options.lineColor != None: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 77 cmd += " -l %s" % options.lineColor | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 78 if options.merge: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 79 cmd += " -1" | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 80 status = subprocess.call(cmd, shell=True) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 81 if status != 0: | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 82 raise Exception("Problem with the execution of command!") | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 83 toTar(options.outTarFileName, directory) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 84 shutil.rmtree(directory) | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 85 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 86 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 87 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 88 | 
| 
e0f8dcca02ed
Uploaded S-MART tool. A toolbox manages RNA-Seq and ChIP-Seq data.
 yufei-luo parents: diff
changeset | 89 | 
