Hi,
I know this isnt the pyparsing list, but it doesnt seem like there is
one. I m trying to use pyparsing to parse a file however I cant get
the Optional keyword to work. My file generally looks like this:
ALIGNMENT 1020 YS2-10a02.q1k chr09 1295 42 141045
142297 C 1254 95.06 1295 reject_bad_brea k 0
or this:
ALIGNMENT 36 YS2-10a08.q1k chrm 208 165 10745
10788 C 44 95.45 593 reject_low 10,14
and my grammar work well for these lines, however somethings the row looks like:
ALIGNMENT 53 YS2-10b03.p1k chr12 180 125 1067465
1067520 C 56 98.21 532|5,2 reject_low 25
So I try to parse the 532 using
from pyparsing import *
integer = Word( nums )
float = Word( nums+".")
identifier = Word( alphanums+"-_." )
alignment = Literal("ALIGNM ENT ").suppress ()
row_1 = integer.setResu ltsName("row_1" )#.setParseActi on(make_int)
src_id = identifier.setR esultsName("src _id")
dest_id = identifier.setR esultsName("des t_id")
src_start = integer.setResu ltsName("src_st art")#.setParse Action(make_int )
src_stop = integer.setResu ltsName("src_st op")#.setParseA ction(make_int)
dest_start = integer.setResu ltsName("dest_s tart")#.setPars eAction(make_in t)
dest_stop = integer.setResu ltsName("dest_s top")#.setParse Action(make_int )
row_8 = oneOf("F C").setResultsN ame("row_8")
length = integer.setResu ltsName("length ")#.setParseAct ion(make_int)
percent_id = float.setResult sName("percent_ id")#.setParseA ction(make_floa t)
row_11 = integer + Optional(Litera l("|") + commaSeparatedL ist )
)#.setResultsNa me("row_11")#.s etParseAction(m ake_int)
result = Word(alphas+"_" ).setResultsNam e("result")
row_13 = commaSeparatedL ist.setResultsN ame("row_13")
def make_alilines_s tatus_parser():
return alignment + row_1 + src_id + dest_id + src_start + src_stop
+ dest_start + dest_stop + row_8 + length + percent_id + row_11 +
result + row_13
def parse_alilines_ status(ifile):
alilines = make_alilines_s tatus_parser()
for l in ifile:
yield alilines.parseS tring( l )
However my parser always fails on lines of type 3. Does anyone know
why the Optional part is not working.
Many Thanks in advance
Nathan