annotate commons/tools/dbShuffle.py @ 19:9bcfa7936eec

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