annotate SMART/Java/Python/WrappPlotRepartition.py @ 67:f4de72c80eac draft

Uploaded
author m-zytnicki
date Mon, 16 Nov 2015 11:59:35 -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 = "%sSMART" % 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 = "Plot the repartition of different data on a whole genome. (This tool uses 1 input file only, the different values being stored in the tags. See documentation to know more about it.) [Category: Visualization]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 parser = OptionParser(description = description)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 parser.add_option("-i", "--input",dest="inputFileName",action="store",type="string",help="input file name [compulsory] [format: file in GFF3 format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 parser.add_option("-n", "--names",dest="names", action="store", type="string", help="name for the tags (separated by commas and no space) [compulsory] [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 parser.add_option("-o", "--output",dest="outTarFileName",action="store",type="string", help="output file [compulsory] [format: output file tar format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 parser.add_option("-c", "--color",dest="colors",action="store",default=None,type="string", help="color of the lines (separated by commas and no space) [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 parser.add_option("-f", "--format",dest="format",action="store",default="png",type="string", help="format of the output file [format: string] [default: png]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 parser.add_option("-r", "--normalize",dest="normalize",action="store_true", default=False,help="normalize data (when panels are different) [format: bool] [default: false]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 parser.add_option("-l", "--log",dest="log",action="store",default="",type="string", help="use log on x- or y-axis (write 'x', 'y' or 'xy') [format: string]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 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
40 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 absPath = os.getcwd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 print "the current path is :", absPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 directory = "/tmp/wrappPlotRepartition"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 print "the dir path is :", directory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 if not os.path.exists(directory):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 os.makedirs(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 os.chdir(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 if options.inputFileName != None and options.format != None and options.outTarFileName != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 cmd = "python %s/Java/Python/plotRepartition.py -i %s -o %s -D %s" % (SMART_PATH, options.inputFileName, outputFileName, directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 if options.names != None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 cmd += " -n %s" % options.names
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 else: print "You must choose tag names !"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 if options.colors != None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 cmd += " -c %s" % options.colors
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 if options.format != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 cmd += " -f %s" % options.format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 if options.normalize :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 cmd += " -r "
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 if options.log != "" :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 cmd += " -l %s" % options.log
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 print "cmd is: ", cmd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 status = subprocess.call(cmd, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 raise Exception("Problem with the execution of command!")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 toTar(options.outTarFileName, directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 shutil.rmtree(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71