comparison SMART/Java/Python/WrappGetDistribution.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 if __name__ == "__main__":
24
25 magnifyingFactor = 1000
26
27 # parse command line
28 description = "Get Distribution v1.0.1: Get the distribution of the genomic coordinates on a genome. [Category: Visualization]"
29
30 parser = OptionParser(description = description)
31 parser.add_option("-i", "--input", dest="inputFileName", action="store", type="string", help="input file [compulsory] [format: file in transcript format given by -f]")
32 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of the input file [compulsory] [format: transcript file format]")
33 parser.add_option("-o", "--output", dest="outTarFileName", action="store", type="string", help="output file [compulsory] [format: output file in GFF3 format]")
34 parser.add_option("-r", "--reference", dest="referenceFileName", action="store", default=None, type="string", help="file containing the genome [compulsory] [format: file in FASTA format]")
35 parser.add_option("-n", "--nbBins", dest="nbBins", action="store", default=1000, type="int", help="number of bins [default: 1000] [format: int]")
36 parser.add_option("-2", "--bothStrands", dest="bothStrands", action="store_true", default=False, help="plot one curve per strand [format: bool] [default: false]")
37 parser.add_option("-w", "--raw", dest="raw", action="store_true", default=False, help="plot raw number of occurrences instead of density [format: bool] [default: false]")
38 parser.add_option("-x", "--csv", dest="csv", action="store_true", default=False, help="write a .csv file [format: bool]")
39 parser.add_option("-c", "--chromosome", dest="chromosome", action="store", default=None, type="string", help="plot only a chromosome [format: string]")
40 parser.add_option("-s", "--start", dest="start", action="store", default=None, type="int", help="start from a given region [format: int]")
41 parser.add_option("-e", "--end", dest="end", action="store", default=None, type="int", help="end from a given region [format: int]")
42 parser.add_option("-y", "--yMin", dest="yMin", action="store", default=None, type="int", help="minimum value on the y-axis to plot [format: int]")
43 parser.add_option("-Y", "--yMax", dest="yMax", action="store", default=None, type="int", help="maximum value on the y-axis to plot [format: int]")
44 parser.add_option("-g", "--gff", dest="gff", action="store_true", default=False, help="also write GFF3 file [format: bool] [default: false]")
45 parser.add_option("-H", "--height", dest="height", action="store", default=None, type="int", help="height of the graphics [format: int] [default: 300]")
46 parser.add_option("-W", "--width", dest="width", action="store", default=None, type="int", help="width of the graphics [format: int] [default: 1000]")
47 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [default: 1] [format: int]")
48 parser.add_option("-l", "--log", dest="log", action="store_true", default=False, help="write a log file [format: bool]")
49 (options, args) = parser.parse_args()
50
51
52 absPath = os.getcwd()
53 print "the current path is :", absPath
54 directory = "/tmp/wrappGetDistribution"
55 print "the dir path is :", directory
56 if not os.path.exists(directory):
57 os.makedirs(directory)
58 os.chdir(directory)
59 if options.inputFileName != None and options.format != None and options.outTarFileName != None:
60 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
61 cmd = "python %s/Java/Python/getDistribution.py -i %s -f %s -o %s -D %s" % (SMART_PATH, options.inputFileName, options.format, outputFileName, directory)
62 if options.referenceFileName != None :
63 cmd += " -r %s" % options.referenceFileName
64 if options.nbBins != None :
65 cmd += " -n %s" % options.nbBins
66 if options.chromosome :
67 cmd += " -c %s" % options.chromosome
68 if options.start != None :
69 cmd += " -s %s" % options.start
70 if options.end != None :
71 cmd += " -e %s" % options.end
72 if options.yMin != None :
73 cmd += " -y %s" % options.yMin
74 if options.yMax != None :
75 cmd += " -Y %s" % options.yMax
76 if options.height != None :
77 cmd += " -H %s" % options.height
78 if options.width != None :
79 cmd += " -W %s" % options.width
80 if options.bothStrands :
81 cmd += " -2"
82 if options.raw :
83 cmd += " -w"
84 if options.csv :
85 cmd += " -x"
86 if options.gff :
87 cmd += " -g"
88 if options.log :
89 cmd += " -l"
90 print "cmd is: ", cmd
91 status = subprocess.call(cmd, shell=True)
92 if status != 0:
93 raise Exception("Problem with the execution of command!")
94 toTar(options.outTarFileName, directory)
95 shutil.rmtree(directory)
96