18
|
1 #!/usr/bin/env python
|
|
2
|
|
3 ## @file
|
|
4 # This program extracts the n longest sequences from the input fasta file.
|
|
5 # usage: dbBestLength.py [ options ]
|
|
6 # options:
|
|
7 # -h: this help
|
|
8 # -i: name of the input fasta file
|
|
9 # -n: maximum number of sequences in the output file (default=20)
|
|
10 # -o: name of the output fasta file (default=inFileName+'.best20')
|
|
11 # -v: verbose (default=0/1/2)
|
|
12
|
|
13 import os
|
|
14 import sys
|
|
15 import getopt
|
|
16
|
|
17 if not os.environ.has_key( "REPET_PATH" ):
|
|
18 print "*** Error: no environment variable REPET_PATH"
|
|
19 sys.exit(1)
|
|
20 sys.path.append( os.environ["REPET_PATH"] )
|
|
21
|
|
22 from pyRepet.seq.fastaDB import *
|
|
23
|
|
24
|
|
25 def help():
|
|
26 """
|
|
27 Give the list of the command-line options.
|
|
28 """
|
|
29 print
|
|
30 print "usage: dbBestLength.py [ options ]"
|
|
31 print "options:"
|
|
32 print " -h: this help"
|
|
33 print " -i: name of the input fasta file"
|
|
34 print " -n: maximum number of sequences in the output file (default=20)"
|
|
35 print " -o: name of the output fasta file (default=inFileName+'.best20')"
|
|
36 print " -v: verbose (default=0/1/2)"
|
|
37 print
|
|
38
|
|
39
|
|
40 def main():
|
|
41 """
|
|
42 This program extracts the n longest sequences from the input fasta file.
|
|
43 """
|
|
44
|
|
45 inFileName = ""
|
|
46 nbSeq = 20
|
|
47 outFileName = ""
|
|
48 verbose = 0
|
|
49
|
|
50 try:
|
|
51 opts, args = getopt.getopt(sys.argv[1:],"hi:n:o:v:")
|
|
52 except getopt.GetoptError, err:
|
|
53 print str(err)
|
|
54 help()
|
|
55 sys.exit(1)
|
|
56 for o,a in opts:
|
|
57 if o == "-h":
|
|
58 help()
|
|
59 sys.exit(0)
|
|
60 elif o == "-i":
|
|
61 inFileName = a
|
|
62 elif o == "-n":
|
|
63 nbSeq = a
|
|
64 elif o == "-o":
|
|
65 outFileName = a
|
|
66 elif o == "-v":
|
|
67 verbose = int(a)
|
|
68
|
|
69 if inFileName == "":
|
|
70 print "ERROR: missing input file (-i)"
|
|
71 help()
|
|
72 sys.exit(1)
|
|
73
|
|
74 if verbose > 0:
|
|
75 print "START dbBestLength.py"
|
|
76 sys.stdout.flush()
|
|
77
|
|
78 if outFileName == "":
|
|
79 outFileName = "%s.best%s" % ( inFileName, nbSeq )
|
|
80
|
|
81 log = dbBestLength( nbSeq, inFileName, outFileName, verbose )
|
|
82 if log != 0:
|
|
83 print "ERROR: dbBestLength() returned %i" % ( log )
|
|
84 sys.exit(1)
|
|
85
|
|
86 if verbose > 0:
|
|
87 print "END dbBestLength.py"
|
|
88 sys.stdout.flush()
|
|
89
|
|
90 return 0
|
|
91
|
|
92
|
|
93 if __name__ == "__main__":
|
|
94 main()
|