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

2024-04-23 07:14:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用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...'

如何遍历所选节点下的所有节点?你知道吗


Tags: andofthetoabstract节点thatare
1条回答
网友
1楼 · 发布于 2024-04-23 07:14:47

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.

相关问题 更多 >