annotate SMART/Java/Python/WrappGetReadDistribution.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
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 # parse command line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 description = "Get Read Distribution v1.0.1: Plot the number of identical reads and give the most represented. [Category: Visualization]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 parser = OptionParser(description = description)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 parser.add_option("-i", "--input", dest="inputFileName", action="store", type="string", help="input file sequence [compulsory] [format: file in sequence format given by -f]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of the file [compulsory] [format: sequence file format]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 parser.add_option("-n", "--number", dest="number", action="store", default=None, type="int", help="keep the best n [format: int]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 parser.add_option("-p", "--percent", dest="percent", action="store", default=None, type="float", help="keep the best n\% [format: float]")
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: zip]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 absPath = os.getcwd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 print "the current path is :", absPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 directory = "/tmp/wrappGetReadDistribution"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 print "the dir path is :", directory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 if not os.path.exists(directory):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 os.makedirs(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 os.chdir(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 if options.inputFileName != None and options.format != None and options.outTarFileName != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 outputFileName = os.path.splitext(os.path.basename(options.outTarFileName))[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 cmd = "python %s/Java/Python/getReadDistribution.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
48 if options.number != None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 cmd += " -n %s" % options.number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 if options.percent != None :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 cmd += " -p %s" % options.percent
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 print "cmd is: ", cmd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 status = subprocess.call(cmd, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 raise Exception("Problem with the execution of command!")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 toTar(options.outTarFileName, directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 shutil.rmtree(directory)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58