comparison SMART/galaxy/WrappGetLetterDistribution.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
3 import os
4 import sys
5 import getopt
6 from pyRepetUnit.commons.checker.CheckerException import CheckerException
7
8 SMART_PATH = "%s/SMART" % os.environ["REPET_PATH"]
9
10 class WrappGetLetterDistribution(object):
11
12 def __init__(self):
13 self._inputFileName = ""
14 self._inputFileFormat = ""
15 self._outputFileName = "tmpOutputFile"
16 self._csv = False
17
18 def help( self ):
19 print
20 print "usage: %s [ options ]" % ( sys.argv[0] )
21 print "options:"
22 print " -h: this help"
23 print " -i: input file"
24 print " -f: 'fasta' or 'fastq'"
25 print " -c: CSV output file"
26 print " -a: first PNG output file"
27 print " -b: second PNG output file"
28 print
29 print "Exemple:"
30 print
31 print "1:\n\tpython WrappGetLetterDistribution.py -i inputFile.fasta -f fasta -c outputFile1.csv -a outputFile2.png -b outputFile3.png"
32 print
33 print "2:\n\tpython WrappGetLetterDistribution.py -i inputFile.fastq -f fastq -c outputFile1.csv -a outputFile2.png -b outputFile3.png"
34 print
35 print
36
37
38 def setAttributesFromCommandLine(self):
39 try:
40 opts, args = getopt.getopt( sys.argv[1:], "hi:f:a:b:c:" )
41 except getopt.GetoptError, err:
42 print str(err); sys.exit(1)
43 for o, a in opts:
44 if o == "-h":
45 self.help()
46 sys.exit(0)
47 if o == "-i":
48 self._inputFileName = a
49 elif o == "-f":
50 self._inputFileFormat = a
51 elif o == "-c":
52 self._outputFileNameCSV = a
53 self._csv = True
54 elif o == "-a":
55 self._outputFileNamePNG = a
56 elif o == "-b":
57 self._outputFileNamePerNtPNG = a
58
59 def checkAttributes(self):
60 lMsg = []
61 if self._inputFileName == "" and not os.path.exists(self._inputFileName):
62 lMsg.append("ERROR: This input file doesn't exist!")
63 if self._inputFileFormat == "":
64 lMsg.append("ERROR: No input file format specified in option!")
65 if self._outputFileNamePNG == "":
66 lMsg.append("ERROR: No output file.png specified in option!")
67 if self._outputFileNamePerNtPNG == "":
68 lMsg.append("ERROR: No output filePerNt.png specified in option!")
69 if self._outputFileNameCSV == "" and self._csv == True :
70 lMsg.append("ERROR: No output file.csv specified in option!")
71
72 print ">>> lMsg " + str(lMsg)
73 if lMsg != []:
74 exp = CheckerException()
75 exp.setMessages(lMsg)
76 raise (exp)
77
78 def _cleanWorkingDir(self, cDir):
79 os.system("rm %s/tmpData* %s/tmpScript*" % (cDir, cDir))
80
81 def wrapp(self):
82 self.checkAttributes()
83 cDir = os.getcwd()
84
85 if self._csv == True:
86 os.system("python %s/Java/Python/getLetterDistribution.py -i %s -f %s -o %s/%s -c" % (SMART_PATH, self._inputFileName, self._inputFileFormat, cDir, self._outputFileName))
87 os.system("mv %s/%s.csv %s" % (cDir, self._outputFileName, self._outputFileNameCSV))
88 os.system("mv %s/%s.png %s" % (cDir, self._outputFileName, self._outputFileNamePNG))
89 os.system("mv %s/%sPerNt.png %s" % (cDir, self._outputFileName, self._outputFileNamePerNtPNG))
90
91 self._cleanWorkingDir(cDir)
92
93 if __name__ == '__main__':
94 launcher = WrappGetLetterDistribution()
95 launcher.setAttributesFromCommandLine()
96 launcher.wrapp()
97