【问题标题】:Access abstract from pubmed using Bio::DB::EUtilities使用 Bio::DB::EUtilities 从 pubmed 访问摘要
【发布时间】:2013-11-07 04:37:32
【问题描述】:

我正在使用 Bio::DB::EUtilities 来查询具有给定 PMID(Pubmed Id)的 Pubmed DB。

use Bio::DB::EUtilities;

use strict;
use warnings;

my @ids = (23298400);
my $factory = Bio::DB::EUtilities->new(-eutil => 'efetch',
                                    -email => 'mymail@foo.bar',
                                    -db => 'pubmed',
                                    -retmode => 'xml',
                                    -id => \@ids);

$factory -> get_Response(-file => 'pubmed_response.xml');

有没有办法直接访问对象(例如抽象)而不是写入文件响应并使用 XML::Twig 左右?

【问题讨论】:

    标签: perl xml-parsing bioperl ncbi pubmed


    【解决方案1】:

    如果您正在寻找像$factory->get_abstract 这样的对象方法,它不存在。使用esummary 将告诉您条目是否有摘要。例如,

    #!/usr/bin/env perl
    
    use 5.010;
    use strict;
    use warnings;
    use Bio::DB::EUtilities;
    
    my @ids = (23298400);
    my $factory = Bio::DB::EUtilities->new(-eutil   => 'esummary',
                                           -email   => 'mymail@foo.bar',
                                           -db      => 'pubmed',
                                           -retmode => 'xml',
                                           -id      => \@ids);
    
    while (my $doc = $factory->next_DocSum) {
        while (my $item = $doc->next_Item('flattened')) {
            if ($item->get_name eq 'HasAbstract') {
                printf("%-20s: %s\n",$item->get_name,$item->get_content) if $item->get_content;
            }
        }
    }
    

    这只是打印,HasAbstract : 1。如果你想获得摘要,有几个选择。一种是使用efetch 返回xml,您可以存储内容而不是使用my $xml = $factory->get_Response->content 写入文件,然后在其中查找“抽象”节点。

    #!/usr/bin/env perl                                                                                                                                                
    
    use 5.010;
    use utf8;
    use strict;
    use warnings;
    use Bio::DB::EUtilities;
    use XML::LibXML;
    
    my @ids = (23298400);
    my $factory = Bio::DB::EUtilities->new(-eutil   => 'efetch',
                                           -email   => 'mymail@foo.bar',
                                           -db      => 'pubmed',
                                           -retmode => 'xml',
                                           -id      => \@ids);
    
    my $xml = $factory->get_Response->content;
    
    my $xml_parser = XML::LibXML->new();
    my $dom = $xml_parser->parse_string($xml);
    my $root = $dom->documentElement();
    
    for my $node ($root->findnodes('//*[text()]')) {
        my $name = $node->nodeName();
        if ($name eq 'Abstract') {
            for my $child ($node->findnodes('*')) {
                binmode STDOUT, ":utf8";
                say $child->textContent();
            }
        }
    }
    

    此代码打印摘要(这与我在 biostars 上提供的答案相同,但为了完整起见将其包含在此处)。另一种选择是在 Bash 脚本中使用 curl,或者在 Perl 脚本中使用 LWP::UserAgent 来自己形成查询。如果您查看EFetch 的指南,您会发现可以将retmode 设置为“文本”,将rettype 设置为“抽象”。此外,在“示例”部分下,很少有示例说明如何使用 PMID 形成查询以仅获取摘要文本。

    BioPerl 方法可以让您访问更多信息,但您可能需要自己进行一些解析(或阅读 API)。或者,您可以只获取您感兴趣的摘要,但这种方法更受限制,因为您只能获取摘要,而不是与出版物相关的其他信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 2014-11-12
      相关资源
      最近更新 更多