XQuery:订购后返回最大值

问题描述 投票:0回答:2

我还是XQuery的新手,但是我几乎已经弄清楚了这个查询,但是它只需要返回作者最多的元素的proteinID和numberOfAuthors,但是当前它返回的是所有这些而不是仅仅作者数量最多的元素。

我的查询是

for $i in doc("proteindb.xml")/ProteinDatabase/ProteinEntry
let $author-count := count($i/reference/refinfo/authors)
let $proteinID := $i/@id
where $author-count = max($author-count)
order by $author-count descending
return ((<proteinID>{data($proteinID)}</proteinID>,
<numberOfAuthors>{data($author-count)}</numberOfAuthors>))

返回:

<proteinID>QRHUA4</proteinID>
<numberOfAuthors>47</numberOfAuthors>
<proteinID>PLHU</proteinID>
<numberOfAuthors>29</numberOfAuthors>
<proteinID>LPHUB</proteinID>
<numberOfAuthors>29</numberOfAuthors>

依此类推。

我只想返回的是第一个蛋白质编号,最高的是47,如下所示:

<proteinID>QRHUA4</proteinID>
<numberOfAuthors>47</numberOfAuthors>

我已经尝试了一些方法,例如其中的where语句

where $author-count = max($author-count)

但是它似乎实际上没有做任何事情。我还尝试了一些定位操作,仅选择了第一个索引,但它似乎仅返回ID QRHUA4,但未返回numberOfAuthors

样本XML:

  <ProteinEntry id="CCPG">
  <header>
    <uid>CCPG</uid>
    <accession>A00007</accession>
    <created_date>17-Mar-1987</created_date>
    <seq-rev_date>17-Mar-1987</seq-rev_date>
    <txt-rev_date>28-Jul-2000</txt-rev_date>
  </header>
  <protein>
    <name>cytochrome c [validated]</name>
  </protein>
  <organism>
    <source>pig</source>
    <common>domestic pig</common>
    <formal>Sus scrofa domestica</formal>
  </organism>
  <reference>
    <refinfo refid="A90743">
      <authors>
        <author>Stewart, J.W.</author>
        <author>Margoliash, E.</author>
      </authors>
      <citation>Can. J. Biochem.</citation>
      <volume>43</volume>
      <year>1965</year>
      <pages>1187-1206</pages>
      <title>The primary structure of the cytochrome c from various organs of the hog.</title>
      <xrefs>
        <xref>
          <db>MUID</db>
          <uid>66072936</uid>
        </xref>
      </xrefs>
    </refinfo>
    <accinfo label="STE">
      <accession>A00007</accession>
      <mol-type>protein</mol-type>
      <seq-spec>1-104</seq-spec>
    </accinfo>
  </reference>
  <classification>
    <superfamily>cytochrome c</superfamily>
    <superfamily>cytochrome c homology</superfamily>
  </classification>
  <keywords>
    <keyword>acetylated amino end</keyword>
    <keyword>chromoprotein</keyword>
    <keyword>electron transfer</keyword>
    <keyword>heme</keyword>
    <keyword>iron</keyword>
    <keyword>metalloprotein</keyword>
    <keyword>mitochondrion</keyword>
    <keyword>oxidative phosphorylation</keyword>
    <keyword>respiratory chain</keyword>
  </keywords>
  <feature label="CYC">
    <feature-type>domain</feature-type>
    <description>cytochrome c homology</description>
    <seq-spec>4-98</seq-spec>
  </feature>
  <feature>
    <feature-type>modified-site</feature-type>
    <description>acetylated amino end (Gly)</description>
    <seq-spec>1</seq-spec>
    <status>experimental</status>
  </feature>
  <feature>
    <feature-type>binding-site</feature-type>
    <description>heme (Cys) (covalent)</description>
    <seq-spec>14,17</seq-spec>
    <status>experimental</status>
  </feature>
  <feature>
    <feature-type>binding-site</feature-type>
    <description>heme iron (His, Met) (axial ligands)</description>
    <seq-spec>18,80</seq-spec>
    <status>predicted</status>
  </feature>
  <summary>
    <length>104</length>
    <type>complete</type>
  </summary>
  <sequence>GDVEKGKKIFVQKCAQCHTVEKGGKHKTGPNLHGLFGRKTGQAPGFSYTDANKNKGITWG
EETLMEYLENPKKYIPGTKMIFAGIKKKGEREDLIAYLKKATNE</sequence>
</ProteinEntry>
xml xpath xquery
2个回答
0
投票
嗯,您可以使用以下任一方法简单地选择结果序列中的第一项]

(for $i in doc("proteindb.xml")/ProteinDatabase/ProteinEntry let $author-count := count($i/reference/refinfo/authors) let $proteinID := $i/@id where $author-count = max($author-count) order by $author-count descending return ((<proteinID>{data($proteinID)}</proteinID>, <numberOfAuthors>{data($author-count)}</numberOfAuthors>)))[1]


0
投票
for $i in //ProteinEntry[reference/refinfo/authors/count(*) = max(//ProteinEntry/reference/refinfo/authors/count(*)) ] let $author-count := count($i/reference/refinfo/authors/author) let $proteinID := $i/@id return ((<proteinID>{$proteinID}</proteinID>, <numberOfAuthors>{$author-count}</numberOfAuthors>))
© www.soinside.com 2019 - 2024. All rights reserved.