3 import os, string, sys, getopt, Args, optparse
5 record_delimiter = "\n---\n"
15 ###########################################
18 ###########################################
20 ###########################################
21 def open_streams(self, input_file, output_file):
22 #print input_file, output_file
24 self.in_stream = sys.stdin
25 #print "in_stream = <STDIN>"
28 self.in_stream = open(input_file, 'r')
29 #print "in_stream = %s" % (input_file)
34 self.out_stream = sys.stdout
35 #print "out_stream = <STDOUT>"
38 self.out_stream = open(output_file, 'w')
39 #print "out_stream = %s" % (output_file)
42 ###########################################
44 ###########################################
45 def close_streams(self):
47 self.in_stream.close()
49 self.out_stream.close()
50 ###########################################
52 ###########################################
56 while not self.eo_buffer:
57 #print "STDIN.ISATTY :", self.in_stream.isatty()
59 if self.in_stream.isatty():
67 tmp = self.in_stream.read(1000)
71 self.buffer = self.buffer + tmp
72 delim_index = self.buffer.find(record_delimiter)
74 rec = self.buffer[:delim_index]
75 self.buffer = self.buffer[delim_index + len(record_delimiter):]
78 ###########################################
80 ###########################################
81 def process_record(self, rec):
85 lines = rec.split("\n")
87 self.rec_dic[self.rec_num] = {}
91 self.rec_dic[self.rec_num][toks[0]] = toks[1].lower()
93 self.rec_dic[self.rec_num][toks[0]] = toks[1]
94 #self.rec_dic[self.rec_num][toks[0]] = toks[1]
95 #print self.rec_dic[self.rec_num]
97 ###########################################
99 ###########################################
100 def put_record(self, r_num):
101 rec = self.rec_dic[r_num]
103 #print "%s: %s" % (k, rec[k])
104 self.out_stream.write("%s: %s\n" % (k, rec[k]))
106 self.out_stream.write("---\n")
107 ###########################################
109 ###########################################
110 def print_usage(self, opt):
112 bp_dir = os.environ['BP_DIR']
113 usage_path = bp_dir + os.path.sep + "bp_usage" + os.path.sep + "lowercase_seq.wiki"
114 os.system("print_usage -i %s %s" % (usage_path, opt))
115 ###########################################
120 lc_seq = Lowercase_seq()
123 opts, args = getopt.getopt(sys.argv[1:], "I:O:?vx", ["stream_in=", "stream_out=", "help", "verbose", "no_stream"])
124 except getopt.GetoptError, err:
125 # print help information and exit:
126 print str(err) # will print something like "option -a not recognized"
127 lc_seq.print_usage("")
132 lc_seq.print_usage("")
139 if o in ("-I", "--stream_in"):
141 elif o in ("-O", "--stream_out"):
144 lc_seq.print_usage("")
147 lc_seq.print_usage("-?")
149 elif o in ("-v", "--verbose"):
156 lc_seq.open_streams(stream_in, stream_out)
158 sys.stderr.write("%s\n" % ("IOError"))
163 rec = lc_seq.get_record()
166 rec_num = lc_seq.process_record(rec)
167 lc_seq.put_record(rec_num)
169 lc_seq.close_streams()
171 #source = "Dmel_tRNAs_key_record_tuples.txt"
172 #lc_seq.open_stream(source)