使用 DOM 从纯文本中提取信息并写入 XML
目前,我正在设计一些糖生物学领域的格式转换工具。格式转换涉及从文本文件到该领域标准的 XML 文件。大多数时候,我们获得的数据包含以下纯文本文件中感兴趣的信息。实际文件将所有这些内容写在一行中。阅读并拆分此文本以获取信息很简单(可能不直观),但 XML 正是问题所在。
[][b-D-GlcpNAc]
{[(4+1)][b-D-GlcpNAc]
{[(4+1)][b-D-Manp]
{[(3+1)][a-D-Manp]
{[(2+1)][a-D-Manp]{}
}
[(6+1)][a-D-Manp]
{[(3+1)][a-D-Manp]{}
[(6+1)][a-D-Manp]{}
}
}
}
如何解释:
- ww-w+形式的所有东西都是与另一种糖相连的糖。链接由大花 { 表示。
- 4+1、3+1 等表示一种糖上的碳键与另一种糖上的碳键合。因此前一个碳的第四个碳链接到后一个碳的第一个碳。
- {} 这表示没有额外的糖与该糖相关联
- } 卷曲只是关闭该层。
您或许可以阅读 XML 并弄清楚链接是如何工作的。但如果你们想要更详细的解释,尽管问。
XML 应该如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<GlydeII>
<molecule subtype="glycan" id="From_GlycoCT_Translation">
<residue subtype="base_type" partid="1" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dglc-HEX-1:5" />
<residue subtype="substituent" partid="2" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=n-acetyl" />
<residue subtype="base_type" partid="3" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dglc-HEX-1:5" />
<residue subtype="substituent" partid="4" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=n-acetyl" />
<residue subtype="base_type" partid="5" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dman-HEX-1:5" />
<residue subtype="base_type" partid="6" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="7" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="8" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="9" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="10" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue_link from="2" to="1">
<atom_link from="N1H" to="C2" to_replace="O2" bond_order="1" />
</residue_link>
<residue_link from="3" to="1">
<atom_link from="C1" to="O4" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="4" to="3">
<atom_link from="N1H" to="C2" to_replace="O2" bond_order="1" />
</residue_link>
<residue_link from="5" to="3">
<atom_link from="C1" to="O4" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="6" to="5">
<atom_link from="C1" to="O3" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="7" to="6">
<atom_link from="C1" to="O2" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="8" to="5">
<atom_link from="C1" to="O6" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="9" to="8">
<atom_link from="C1" to="O3" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="10" to="8">
<atom_link from="C1" to="O6" from_replace="O1" bond_order="1" />
</residue_link>
</molecule>
</GlydeII>
到目前为止,我已经能够轻松获取所有剩余字段并将它们写入 XML。但我什至在为residual_link 字段编写伪代码时遇到了麻烦。即使我只能获得有关如何在 xml 中添加链接信息的帮助和想法,我也会很感激。
Currently, I'm designing some format conversion tools in the area of glycobiology. The format conversion involves going from a text file to an XML file that is standard in the field. Most of the time, the data we get contains the information of interest in a plain text file like below. The actual file has all of this in one line. Reading and splitting this text to get the information is trivial (probably not intuitive) but XML is where the problem is.
[][b-D-GlcpNAc]
{[(4+1)][b-D-GlcpNAc]
{[(4+1)][b-D-Manp]
{[(3+1)][a-D-Manp]
{[(2+1)][a-D-Manp]{}
}
[(6+1)][a-D-Manp]
{[(3+1)][a-D-Manp]{}
[(6+1)][a-D-Manp]{}
}
}
}
How to interpret this:
- Everything of the form w-w-w+ is a sugar that is linked to another one. Linkage is shown by the curly {.
- 4+1, 3+1 and so on indicate which carbon bonds on one sugar to the other one. So the 4th carbon on the preceding one links to the 1st carbon on the succeeding one.
- {} This indicates no additional sugar linked to that sugar
- } curlies just close that tier.
You can probably read the XML and figure out how the linkages work. But if you guys would prefer a more detailed explanation, just ask.
What the XML should look like is shown below.
<?xml version="1.0" encoding="UTF-8"?>
<GlydeII>
<molecule subtype="glycan" id="From_GlycoCT_Translation">
<residue subtype="base_type" partid="1" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dglc-HEX-1:5" />
<residue subtype="substituent" partid="2" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=n-acetyl" />
<residue subtype="base_type" partid="3" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dglc-HEX-1:5" />
<residue subtype="substituent" partid="4" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=n-acetyl" />
<residue subtype="base_type" partid="5" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=b-dman-HEX-1:5" />
<residue subtype="base_type" partid="6" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="7" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="8" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="9" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue subtype="base_type" partid="10" ref="http://www.monosaccharideDB.org/GLYDE-II.jsp?G=a-dman-HEX-1:5" />
<residue_link from="2" to="1">
<atom_link from="N1H" to="C2" to_replace="O2" bond_order="1" />
</residue_link>
<residue_link from="3" to="1">
<atom_link from="C1" to="O4" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="4" to="3">
<atom_link from="N1H" to="C2" to_replace="O2" bond_order="1" />
</residue_link>
<residue_link from="5" to="3">
<atom_link from="C1" to="O4" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="6" to="5">
<atom_link from="C1" to="O3" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="7" to="6">
<atom_link from="C1" to="O2" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="8" to="5">
<atom_link from="C1" to="O6" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="9" to="8">
<atom_link from="C1" to="O3" from_replace="O1" bond_order="1" />
</residue_link>
<residue_link from="10" to="8">
<atom_link from="C1" to="O6" from_replace="O1" bond_order="1" />
</residue_link>
</molecule>
</GlydeII>
So far I've been trivially able to get all the residue fields and written them to XML. But I'm having trouble even writing pseudo code for the residue_link fields. Even if I can just get help and ideas on how to go about adding the linkage information in the xml I would appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的!很酷的问题,它以一种很好的方式伤害了我的大脑。
首先......为了我的理智,我将你的原始数据标记为一种有意义的方式:
我认为关键是弄清楚这些对是什么,并且你想以编程方式找出你所处的级别。
伪代码:
您还想跟踪哪个糖是先前的“父”糖。
Okay! Cool problem, it hurts my brain in a good way.
First... for my sanity I tabbed your raw data into a way that makes sense:
I think that the key to this is figuring out what the pairs are, and you want to programmatically figure out what level you're on.
Pseudocode:
You'd also want to keep track of which sugar is the previous "parent" sugar.