annotate SMART/galaxy/WrappGetLetterDistribution.py @ 10:c081f25e1572

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