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);
24 pubmed_search - Search for articles on pubmed
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 'pmid_only|pmid-only',
72 'debug|d+','help|h|?','man|m');
74 pod2usage() if $options{help};
75 pod2usage({verbose=>2}) if $options{man};
77 $DEBUG = $options{debug};
81 push @USAGE_ERRORS,"You must pass something";
84 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
87 my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
88 -email => 'don@donarmstrong.com',
90 -term => join(' ',@ARGV),
93 my @ids = $search->get_ids();
94 if ($options{org_mode}) {
95 print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
97 } elsif ($options{pmid_only}) {
98 print map{qq($_\n)} @ids;
101 print scalar(@ids)." results:\n";
103 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
104 -email => 'don@donarmstrong.com',
109 my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
110 for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
111 # print $article->toString;
112 my ($pmid) = $article->findnodes('./PMID');
113 my ($title) = $article->findnodes('./Article/ArticleTitle');
114 my ($abstract) = $article->findnodes('./Article/Abstract');
115 if ($options{org_mode}) {
118 print BOLD GREEN if $options{color};
119 print $pmid->textContent();
121 print RESET if $options{color};
122 print BOLD CYAN if $options{color};
123 print encode_utf8($title->textContent())."\n";
124 print RESET if $options{color};
125 print BOLD MAGENTA if $options{color};
126 if (defined $abstract) {
127 if ($options{org_mode}) {
128 print "*** Abstract\n";
130 $abstract = $abstract->textContent();
131 $abstract =~ s/^\s*//mg;
132 $abstract =~ s/(.{,80})\s/$1\n/g;
133 $abstract = encode_utf8($abstract);
134 print wrap('','',$abstract);
136 print RESET if $options{color};