[Biopython-dev] nodes in Martel tree
Andrew Dalke
dalke at acm.org
Mon Apr 23 00:49:41 EDT 2001
Cayte wrote:
> I wonder if with nested nodes, you need to use the leaf nodes to get it to
> work right. I had the following structure.
No, you shouldn't need to.
> I had the following structure.
It's hard to evaluate that without the full format definition. I've
attached a file which I used for testing. The result when parsing
the data:
SEQTPA 107 98 gag GLU E
SEQTPA 108 99 tgg TRP W
SEQTPA 106 100 aaa XXX X bbb YYY Y
is (up to newlines)
<?xml version="1.0" encoding="iso-8859-1"?>
SEQTPA <n1>107</n1> <n2>98</n2><residue> <codon>gag</codon>
<three_letter>GLU</three_letter> <one_letter>E</one_letter></residue>
SEQTPA <n1>108</n1> <n2>99</n2><residue> <codon>tgg</codon>
<three_letter>TRP</three_letter> <one_letter>W</one_letter></residue>
SEQTPA <n1>106</n1> <n2>100</n2><residue> <codon>aaa</codon>
<three_letter>XXX</three_letter> <one_letter>X</one_letter></residue>
<residue> <codon>bbb</codon> <three_letter>YYY</three_letter>
<one_letter>Y</one_letter></residue>
As you can see in the last line, there are two "residue" fields.
I can't seem to reproduce the behaviour you are seeing.
> I have another question about residue notation.
That one I cannot answer - I don't know. My guess agrees
with yours.
Andrew
dalke at acm.org
-------------- next part --------------
import Martel
from xml.sax import saxutils
blank_space = Martel.Str(" ")
codon = Martel.Re("(?P<codon>...)")
amino_3_letter_code = Martel.Re("(?P<three_letter>...)")
amino_1_letter_code = Martel.Re("(?P<one_letter>.)")
residue = Martel.Group( "residue",
blank_space +
codon +
blank_space +
amino_3_letter_code +
blank_space +
amino_1_letter_code )
spaces = Martel.Re(" +")
seqtpa = Martel.Str("SEQTPA") + \
spaces + Martel.Integer("n1") + \
spaces + Martel.Integer("n2") + \
Martel.Rep1(residue) + \
Martel.AnyEol()
format = Martel.Rep1(seqtpa)
data = """\
SEQTPA 107 98 gag GLU E
SEQTPA 108 99 tgg TRP W
SEQTPA 106 100 aaa XXX X bbb YYY Y
"""
parser = format.make_parser()
parser.setContentHandler(saxutils.XMLGenerator())
parser.parseString(data)
More information about the Biopython-dev
mailing list