18
|
1 #!/usr/bin/env python
|
|
2
|
|
3 # Copyright INRA (Institut National de la Recherche Agronomique)
|
|
4 # http://www.inra.fr
|
|
5 # http://urgi.versailles.inra.fr
|
|
6 #
|
|
7 # This software is governed by the CeCILL license under French law and
|
|
8 # abiding by the rules of distribution of free software. You can use,
|
|
9 # modify and/ or redistribute the software under the terms of the CeCILL
|
|
10 # license as circulated by CEA, CNRS and INRIA at the following URL
|
|
11 # "http://www.cecill.info".
|
|
12 #
|
|
13 # As a counterpart to the access to the source code and rights to copy,
|
|
14 # modify and redistribute granted by the license, users are provided only
|
|
15 # with a limited warranty and the software's author, the holder of the
|
|
16 # economic rights, and the successive licensors have only limited
|
|
17 # liability.
|
|
18 #
|
|
19 # In this respect, the user's attention is drawn to the risks associated
|
|
20 # with loading, using, modifying and/or developing or reproducing the
|
|
21 # software by the user in light of its specific status of free software,
|
|
22 # that may mean that it is complicated to manipulate, and that also
|
|
23 # therefore means that it is reserved for developers and experienced
|
|
24 # professionals having in-depth computer knowledge. Users are therefore
|
|
25 # encouraged to load and test the software's suitability as regards their
|
|
26 # requirements in conditions enabling the security of their systems and/or
|
|
27 # data to be ensured and, more generally, to use and operate it in the
|
|
28 # same conditions as regards security.
|
|
29 #
|
|
30 # The fact that you are presently reading this means that you have had
|
|
31 # knowledge of the CeCILL license and that you accept its terms.
|
|
32
|
|
33
|
|
34 import os
|
|
35 import sys
|
|
36 import getopt
|
|
37
|
|
38 from commons.core.seq.FastaUtils import FastaUtils
|
|
39
|
|
40
|
|
41 def help():
|
|
42 print
|
|
43 print "usage: %s [ options ]" % ( sys.argv[0].split("/")[-1] )
|
|
44 print "options:"
|
|
45 print " -h: this help"
|
|
46 print " INPUT: use '-i' or '-I'"
|
|
47 print " -i: name of the input file (fasta format)"
|
|
48 print " -I: name of the input directory (containing fasta files)"
|
|
49 print " OUTPUT: use '-o' or '-O'"
|
|
50 print " -o: name of the output file (use only with '-i')"
|
|
51 print " -O: name of the output directory (use only with '-I')"
|
|
52 print " output file are: prefix of input fasta file + '_shuffle.fa')"
|
|
53 print " -v: verbose (default=0/1/2)"
|
|
54 print
|
|
55
|
|
56
|
|
57 def main():
|
|
58 inData = ""
|
|
59 outData = ""
|
|
60 verbose = 0
|
|
61 try:
|
|
62 opts, args = getopt.getopt( sys.argv[1:], "hi:I:o:O:v:" )
|
|
63 except getopt.GetoptError, err:
|
|
64 sys.stderr.write( "%s\n" % str(err) )
|
|
65 help()
|
|
66 sys.exit(1)
|
|
67 for o,a in opts:
|
|
68 if o == "-h":
|
|
69 help()
|
|
70 sys.exit(0)
|
|
71 elif o == "-i":
|
|
72 inData = a
|
|
73 elif o == "-I":
|
|
74 inData = a
|
|
75 elif o == "-o":
|
|
76 outData = a
|
|
77 elif o == "-O":
|
|
78 outData = a
|
|
79 elif o == "-v":
|
|
80 verbose = int(a)
|
|
81
|
|
82 if inData == "" or ( not os.path.isfile( inData ) \
|
|
83 and not os.path.isdir( inData ) ):
|
|
84 msg = "ERROR: missing input file or directory (-i or -I)"
|
|
85 sys.stderr.write( "%s\n" % msg )
|
|
86 help()
|
|
87 sys.exit(1)
|
|
88
|
|
89 if outData == "":
|
|
90 print "ERROR: missing name of output file or directory (-o or -O)"
|
|
91 help()
|
|
92 sys.exit(1)
|
|
93
|
|
94 if verbose > 0:
|
|
95 print "START %s" % ( sys.argv[0].split("/")[-1] )
|
|
96 sys.stdout.flush()
|
|
97
|
|
98 FastaUtils.dbShuffle( inData, outData, verbose )
|
|
99
|
|
100 if verbose > 0:
|
|
101 print "END %s" % ( sys.argv[0].split("/")[-1] )
|
|
102 sys.stdout.flush()
|
|
103
|
|
104 return 0
|
|
105
|
|
106
|
|
107 if __name__ == "__main__":
|
|
108 main()
|