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 organism => 'Homo sapiens',
75 'debug|d+','help|h|?','man|m');
77 pod2usage() if $options{help};
78 pod2usage({verbose=>2}) if $options{man};
80 $DEBUG = $options{debug};
84 push @USAGE_ERRORS,"You must pass something";
87 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
89 my $term = join(' ',@ARGV);
90 if ($options{symbol}) {
91 $term = join(' OR ',map {'('.$_.'[Preferred Symbol] AND '.$options{organism}.'[Orgn])'} @ARGV);
94 my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
95 -email => 'don@donarmstrong.com',
100 my @ids = $search->get_ids();
101 # print scalar(@ids)." results:\n";
103 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
104 -email => 'don@donarmstrong.com',
109 #print $esummary->get_Response()->content() if $DEBUG;
111 my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
112 for my $gene ($xml->findnodes('Entrezgene-Set/Entrezgene')) {
113 print $gene->toString if $DEBUG;
114 my ($locus) = $gene->findnodes('.//Gene-ref_locus');
115 my ($desc) = $gene->findnodes('.//Gene-ref_desc');
116 my ($summary) = $gene->findnodes('.//Entrezgene_summary');
117 my ($idiogram) = $gene->findnodes('.//Gene-ref_maploc');
118 next unless defined $idiogram;
119 my ($start) = $gene->findnodes('.//Gene-commentary_seqs/Seq-loc/Seq-loc_int/Seq-interval/Seq-interval_from');
120 my ($stop) = $gene->findnodes('.//Gene-commentary_seqs/Seq-loc/Seq-loc_int/Seq-interval/Seq-interval_to');
121 if ($options{org_mode}) {
124 print BOLD GREEN if $options{color};
125 print $locus->textContent();
127 print RESET if $options{color};
128 print "(".$idiogram->textContent();
129 print " ".$start->textContent().":";
130 print $stop->textContent().") ";
131 print BOLD CYAN if $options{color};
132 print encode_utf8($desc->textContent())."\n";
133 print RESET if $options{color};
134 print BOLD MAGENTA if $options{color};
135 if (defined $summary) {
136 if ($options{org_mode}) {
137 print "** Summary\n";
139 $summary = $summary->textContent();
140 $summary =~ s/^\s*//mg;
141 $summary = encode_utf8($summary);
142 print wrap('','',$summary);
144 print RESET if $options{color};