annotate SMART/Java/Python/WrappGetDistribution.py @ 48:809ed01c8014

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