3 # get_uniprot_results retreives files of search results from uniprot,
4 # and is released under the terms of the GPL version 2, or any later
5 # version, at your option. See the file README and COPYING for more
8 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
20 get_uniprot_results [options]
26 --dir, -D directory to stick results into [default .]
27 --name, -n file naming scheme [default ${search}_results.$format]
28 --terms, -t file of search terms [default -]
29 --debug, -d debugging level [default 0]
30 --help, -h display this help
31 --man, -m display manual
39 Debug verbosity. (Default 0)
43 Display brief useage information.
53 get_uniprot_results -D ./uniprot_results/ -n '${search}_name.html' < search_parameters
55 Will pretty much do what you want
61 use vars qw($DEBUG $REVISION);
64 ($REVISION) = q$LastChangedRevision: 1$ =~ /LastChangedRevision:\s+([^\s]+)/;
65 $DEBUG = 0 unless defined $DEBUG;
71 use Time::HiRes qw(usleep);
73 # XXX parse config file
75 my %options = (debug => 0,
79 name => '${search}_results_uniprot',
81 uniprot_site => 'http://ca.expasy.org',
82 uniprot_search_url => '/cgi-bin/sprot-search-ful?S=on&T=on',
85 GetOptions(\%options,'name|n=s',
86 'terms|t=s','dir|D=s','debug|d+','help|h|?','man|m');
88 pod2usage() if $options{help};
89 pod2usage({verbose=>2}) if $options{man};
91 $DEBUG = $options{debug};
93 if (not -d $options{dir}) {
94 die "$options{dir} does not exist or is not a directory";
97 #open search terms file
99 if ($options{terms} eq '-') {
103 $terms = new IO::File $options{terms}, 'r' or die "Unable to open file $options{terms}: $!";
108 # Get uids to retrieve
112 my $dir_name = eval qq("$options{name}") or die $@;
113 if (not -d "$options{dir}/$dir_name") {
114 mkdir("$options{dir}/$dir_name") or die "Unable to make directory $options{dir}/$dir_name $!";
116 my $uri = URI->new($options{uniprot_site}.$options{uniprot_search_url});
117 $uri->query_form($uri->query_form(),
120 my $url = $uri->as_string;
121 my $mech = WWW::Mechanize->new(agent=>"DA_get_uniprot_results/$REVISION");
122 print "retreived $url\n";
124 my @links = $mech->find_all_links(text_regex=>qr/_HUMAN/);
125 for my $gene_link (@links) {
126 my $gene_url = $gene_link->url_abs->as_string;
127 print STDERR "saving $gene_url\n";
128 $mech->get($gene_url);
129 $mech->follow_link(text_regex => qr/View\s*entry\s*in\s*raw\s*text\s*format/);
130 my $cleaned_url = $gene_url;
131 $cleaned_url =~ s{http://}{}g;
132 $cleaned_url =~ s/[^\w]//g;
134 $mech->save_content($options{dir}.'/'.$dir_name.'/'.$cleaned_url);