X-Git-Url: https://git.donarmstrong.com/?p=function2gene.git;a=blobdiff_plain;f=bin%2Fget_uniprot_results;fp=bin%2Fget_uniprot_results;h=680e8500193b4bc4d968362894f666f8a538ed41;hp=0000000000000000000000000000000000000000;hb=1e24111af3bd3cb2b5795a64756c8b2fb05be8b5;hpb=63fb26c8c37a0ea5af1cfc32efaad55d4c32b596 diff --git a/bin/get_uniprot_results b/bin/get_uniprot_results new file mode 100755 index 0000000..680e850 --- /dev/null +++ b/bin/get_uniprot_results @@ -0,0 +1,147 @@ +#! /usr/bin/perl + +# get_uniprot_results retreives files of search results from uniprot, +# 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 2008 by Don Armstrong . + + +use warnings; +use strict; + + +use Getopt::Long; +use Pod::Usage; + +=head1 NAME + + get_uniprot_results [options] + +=head1 SYNOPSIS + + + Options: + --dir, -D directory to stick results into [default .] + --name, -n file naming scheme [default ${search}_results.$format] + --terms, -t file of search terms [default -] + --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 useage information. + +=item B<--man, -m> + +Display this manual. + +=back + +=head1 EXAMPLES + + get_uniprot_results -D ./uniprot_results/ -n '${search}_name.html' < search_parameters + +Will pretty much do what you want + +=cut + + + +use vars qw($DEBUG $REVISION); + +BEGIN{ + ($REVISION) = q$LastChangedRevision: 1$ =~ /LastChangedRevision:\s+([^\s]+)/; + $DEBUG = 0 unless defined $DEBUG; +} + +use IO::File; +use URI; +use WWW::Mechanize; +use Time::HiRes qw(usleep); + +# XXX parse config file + +my %options = (debug => 0, + help => 0, + man => 0, + dir => '.', + name => '${search}_results_uniprot', + terms => '-', + uniprot_site => 'http://ca.expasy.org', + uniprot_search_url => '/cgi-bin/sprot-search-ful?S=on&T=on', + ); + +GetOptions(\%options,'name|n=s', + 'terms|t=s','dir|D=s','debug|d+','help|h|?','man|m'); + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + +$DEBUG = $options{debug}; + +if (not -d $options{dir}) { + die "$options{dir} does not exist or is not a directory"; +} + +#open search terms file +my $terms; +if ($options{terms} eq '-') { + $terms = \*STDIN; +} +else { + $terms = new IO::File $options{terms}, 'r' or die "Unable to open file $options{terms}: $!"; +} + +#For every term +while (<$terms>) { + # Get uids to retrieve + chomp; + s/\r$//g; + my $search = $_; + my $dir_name = eval qq("$options{name}") or die $@; + if (not -d "$options{dir}/$dir_name") { + mkdir("$options{dir}/$dir_name") or die "Unable to make directory $options{dir}/$dir_name $!"; + } + my $uri = URI->new($options{uniprot_site}.$options{uniprot_search_url}); + $uri->query_form($uri->query_form(), + SEARCH => $search, + ); + my $url = $uri->as_string; + my $mech = WWW::Mechanize->new(agent=>"DA_get_uniprot_results/$REVISION"); + print "retreived $url\n"; + $mech->get($url); + my @links = $mech->find_all_links(text_regex=>qr/_HUMAN/); + for my $gene_link (@links) { + my $gene_url = $gene_link->url_abs->as_string; + print STDERR "saving $gene_url\n"; + $mech->get($gene_url); + $mech->follow_link(text_regex => qr/View\s*entry\s*in\s*raw\s*text\s*format/); + my $cleaned_url = $gene_url; + $cleaned_url =~ s{http://}{}g; + $cleaned_url =~ s/[^\w]//g; + eval { + $mech->save_content($options{dir}.'/'.$dir_name.'/'.$cleaned_url); + }; + if ($@) { + warn $@; + } + } +} + + + + + + +__END__