繁体   English   中英

在python中解析XML。 获取选定节点内的所有子节点值

[英]Parsing XML in python. Get all child node values inside selected node

我尝试在python中解析以下XML:

<abstract>
    <title>Abstract</title>
    <p>Amphinomids, more commonly known as fireworms, are a basal lineage of marine annelids characterized by the presence of defensive dorsal calcareous chaetae, which break off upon contact. It has long been hypothesized that amphinomids are venomous and use the chaetae to inject a toxic substance. However, studies investigating fireworm venom from a morphological or molecular perspective are scarce and no venom gland has been identified to date, nor any toxin characterized at the molecular level. To investigate this question, we analyzed the transcriptomes of three species of fireworms—
        <italic>Eurythoe complanata</italic>
        , 
        <italic>Hermodice carunculata</italic>
        , and 
        <italic>Paramphinome jeffreysii</italic>
        —following a venomics approach to identify putative venom compounds. Our venomics pipeline involved de novo transcriptome assembly, open reading frame, and signal sequence prediction, followed by three different homology search strategies: BLAST, HMMER sequence, and HMMER domain. Following this pipeline, we identified 34 clusters of orthologous genes, representing 13 known toxin classes that have been repeatedly recruited into animal venoms. Specifically, the three species share a similar toxin profile with C-type lectins, peptidases, metalloproteinases, spider toxins, and CAP proteins found among the most highly expressed toxin homologs. Despite their great diversity, the putative toxins identified are predominantly involved in three major biological processes: hemostasis, inflammatory response, and allergic reactions, all of which are commonly disrupted after fireworm stings. Although the putative fireworm toxins identified here need to be further validated, our results strongly suggest that fireworms are venomous animals that use a complex mixture of toxins for defense against predators.
    </p>
</abstract>

我正在尝试检索<abstract>节点之间的所有文本,包括子节点。 我可以迭代到节点并获取文本,但是迭代在“最深节点”处停止:

import xml.etree.ElementTree as ET

resXML = ET.fromstring(response)
abstract = resXML.find(".//abstract").iter()
for section in abstract:
    print section.text

> Abstract 
> Amphinomids, more commonly known as fireworms, are a basal
> lineage of marine annelids characterized by the presence of defensive
> dorsal calcareous chaetae, which break off upon contact. It has long
> been hypothesized that amphinomids are venomous and use the chaetae to
> inject a toxic substance. However, studies investigating fireworm
> venom from a morphological or molecular perspective are scarce and no
> venom gland has been identified to date, nor any toxin characterized
> at the molecular level. To investigate this question, we analyzed the
> transcriptomes of three species of fireworms— 
> Eurythoe complanata
> Hermodice carunculata 
> Paramphinome jeffreysii

显然,我的方法还不够到位。 我看不到斜体或本段其余部分的逗号: '-following a venomics...'

如何遍历所选节点下的所有节点?

ElementTree模型中,元素之后(之后为兄弟元素)的文本节点存储为该元素的尾部,而不是父元素的text 因此,除了section.text之外,您还需要查看section.tail

>>> section in abstract:
...     print section.text.strip()
...     if section.tail:
...         print section.tail.strip()
... 

Abstract

Amphinomids, more commonly known as fireworms, are a basal lineage of marine annelids characterized by the presence of defensive dorsal calcareous chaetae, which break off upon contact. It has long been hypothesized that amphinomids are venomous and use the chaetae to inject a toxic substance. However, studies investigating fireworm venom from a morphological or molecular perspective are scarce and no venom gland has been identified to date, nor any toxin characterized at the molecular level. To investigate this question, we analyzed the transcriptomes of three species of fireworms—

Eurythoe complanata
,
Hermodice carunculata
, and
Paramphinome jeffreysii
—following a venomics approach to identify putative venom compounds. Our venomics pipeline involved de novo transcriptome assembly, open reading frame, and signal sequence prediction, followed by three different homology search strategies: BLAST, HMMER sequence, and HMMER domain. Following this pipeline, we identified 34 clusters of orthologous genes, representing 13 known toxin classes that have been repeatedly recruited into animal venoms. Specifically, the three species share a similar toxin profile with C-type lectins, peptidases, metalloproteinases, spider toxins, and CAP proteins found among the most highly expressed toxin homologs. Despite their great diversity, the putative toxins identified are predominantly involved in three major biological processes: hemostasis, inflammatory response, and allergic reactions, all of which are commonly disrupted after fireworm stings. Although the putative fireworm toxins identified here need to be further validated, our results strongly suggest that fireworms are venomous animals that use a complex mixture of toxins for defense against predators.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM