annotate SMART/galaxy/WrappGetLetterDistribution.py @ 28:2a3fdec156e0

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