--- /dev/null
+#! /usr/bin/perl
+
+# get_genecard_results retreives files of search results from ncbi,
+# 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 2004 by Don Armstrong <don@donarmstrong.com>.
+
+# $Id: ss,v 1.1 2004/06/29 05:26:35 don Exp $
+
+
+use warnings;
+use strict;
+
+
+use Getopt::Long;
+use Pod::Usage;
+
+=head1 NAME
+
+ get_genecard_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_harvester_results -D ./harvester_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::ParamMunge;
+use LWP::UserAgent;
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ format => 'xml',
+ database => 'gene',
+ dir => '.',
+ name => '${search}_results_genecard',
+ terms => '-',
+ genecard_site => 'http://bioinfo.weizmann.ac.il/cards-bin/',
+ genecard_search_url => 'cardsearch.pl?search_type=keyword%28s%29&search=complement',
+ );
+
+GetOptions(\%options,'format|f=s','database|b=s','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}: $!";
+}
+
+my $ua = new LWP::UserAgent(agent=>"DA_get_harvester_results/$REVISION");
+
+#For every term
+while (<$terms>) {
+ # Get uids to retrieve
+ chomp;
+ my $search = $_;
+ my $url = uri_param_munge($options{genecard_site}.$options{genecard_search_url},
+ {search => $search,
+ },
+ );
+ my $request = HTTP::Request->new('GET', $url);
+ my $response = $ua->request($request);
+ $response = $response->content;
+ my @result_urls = $response =~ m#<a\s+href=\"(carddisp?[^\"]+)\"\s*>\s+<b>Display</b>\s*<font size=-1>\s*<br>\s*the<b>\s*complete#sg;
+
+ my $dir_name = eval qq("$options{name}") or die $@;
+ mkdir("$options{dir}/$dir_name") or die "Unable to make directory $options{dir}/$dir_name $!";
+ # Get XML file
+ my @current_urls;
+ while (@current_urls = map{$options{genecard_site}.$_} splice(@result_urls,0,30)) {
+ system(q(wget),'-nd','-nH','-w','2','--random-wait','-P',qq($options{dir}/$dir_name),@current_urls) == 0 or warn "$!";
+ }
+}
+
+
+
+
+
+
+__END__