3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2011 by Don Armstrong <don@donarmstrong.com>.
6 # $Id: perl_script 1825 2011-01-02 01:53:43Z don $
15 use Bio::DB::EUtilities;
17 use Encode qw(encode_utf8);
18 use Term::ANSIColor qw(:constants);
28 pubmed_search [options] [searchterms]
31 --debug, -d debugging level (Default 0)
32 --help, -h display this help
33 --man, -m display manual
41 Debug verbosity. (Default 0)
45 Display brief usage information.
61 my %options = (debug => 0,
67 'debug|d+','help|h|?','man|m');
69 pod2usage() if $options{help};
70 pod2usage({verbose=>2}) if $options{man};
72 $DEBUG = $options{debug};
76 push @USAGE_ERRORS,"You must pass something";
79 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
82 my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
83 -email => 'don@donarmstrong.com',
85 -term => join(' ',@ARGV),
88 my @ids = $search->get_ids();
89 print scalar(@ids)." results:\n";
90 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
91 -email => 'don@donarmstrong.com',
96 my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
97 for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
98 # print $article->toString;
99 my ($pmid) = $article->findnodes('./PMID');
100 my ($title) = $article->findnodes('./Article/ArticleTitle');
101 my ($abstract) = $article->findnodes('./Article/Abstract');
103 print $pmid->textContent();
107 print $title->textContent()."\n";
110 $abstract = $abstract->textContent();
111 $abstract =~ s/^\s*//mg;
112 $abstract =~ s/(.{,80})\s/$1\n/g;
113 $abstract = encode_utf8($abstract);
114 print wrap('','',$abstract);