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