From: Don Armstrong Date: Wed, 10 Oct 2012 21:33:34 +0000 (+0000) Subject: add gene search X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=commitdiff_plain;h=c9645f6b18d502c7a599e60b772faf2914ccab98 add gene search --- diff --git a/gene_search b/gene_search new file mode 100755 index 0000000..7f1ed28 --- /dev/null +++ b/gene_search @@ -0,0 +1,132 @@ +#! /usr/bin/perl +# , and is released +# under the terms of the GPL version 2, or any later version, at your +# option. See the file README and COPYING for more information. +# Copyright 2011 by Don Armstrong . +# $Id: perl_script 1825 2011-01-02 01:53:43Z don $ + + +use warnings; +use strict; + +use Getopt::Long; +use Pod::Usage; + +use Bio::DB::EUtilities; + +use Encode qw(encode_utf8); +use Term::ANSIColor qw(:constants); +use Text::Wrap; + + +=head1 NAME + +pubmed_search - + +=head1 SYNOPSIS + + pubmed_search [options] [searchterms] + + Options: + --debug, -d debugging level (Default 0) + --help, -h display this help + --man, -m display manual + +=head1 OPTIONS + +=over + +=item B<--debug, -d> + +Debug verbosity. (Default 0) + +=item B<--help, -h> + +Display brief usage information. + +=item B<--man, -m> + +Display this manual. + +=back + +=head1 EXAMPLES + + +=cut + + +use vars qw($DEBUG); + +my %options = (debug => 0, + help => 0, + man => 0, + color => 1, + org_mode => 0, + ); + +GetOptions(\%options, + 'color|c!', + 'org_mode|org-mode', + 'debug|d+','help|h|?','man|m'); + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + +$DEBUG = $options{debug}; + +my @USAGE_ERRORS; +if (not @ARGV) { + push @USAGE_ERRORS,"You must pass something"; +} + +pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS; + +my $search = Bio::DB::EUtilities->new(-eutil => 'esearch', + -email => 'don@donarmstrong.com', + -db => 'gene', + -term => join(' ',@ARGV), + -retmax => 1000, + ); +my @ids = $search->get_ids(); +# print scalar(@ids)." results:\n"; +exit 0 unless @ids; +my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch', + -email => 'don@donarmstrong.com', + -db => 'gene', + -id => \@ids, + -retmode => 'xml', + ); +#print $esummary->get_Response()->content(); +use XML::LibXML; +my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content()); +for my $gene ($xml->findnodes('Entrezgene-Set/Entrezgene')) { + # print $article->toString; + my ($locus) = $gene->findnodes('.//Gene-ref_locus'); + my ($desc) = $gene->findnodes('.//Gene-ref_desc'); + my ($summary) = $gene->findnodes('.//Entrezgene_summary'); + if ($options{org_mode}) { + print "* "; + } + print BOLD GREEN if $options{color}; + print $locus->textContent(); + print ": "; + print RESET if $options{color}; + print BOLD CYAN if $options{color}; + print encode_utf8($desc->textContent())."\n"; + print RESET if $options{color}; + print BOLD MAGENTA if $options{color}; + if (defined $summary) { + if ($options{org_mode}) { + print "** Summary\n"; + } + $summary = $summary->textContent(); + $summary =~ s/^\s*//mg; + $summary = encode_utf8($summary); + print wrap('','',$summary); + print "\n\n"; + print RESET if $options{color}; + } +} + +__END__