18
|
1 #!/usr/bin/env python
|
|
2
|
|
3 from commons.pyRepetUnit.fastaTranslation.allFrames.TranslateInAllFramesAndReplaceStopByX import TranslateInAllFramesAndReplaceStopByX
|
|
4 from commons.core.utils.FileUtils import FileUtils
|
|
5 import os
|
|
6 import sys
|
|
7 import getopt
|
|
8
|
|
9 #------------------------------------------------------------------------------
|
|
10
|
|
11 def help():
|
|
12
|
|
13 """
|
|
14 Give the command-line parameters.
|
|
15 """
|
|
16
|
|
17 print ""
|
|
18 print "usage: ",sys.argv[0],"[ options ]"
|
|
19 print "options:"
|
|
20 print " -h: this help"
|
|
21 print " -i: name of the nucleotidic input file (format='fasta')"
|
|
22 print " -o: name of the output file (default=inFileName+'_aa')"
|
|
23 print " -v: verbose (default=0/1/2)"
|
|
24 print " -c: clean"
|
|
25 print ""
|
|
26
|
|
27 #------------------------------------------------------------------------------
|
|
28
|
|
29 def main():
|
|
30
|
|
31 inFileName = ""
|
|
32 outFileName = ""
|
|
33 verbose = 0
|
|
34 clean = False
|
|
35
|
|
36 try:
|
|
37 opts = getopt.getopt(sys.argv[1:],"hi:o:v:c")[0]
|
|
38 except getopt.GetoptError, err:
|
|
39 print str(err)
|
|
40 help()
|
|
41 sys.exit(1)
|
|
42 for o,a in opts:
|
|
43 if o == "-h":
|
|
44 help()
|
|
45 sys.exit(0)
|
|
46 elif o == "-i":
|
|
47 inFileName = a
|
|
48 elif o == "-o":
|
|
49 outFileName = a
|
|
50 elif o == "-v":
|
|
51 verbose = int(a)
|
|
52 elif o == "-c":
|
|
53 clean = True
|
|
54
|
|
55 if inFileName == "":
|
|
56 print "*** Error: missing compulsory options"
|
|
57 help()
|
|
58 sys.exit(1)
|
|
59
|
|
60 if verbose > 0:
|
|
61 print "beginning of %s" % (sys.argv[0].split("/")[-1])
|
|
62 sys.stdout.flush()
|
|
63
|
|
64 if outFileName == "":
|
|
65 outFileName = "%s_aa" % ( inFileName )
|
|
66
|
|
67 iTIAFARSBX = TranslateInAllFramesAndReplaceStopByX()
|
|
68 iTIAFARSBX.setInputFile( inFileName )
|
|
69 iTIAFARSBX.setOutputFile( outFileName )
|
|
70 iTIAFARSBX.run( )
|
|
71
|
|
72 if clean == True:
|
|
73 os.remove( inFileName )
|
|
74
|
|
75 if verbose > 0:
|
|
76 if FileUtils.isRessourceExists( outFileName ) and not(FileUtils.isEmpty( outFileName )):
|
|
77 print "%s finished successfully" % (sys.argv[0].split("/")[-1])
|
|
78 sys.stdout.flush()
|
|
79 else:
|
|
80 print "warning %s execution failed" % (sys.argv[0].split("/")[-1])
|
|
81 sys.stdout.flush()
|
|
82
|
|
83 return 0
|
|
84
|
|
85 #------------------------------------------------------------------------------
|
|
86
|
|
87 if __name__ == '__main__':
|
|
88 main() |