Go to the documentation of this file.00001
00002 import sys,rp
00003 rule=['init sqs_ranges=[] ',
00004 'init sqs_locate="" ',
00005 'sqs ::= ranges? parms fileid @sqs_fileid="$fileid" ',
00006 'ranges::= "(" range+ ")" ',
00007 ' | range ',
00008 '# for ranges, we appended two other types',
00009 '# and columns start at 1 (not 0), that explains the $n-1 ',
00010 'range::= n "-" "*" @sqs_ranges.append([$n-1,999]) ',
00011 ' | n "-" m @sqs_ranges.append([$n-1,$m]) ',
00012 ' | n "." m @sqs_ranges.append([$n-1,($m+$n-1)]) ',
00013 ' | n "-" @sqs_ranges.append([$n-1,999]) ',
00014 'n ::= r"[0-9]"* ',
00015 'm ::= r"[0-9]"* ',
00016 'parms::= sep car* sep @sqs_locate="$car"',
00017 'sep ::= r"\S" ',
00018 'car ::= r"." ^sep ',
00019 'fileid::= r"\S"* ']
00020 parms=' '.join(sys.argv[1:])
00021
00022 cmp=rp.match(rule,parms)
00023 if cmp==None:
00024 print "Error in parsing:"
00025 else:
00026 id=None
00027 try:
00028
00029
00030 id=open(cmp.sqs_fileid)
00031 for l in id.readlines():
00032
00033
00034 if len(cmp.sqs_ranges)==0:
00035 data=l
00036 else:
00037 data=''
00038
00039
00040 for n,m in cmp.sqs_ranges:
00041 data+=l[n:m]
00042 if data.find(cmp.sqs_locate)>-1:
00043 print l[:-1]
00044 except Exception,e:
00045 print e
00046 else:
00047 if id!=None: id.close()