]> git.donarmstrong.com Git - bin.git/commitdiff
allow outputting pubmed ids only
authorDon Armstrong <don@donarmstrong.com>
Mon, 18 Nov 2013 22:53:02 +0000 (14:53 -0800)
committerDon Armstrong <don@donarmstrong.com>
Mon, 18 Nov 2013 22:53:02 +0000 (14:53 -0800)
pubmed_search

index b3367d934497f13391a79cbadb62391aaabc9d05..7b3041ed43b4f552bebb1082e9b2c185e8a6910b 100755 (executable)
@@ -21,7 +21,7 @@ use Text::Wrap;
 
 =head1 NAME
 
-pubmed_search - 
+pubmed_search - Search for articles on pubmed
 
 =head1 SYNOPSIS
 
@@ -66,9 +66,10 @@ my %options = (debug           => 0,
               );
 
 GetOptions(\%options,
-          'color|c!',
-          'org_mode|org-mode',
-          'debug|d+','help|h|?','man|m');
+           'color|c!',
+           'org_mode|org-mode',
+           'pmid_only|pmid-only',
+           'debug|d+','help|h|?','man|m');
 
 pod2usage() if $options{help};
 pod2usage({verbose=>2}) if $options{man};
@@ -84,23 +85,26 @@ pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
 
 
 my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
-                                      -email => 'don@donarmstrong.com',
-                                      -db    => 'pubmed',
-                                      -term => join(' ',@ARGV),
-                                      -retmax => 1000,
-                                     );
+                                      -email => 'don@donarmstrong.com',
+                                      -db    => 'pubmed',
+                                      -term => join(' ',@ARGV),
+                                      -retmax => 1000,
+                                     );
 my @ids = $search->get_ids();
 if ($options{org_mode}) {
     print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
     print "  + ";
+} elsif ($options{pmid_only}) {
+    print map{qq($_\n)} @ids;
+    exit 0;
 }
 print scalar(@ids)." results:\n";
 exit 0 unless @ids;
 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
-                                       -email => 'don@donarmstrong.com',
-                                       -db    => 'pubmed',
-                                       -id  => \@ids
-                                      );
+                                        -email => 'don@donarmstrong.com',
+                                        -db    => 'pubmed',
+                                        -id  => \@ids
+                                       );
 use XML::LibXML;
 my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
 for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
@@ -109,7 +113,7 @@ for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation
     my ($title) = $article->findnodes('./Article/ArticleTitle');
     my ($abstract) = $article->findnodes('./Article/Abstract');
     if ($options{org_mode}) {
-       print "** PMID: ";
+        print "** PMID: ";
     }
     print BOLD GREEN if $options{color};
     print $pmid->textContent();
@@ -120,16 +124,16 @@ for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation
     print RESET if $options{color};
     print BOLD MAGENTA if $options{color};
     if (defined $abstract) {
-       if ($options{org_mode}) {
-           print "*** Abstract\n";
-       }
-       $abstract = $abstract->textContent();
-       $abstract =~ s/^\s*//mg;
-       $abstract =~ s/(.{,80})\s/$1\n/g;
-       $abstract = encode_utf8($abstract);
-       print wrap('','',$abstract);
-       print "\n\n";
-       print RESET if $options{color};
+        if ($options{org_mode}) {
+            print "*** Abstract\n";
+        }
+        $abstract = $abstract->textContent();
+        $abstract =~ s/^\s*//mg;
+        $abstract =~ s/(.{,80})\s/$1\n/g;
+        $abstract = encode_utf8($abstract);
+        print wrap('','',$abstract);
+        print "\n\n";
+        print RESET if $options{color};
     }
 }