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,
71 'debug|d+','help|h|?','man|m');
73 pod2usage() if $options{help};
74 pod2usage({verbose=>2}) if $options{man};
76 $DEBUG = $options{debug};
80 push @USAGE_ERRORS,"You must pass something";
83 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
86 my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
87 -email => 'don@donarmstrong.com',
89 -term => join(' ',@ARGV),
92 my @ids = $search->get_ids();
93 if ($options{org_mode}) {
94 print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
97 print scalar(@ids)." results:\n";
99 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
100 -email => 'don@donarmstrong.com',
105 my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
106 for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
107 # print $article->toString;
108 my ($pmid) = $article->findnodes('./PMID');
109 my ($title) = $article->findnodes('./Article/ArticleTitle');
110 my ($abstract) = $article->findnodes('./Article/Abstract');
111 if ($options{org_mode}) {
114 print BOLD GREEN if $options{color};
115 print $pmid->textContent();
117 print RESET if $options{color};
118 print BOLD CYAN if $options{color};
119 print encode_utf8($title->textContent())."\n";
120 print RESET if $options{color};
121 print BOLD MAGENTA if $options{color};
122 if (defined $abstract) {
123 if ($options{org_mode}) {
124 print "*** Abstract\n";
126 $abstract = $abstract->textContent();
127 $abstract =~ s/^\s*//mg;
128 $abstract =~ s/(.{,80})\s/$1\n/g;
129 $abstract = encode_utf8($abstract);
130 print wrap('','',$abstract);
132 print RESET if $options{color};