]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_python/Cjung/lowercase_seq
fixed seq qual length check
[biopieces.git] / code_python / Cjung / lowercase_seq
index c608e80d051a31d6971b8133139acd94f426cd88..d3c53fe1cf0e9cc2a33ed99a60a18704ac7a8c9d 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,61 +108,53 @@ 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))
+               os.system("print_wiki -i %s %s" % (usage_path, opt))
        ###########################################
 
 
 # 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
-
-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('')
-       sys.exit(1)
+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)
 
-#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 len(opts)==0:
+       if sys.stdin.isatty():
+               lc_seq.print_usage("")
+               sys.exit(1)
 
+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
 
-if a.opt.has_key('-?'):
-       lc_seq.print_usage('-?')
+try:
+       lc_seq.open_streams(stream_in, stream_out)
+except:
+       sys.stderr.write("%s\n" % ("IOError"))
        sys.exit(1)
-else:
-       try:
-               lc_seq.open_streams(a.opt['-I'], a.opt['-O'])
-       except:
-               sys.stderr.write("%s\n" % ("IOError"))
-               sys.exit(1)
 
 
 while True:
@@ -169,11 +166,4 @@ while True:
 
 lc_seq.close_streams()
 
-#source = "Dmel_tRNAs_key_record_tuples.txt"
-#lc_seq.open_stream(source)
-
-#lc_seq.get_record()
-#lc_seq.put_record()
-
-