]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_python/Cjung/lowercase_seq
added --check to a number of Biopieces
[biopieces.git] / code_python / Cjung / lowercase_seq
index c608e80d051a31d6971b8133139acd94f426cd88..b51df83a5ebb2007de9e86f866a71c2202c1fc84 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import os, string, sys, getopt, Args
+import os, string, sys, getopt, Args, optparse
 
 record_delimiter = "\n---\n"
 
@@ -54,6 +54,11 @@ class Lowercase_seq:
                rec = ''
                eof_flag = False
                while not self.eo_buffer:
+                       #print "STDIN.ISATTY :", self.in_stream.isatty()
+
+                       if self.in_stream.isatty():
+                               eof_flag = True
+
                        if eof_flag:
                                if self.buffer == '':
                                        self.eo_buffer = True
@@ -103,6 +108,7 @@ class Lowercase_seq:
 
        ###########################################
        def print_usage(self, opt):
+               #print opt
                bp_dir = os.environ['BP_DIR']
                usage_path = bp_dir + os.path.sep + "bp_usage" + os.path.sep + "lowercase_seq.wiki"
                os.system("print_usage -i %s %s" % (usage_path, opt))
@@ -111,53 +117,46 @@ class Lowercase_seq:
 
 # main
 
-"""
-print "############"
-print len(sys.argv)
-print sys.argv
-print "############"
-"""
-
-
 lc_seq = Lowercase_seq()
 
-a = Args.Args('Usage: %(progname)s [-a value] [-b value] [-c] word [file...]')
-
-a.opt['-I'] = ''    # input file
-a.opt['-O'] = ''    # output file
-a.getopt('I:O:?:v')                    # get user supplied option values
-
-#print >> sys.stderr, a.opt
+try:
+       opts, args = getopt.getopt(sys.argv[1:], "I:O:?vx", ["stream_in=", "stream_out=", "help", "verbose", "no_stream"])
+except getopt.GetoptError, err:
+       # print help information and exit:
+       print str(err) # will print something like "option -a not recognized"
+       lc_seq.print_usage("")
+       sys.exit(2)
 
-word = a.shift()                       # get the first of the remaining arguments
-                                                       # use a.pop() to get the last instead
-if not word == None:
-       sys.stderr.write("Unknown argument %s\n" % (word))
-       sys.exit(1)
 
-if sys.stdin.isatty():
-       lc_seq.print_usage('')
+if len(opts)==0:
+       lc_seq.print_usage("")
        sys.exit(1)
 
-#for line in a:              # iterate over the contents of all remaining arguments (file names)
-#      if a.lineno == 1:
-#              print 'starting new file:', a.infile
-#      a.warning(line.rstrip())
-
-#print 'Options:', a.opt
-#print 'Word:', word
-#print 'Total number of lines:', a.linesum
-
-
-if a.opt.has_key('-?'):
-       lc_seq.print_usage('-?')
-       sys.exit(1)
-else:
-       try:
-               lc_seq.open_streams(a.opt['-I'], a.opt['-O'])
-       except:
-               sys.stderr.write("%s\n" % ("IOError"))
+stream_in = ""
+stream_out = ""
+verbose = False
+for o, a in opts:
+       if o in ("-I", "--stream_in"):
+               stream_in = a
+       elif o in ("-O", "--stream_out"):
+               stream_out = a
+       elif o == "-?":
+               lc_seq.print_usage("")
+               sys.exit(1)
+       elif o == "--help":
+               lc_seq.print_usage("-?")
                sys.exit(1)
+       elif o in ("-v", "--verbose"):
+               verbose = True
+       #else:
+       #       assert False
+       #       print_usage()
+
+try:
+       lc_seq.open_streams(stream_in, stream_out)
+except:
+       sys.stderr.write("%s\n" % ("IOError"))
+       sys.exit(1)
 
 
 while True: