--- /dev/null
+#! /usr/bin/perl
+
+# parse_ncbi_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
+
+ parse_ncbi_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
+
+ parse_ncbi_results -D ./ncbi_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 XML::Parser::Expat;
+use IO::File;
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ dir => '.',
+ keyword => undef,
+ );
+
+GetOptions(\%options,'keyword|k=s','debug|d+','help|h|?','man|m');
+
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+# CSV columns
+use constant {NAME => 0,
+ REFSEQ => 1,
+ LOCATION => 2,
+ ALIAS => 3,
+ FUNCTION => 4,
+ DESCRIPTION => 5,
+ KEYWORD => 6,
+ DBNAME => 7,
+ FILENAME => 8,
+ };
+
+my @csv_fields = qw(name hits rzscore refseq location alias database terms description function);
+
+my %genes;
+
+for my $file_name (@ARGV) {
+ my $file = new IO::File $file_name, 'r' or die "Unable to open file $file_name $!";
+ while (<$file>) {
+ next if /^"Name"/;
+ my @gene = map {s/^\"//; s/\"$//; $_;} split /(?<=\")\,(?=\")/, $_;
+ $genes{$gene[NAME]}{name} = $gene[NAME];
+ $genes{$gene[NAME]}{database}{$gene[DBNAME]}++;
+ $genes{$gene[NAME]}{hits}++;
+ $genes{$gene[NAME]}{terms}{$gene[KEYWORD]}++;
+ add_unique_parts($genes{$gene[NAME]},'refseq',$gene[REFSEQ]);
+ add_if_better($genes{$gene[NAME]},'description',$gene[DESCRIPTION]);
+ add_if_better($genes{$gene[NAME]},'location',$gene[LOCATION]);
+ add_unique_parts($genes{$gene[NAME]},'function',split(/; /, $gene[FUNCTION]));
+ add_unique_parts($genes{$gene[NAME]},'alias', split(/; /, $gene[ALIAS]));
+ }
+}
+
+print join(',',map {qq("$_")} @csv_fields),qq(\n);
+for my $gene (keys %genes) {
+ $genes{$gene}{rzscore} = scalar keys %{$genes{$gene}{terms}};
+ next if $genes{$gene}{rzscore} == 1 and exists $genes{$gene}{terms}{antigen};
+ $genes{$gene}{rzscore} -= 1 if exists $genes{$gene}{terms}{antigen};
+ print STDOUT join (',',
+ map {s/"//g; qq("$_")}
+ map {
+ my $value = $_;
+ if (ref $value eq 'HASH') {
+ join('; ',map {qq($_:$$value{$_})} keys %$value);
+ }
+ elsif (ref $value eq 'ARRAY') {
+ join('; ', @$value);
+ }
+ else {
+ $value;
+ }
+ } @{$genes{$gene}}{@csv_fields}
+ ), qq(\n);
+}
+
+
+sub add_unique_parts{
+ my ($hr,$key,@values) = @_;
+ if (not defined $$hr{key}) {
+ $$hr{$key} = [@values];
+ }
+ else {
+ my %temp_hash;
+ @temp_hash{@{$$hr{$key}}} = (1) x scalar @{$$hr{$key}};
+ $temp_hash{@values} = (1) x scalar @values;
+ $$hr{$key} = [keys %temp_hash];
+ }
+}
+
+sub add_if_better{
+ my ($hash, $key, $value) = @_;
+ if (not defined $$hash{$key}) {
+ $$hash{$key} = $value;
+ }
+ elsif (length $$hash{$key} < length $value and $value !~ /^NO\s+(LOCATION|DESCRIPTION)+$/) {
+ $$hash{$key} = $value;
+ }
+}
+
+
+
+
+__END__
--- /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__
--- /dev/null
+#! /usr/bin/perl
+
+# get_harvester_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_harvester_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_harvester',
+ terms => '-',
+ harvester_site => 'http://www-db.embl.de',
+ harvester_search_url => '/jss/servlet/de.embl.bk.htmlfind.HarvesterPageSearchOutput?search=GOLGI&chipsetID=-1&maxHits=10000&submit=search',
+ );
+
+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{harvester_site}.$options{harvester_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=(http://harvester.embl.de/harvester/[^\/]+/[^.]+.htm)\s*>#g;
+
+ 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 = 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__
--- /dev/null
+#! /usr/bin/perl
+
+# get_location_from_uniprot 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_location_from_uniprot [options]
+
+=head1 SYNOPSIS
+
+
+ Options:
+ --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_location_from_uniprot -t terms.txt > output.txt
+
+Will pretty much do what you want
+
+=cut
+
+# http://www.ebi.uniprot.org/uniprot-srv/extendedView.do?proteinId=1A01_HUMAN
+
+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_harvester',
+ terms => '-',
+ uniprot_site => 'http://www.ebi.uniprot.org',
+ uniprot_search_url => '/uniprot-srv/extendedView.do?proteinId=1A01_HUMAN',
+ );
+
+GetOptions(\%options,'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};
+
+use constant {NAME => 0,
+ LOCATION => 1,
+ FULLNAME => 2,
+ };
+
+#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_location_from_uniprot/$REVISION");
+
+#For every term
+print STDOUT qq("NAME","LOCATION","FULL NAME"\n);
+while (<$terms>) {
+ my @gene;
+ # Get uids to retrieve
+ chomp;
+ my $search = $_;
+ my $url = uri_param_munge($options{uniprot_site}.$options{uniprot_search_url},
+ {proteinId => $search,
+ },
+ );
+ my $request = HTTP::Request->new('GET', $url);
+ my $response = $ua->request($request);
+ $response = $response->content;
+ $gene[NAME] = $search;
+ ($gene[LOCATION]) = $response =~ m{<!--Chromosome\s+locus-->\s*<tr>\s*
+ <td\s+class="import_title"\s+valign="top"> </td>\s*
+ <td\s+class="value"\s+colspan="5">\s*
+ <table\s+width="100%"><tr\s+class="value"><td>Gene\s+name:[^\&]+ Location:([^\<]+)</td></tr>\s*
+ </table></td></tr>\s*
+ <!--\s*end\s+chromosome\s+locus\s+-->}xis;
+ ($gene[FULLNAME]) = $response =~ m{>Protein\s+name</a>\s*
+ </td>\s*<td\s+class="value"\s+colspan="5">\s*
+ <b>([^\<]+)</b>\s*
+ </td>\s*</tr>\s*<!--end\s+title-->}xis;
+ print STDOUT join(',', map {if (defined $_) {qq("$_");} else {qq("NO DATA");}} @gene[0..2]),qq(\n);
+ sleep 2;
+}
+
+
+
+
+
+
+__END__
--- /dev/null
+#! /usr/bin/perl
+
+# get_ncbi_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_ncbi_results [options]
+
+get_ncbi_results - Retrieve search results from NCBI using parameters
+passed on stdin.
+
+=head1 SYNOPSIS
+
+
+ Options:
+ --format, -f format of search results to return [default xml]
+ --database, -b database to search for results [default gene]
+ --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_ncbi_results -f xml -b gene -D ./results/ -n '${search}_name.xml' < 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.$format',
+ terms => '-',
+ pubmed_site => 'http://www.ncbi.nlm.nih.gov',
+ pubmed_search_url => '/entrez/query.fcgi?db=gene&cmd=search&term=12q24*+AND+homo[Orgn]&doptcmdl=Brief&dispmax=1000',
+ pubmed_get_url => '/entrez/query.fcgi?db=gene&cmd=Text&dopt=XML',
+ );
+
+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_ncbi_results/$REVISION");
+
+#For every term
+while (<$terms>) {
+ # Get uids to retrieve
+ chomp;
+ my $search = $_;
+ my $format = $options{format};
+ my $url = uri_param_munge($options{pubmed_site}.$options{pubmed_search_url},
+ {term => $search,
+ db => $options{database},
+ },
+ );
+ my $request = HTTP::Request->new('GET', $url);
+ my $response = $ua->request($request);
+ $response = $response->content;
+ my @gene_ids = $response =~ m/\[GeneID\:\s+(\d+)\]/g;
+
+ my $file_name = eval qq("$options{name}") or die $@;
+ my $xml_file = new IO::File "$options{dir}/$file_name", 'w' or die "Unable to open $options{dir}/$file_name: $!";
+
+ # Get XML file
+ my @current_ids;
+ while (@current_ids = splice(@gene_ids,0,20)) {
+ $url = uri_param_munge($options{pubmed_site}.$options{pubmed_get_url},
+ {dopt => uc($options{format}),
+ db => $options{database},
+ },
+ ) .'&' . join('&',map {qq(uid=$_)} @current_ids);
+ $request = HTTP::Request->new('GET', $url);
+ $response = $ua->request($request);
+ $response = $response->content;
+ # For some dumb reason, they send us xml with html
+ # entities. Ditch them.
+ #$response = decode_entities($response);
+ $response =~ s/\>/>/gso;
+ $response =~ s/\</</gso;
+ $response =~ s/"/"/gso;
+
+ # They also affix a <pre> and suffix a </pre> ditch them.
+ $response =~ s/^\s*<pre>//gso;
+ $response =~ s#</pre>\s*$##gso;
+
+ $response =~ s#<\?xml[^>]+>##gso;
+ $response =~ s#<!DOCTYPE[^>]+>##gso;
+
+ print {$xml_file} $response;
+ sleep 10;
+ }
+ undef $xml_file;
+}
+
+
+
+
+
+
+__END__
--- /dev/null
+#! /usr/bin/perl
+
+use warnings;
+use strict;
+
+while (<>) {
+ chomp;
+ my @names = split /;\s*/;
+ @names = sort {length $b <=> length $a } @names;
+ # pick the longest name
+ my $name = $names[0];
+ # strip out long parenthetical statements
+ $name =~ s/[\[\(][^\]\)]{10,}[\]\)]//g;
+ $name =~ s/(\s)\s+/$1/g;
+ print $name,qq(\n);
+}
--- /dev/null
+#! /usr/bin/perl
+
+# parse_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
+
+ parse_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
+
+ parse_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 IO::Dir;
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ dir => '.',
+ keyword => undef,
+ );
+
+GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m');
+
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+# CSV columns
+use constant {NAME => 0,
+ REFSEQ => 1,
+ LOCATION => 2,
+ ALIAS => 3,
+ FUNCTION => 4,
+ DESCRIPTION => 5,
+ KEYWORD => 6,
+ DBNAME => 7,
+ FILENAME => 8,
+ };
+
+if (not -d $options{dir}) {
+ die "$options{dir} does not exist or is not a directory";
+}
+
+my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
+
+print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
+
+while ($_ = $dir->read) {
+ my $file_name = $_;
+ next if $file_name =~ /^\./;
+ next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
+
+ my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
+
+ local $/;
+ my $result = <$file>;
+
+ my @results;
+
+ # Find gene name
+ ($results[NAME]) = $result =~ m&(?:Lean|Gene)Card\s+for\s+(?:(?:disorder\s+locus|uncategorized|
+ hugo\s*reserved\s*symbol|cluster|
+ potentially\s*expressed\s*sequence)|(?:predicted\s+|pseudo|rna\s+|)gene)
+ \s*(?:with\s*support\s*|)<FONT\s+COLOR=\"[^\"]+\">\s*<FONT\s+SIZE=\+2>\s*([^\s]+)\s*&xis;
+
+ $results[NAME] ||= 'NO NAME';
+ # Find REF SEQ number
+ ($results[REFSEQ]) = $result =~ m|http://www.ncbi.nlm.nih.gov/entrez/query.fcgi\?
+ cmd=Search\&db=nucleotide\&doptcmdl=GenBank\&term=([^\"]+)\"|xis;
+
+ $results[REFSEQ] ||= 'NO REFSEQ';
+
+ # Find Gene Location
+ ($results[LOCATION]) = $result =~ m&<I>LocusLink\s+cytogenetic\s+band:</I><b>\s+
+ <a\s+href="[^\"]+"\s+target\s+=\s+"aaa">\s*([^\<]+?)\s*</a>&xis;
+
+ $results[LOCATION] ||= 'NO LOCATION';
+
+ # Find gene aliases
+ my ($alias_table) = $result =~ m|<b>Aliases and Descriptions</b>(.+?)</TR>|is;
+ $alias_table ||='';
+
+ my @gene_aliases = $alias_table =~ m|<li>\s*([^\(]{0,20}?)\s*\(<FONT|gis;
+
+ $results[ALIAS] = join('; ', @gene_aliases);
+ $results[ALIAS] ||= 'NO ALIASES';
+
+ # Find gene function(s)
+
+ # Swiss prot functions
+ my @functions = $result =~ m&<li><b>Function:</b>\s+(.+?)(?:<li>)|(?:</ul>)&gis;
+
+ # GO Functions
+ push @functions, (map {s#\s*</a>\s*# #g; $_;} $result =~ m&(GO:\d+\s*</a>.+?)(?:<dd>|<p>)&gis);
+ $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
+ $results[FUNCTION] ||= 'NO FUNCTION';
+
+ # Figure out the keyword used
+ ($results[KEYWORD]) = $file_name =~ /search=([^&]+)/;
+
+ $results[KEYWORD] ||= 'NO KEYWORD';
+
+ # Figure out what the description is
+ $results[DESCRIPTION] = '';
+
+ # Database searched
+ $results[DBNAME] = 'genecard';
+ $results[FILENAME] = $file_name;
+
+ print join(',',map {qq("$_")} @results),qq(\n);
+}
+
+
+
+
+
+
+__END__
--- /dev/null
+#! /usr/bin/perl
+
+# parse_harvester_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
+
+ parse_harvester_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
+
+ parse_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 IO::Dir;
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ dir => '.',
+ keyword => undef,
+ );
+
+GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m');
+
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+# CSV columns
+use constant {NAME => 0,
+ REFSEQ => 1,
+ LOCATION => 2,
+ ALIAS => 3,
+ FUNCTION => 4,
+ DESCRIPTION => 5,
+ KEYWORD => 6,
+ DBNAME => 7,
+ FILENAME => 8,
+ };
+
+if (not -d $options{dir}) {
+ die "$options{dir} does not exist or is not a directory";
+}
+
+my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
+
+print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
+
+my ($keyword) = $options{keyword} || $options{dir} =~ m#(?:^|/)([^\/]+)_results_harvester#;
+
+while ($_ = $dir->read) {
+ my $file_name = $_;
+ next if $file_name =~ /^\./;
+ next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
+
+ my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
+
+ local $/;
+ my $result = <$file>;
+
+ my @results;
+
+ # Find gene name
+ ($results[NAME]) = $result =~ m&<img\s+src=\"http://genome-www5.stanford.edu/images/SOURCE/hsgr.gif\"\s*/>
+ </td><td\s+bgcolor="tomato"\s+colspan="1"><center><font\s+size="\+5"
+ \s+color="white">([^<]+)</font></center>&xis;
+
+ if (not defined $results[NAME]) {
+ ($results[NAME]) = $result =~ m&<TR>\s*<TD\s*BGCOLOR="\#FEFE99"\s*VALIGN="top"\s*NOWRAP>Entry\s*name</TD>\s*
+ <TD\s*VALIGN="top"\s*COLSPAN="5">\s*<b>\s*([^<]+?)\s*</b></TD>\s*</TR>&xis;
+ }
+
+ $results[NAME] ||= 'NO NAME';
+
+ # Find REF SEQ number
+ ($results[REFSEQ]) = $result =~ m&<a\s+href="http://www.ncbi.nlm.nih.gov/entrez/
+ query.fcgi\?db=Nucleotide\&cmd=Search\&term=([^\&]+)\&doptcmdl=GenBank">&xis;
+
+ $results[REFSEQ] ||= 'NO REFSEQ';
+
+ # Find Chromosomal Location
+ ($results[LOCATION]) = $result =~ m&Chromosomal\s+Location</font></td></tr>\s+<tr><td\s+colspan="1"\s+bgcolor="beige"><dl>
+ <dd><b>Chromosome/Cytoband</b></td><td\s+width="525"><center>\s*([^\<]+?)\s*</center>&xis;
+
+ $results[LOCATION] ||= 'NO LOCATION';
+ # Find gene aliases
+ # SOURCE ALIASES
+ my ($alias_table) = $result =~ m|Aliases</font></td></tr>\s*<tr><td\s+bgcolor=\"beige\"\s+colspan=\"2\">
+ <font\s+size=\"-1\"\s*/>\s+<ul>(.+?)</ul>|xis;
+ $alias_table ||='';
+
+ my @gene_aliases = $alias_table =~ m&<li>\s*([^\(\<]{0,30}?)\s*(?:\<|\()&gis;
+
+ # UNIPROT ALIASES
+ push @gene_aliases, $result =~ m&<TR>\s*<TD\s+BGCOLOR=\"\#CECFCE\"\s+VALIGN=\"top\"\s+NOWRAP>\s*Synonym\(s\)\s*</TD>\s*
+ <TD\s+VALIGN=\"top\"\s+COLSPAN=\"\d\">\s*([^<]+?)\s*</TD>\s*</TR>&xis;
+ push @gene_aliases, $result =~ m&<TD\s+BGCOLOR=\"\#CECFCE\"\s+VALIGN=\"top\"\s*>\s*Description\s*</TD>\s*
+ <TD\s+VALIGN=\"top\"\s+COLSPAN=\"\d\">\s*([^<]+?)\s*</TD>\s*</TR>&xis;
+
+ $results[ALIAS] = join('; ', @gene_aliases);
+ $results[ALIAS] ||= 'NO ALIASES';
+
+ # Find gene function(s)
+
+ # Stanford GO functions
+ my ($gene_ontology) = $result =~ m&<table\s+width="100%"\s+cellspacing="0"\s+border="1"><tr>\s*
+ <th\s+valign="middle"\s+align="left"\s+bgcolor="\#CCCCCC">Ontology</th>\s*(.+?)</table>&xis;
+
+ my @functions;
+ push @functions, map {s#\s*\"\>\s*# #g; $_;} $gene_ontology =~ m&<a\s+href="http://godatabase.org/cgi-bin/go.cgi\?view=details
+ \&depth=1\&query=([^\"]+\">[^\<]+)</a>&gxis
+ if defined $gene_ontology;
+
+ # UNIPROT GO Functions
+ push @functions, map {s#\s*</a>\;?\s*# #g; $_;} m&<TD\s+VALIGN="top"\s+COLSPAN="5">
+ <a\s+href="http://www.ebi.ac.uk/ego/GSearch\?query=[^\&+]\&mode=id">
+ (GO\:\d+</a>\;\s+[^\<]+?)\s*</TD>&xgis;
+
+ $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
+ $results[FUNCTION] ||= 'NO FUNCTION';
+
+ # Figure out the keyword used
+ $results[KEYWORD] = $keyword;
+
+ $results[KEYWORD] ||= 'NO KEYWORD';
+
+ # Figure out what the description is
+ ($results[DESCRIPTION]) = map{s#\n# #g; $_;} $result =~ m&<b>Locus\s+Link\s+Summary</b></td><td\s+width="\d+">(.+?)\s*</td>\s*</tr>&is;
+ if (not defined $results[DESCRIPTION]) {
+ ($results[DESCRIPTION]) = map{s#\n# #g; $_;} $result =~ m&<TD\s+BGCOLOR="\#CECFCE"\s+VALIGN="center"\s+COLSPAN="2">
+ <FONT\s+face="verdana,helvetica,arial,sans-serif"><B>FUNCTION</B></TD>\s*
+ <TD\s+VALIGN="top"\s+COLSPAN="4">([^\<]+)</TD>\s*</TR>&xis;
+ }
+ $results[DESCRIPTION] ||= '';
+
+ # Database searched
+ $results[DBNAME] = 'harvester';
+ $results[FILENAME] = $file_name;
+
+ print join(',',map {qq("$_")} @results),qq(\n);
+}
+
+
+
+
+
+
+__END__
--- /dev/null
+#! /usr/bin/perl
+
+# parse_ncbi_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
+
+ parse_ncbi_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
+
+ parse_ncbi_results -D ./ncbi_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 XML::Parser::Expat;
+use IO::File;
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ dir => '.',
+ keyword => undef,
+ );
+
+GetOptions(\%options,'keyword|k=s','debug|d+','help|h|?','man|m');
+
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+# CSV columns
+use constant {NAME => 0,
+ REFSEQ => 1,
+ LOCATION => 2,
+ ALIAS => 3,
+ FUNCTION => 4,
+ DESCRIPTION => 5,
+ KEYWORD => 6,
+ DBNAME => 7,
+ FILENAME => 8,
+ };
+
+my $current_gene = undef;
+my $keyword = undef;
+my $file_name = undef;
+my ($within_GO,$mrna_ref_seq) = 0,0;
+
+sub tag_start{
+ my ($expat, $element, %attr) = @_;
+
+ local $_ = lc $element;
+ if ($_ eq 'entrezgene') {
+ $current_gene = [];
+ $$current_gene[KEYWORD] = $keyword;
+ $$current_gene[DBNAME] = 'ncbi';
+ $$current_gene[FILENAME] = $file_name;
+ }
+}
+
+sub tag_content {
+ my ($expat, $string) = @_;
+
+ return unless defined $current_gene;
+
+ local $_ = lc $expat->current_element;
+
+ if ($_ eq 'gene-ref_locus') {
+ $$current_gene[NAME] = $string;
+ }
+ elsif ($_ eq 'gene-ref_maploc') {
+ $$current_gene[LOCATION] = $string;
+ }
+ elsif ($_ eq 'gene-ref_desc') {
+ push @{$$current_gene[ALIAS]}, $string;
+ }
+ elsif ($_ eq 'prot-ref_name_e' or $_ eq 'gene-ref_syn_e') {
+ push @{$$current_gene[ALIAS]}, $string;
+ }
+ elsif ($_ eq 'entrezgene_summary') {
+ $$current_gene[DESCRIPTION] = $string;
+ }
+ elsif ($_ eq 'gene-commentary_heading') {
+ $within_GO = 0;
+ $mrna_ref_seq = 0;
+ $within_GO = 1 if $string =~ /GeneOntology/;
+ $mrna_ref_seq = 1 if $string =~ /mRNA Sequence/i;
+ }
+ elsif ($_ eq 'other-source_anchor') {
+ return unless $within_GO;
+ push @{$$current_gene[FUNCTION]}, $string;
+ }
+ elsif ($_ eq 'gene-commentary_accession') {
+ return unless $expat->within_element('Gene-commentary_products');
+ $$current_gene[REFSEQ] ||= $string;
+ }
+}
+
+sub tag_stop {
+ my ($expat, $element) = @_;
+
+ local $_ = lc $element;
+ if ($_ eq 'entrezgene') {
+ # If current_gene is defined, output the current gene information
+ if (defined $current_gene and @$current_gene) {
+ $$current_gene[NAME] ||= ${$$current_gene[ALIAS]}[1] if defined $$current_gene[ALIAS];
+ for (qw(NAME REFSEQ LOCATION ALIAS
+ FUNCTION DESCRIPTION KEYWORD DBNAME
+ FILENAME)) {
+ $$current_gene[eval "$_"] ||= "NO $_";
+ }
+ print STDOUT join(',', map {$_ = join('; ', @$_) if ref $_; qq("$_");} @$current_gene),qq(\n);
+ undef $current_gene;
+ }
+ }
+}
+
+my $parser = new XML::Parser::Expat;
+$parser->setHandlers('Start' => \&tag_start,
+ 'End' => \&tag_stop,
+ 'Char' => \&tag_content
+ );
+
+for (@ARGV) {
+ $file_name = $_;
+ ($keyword) = $options{keyword} || $file_name =~ m#(?:^|/)([^\/]+?)[\s-]+AND[\s\-].+_results.xml$#;
+ print STDOUT join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
+ my $file = new IO::File $file_name, 'r' or die "Unable to open file $file_name $!";
+
+ $parser->parse($file);
+
+ undef $file;
+}
+
+
+
+
+
+
+__END__
--- /dev/null
+#! /usr/bin/perl
+
+
+=head1 NAME
+
+stupid_missing_names -
+
+=head1 SYNOPSIS
+
+Some of the genes don't actually have locations. This misnamed script
+is designed to take the names of those missing locations and try to
+figure out where the actual genes are located.
+
+=head1 DESCRIPTION
+
+
+
+=cut
+
+
+use warnings;
+use strict;
+
+
+use vars qw($DEBUG $REVISION);
+
+BEGIN{
+ ($REVISION) = q$LastChangedRevision: 1$ =~ /LastChangedRevision:\s+([^\s]+)/;
+ $DEBUG = 0 unless defined $DEBUG;
+}
+
+use URI::ParamMunge;
+use LWP::UserAgent;
+
+# XXX parse config file
+
+my $LOCATION = 0;
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ format => 'xml',
+ database => 'gene',
+ dir => '.',
+ name => '${search}_results_genecard',
+ terms => '-',
+ );
+
+my $terms;
+if ($options{terms} eq '-') {
+ $terms = \*STDIN;
+}
+
+my $ua = new LWP::UserAgent(agent=>"DA_get_harvester_results/$REVISION");
+
+sub get_url($){
+ my $url = shift;
+
+ my $request = HTTP::Request->new('GET', $url);
+ my $response = $ua->request($request);
+ $response = $response->content;
+ return $response;
+}
+
+#For every term
+while (<$terms>) {
+ # Get uids to retrieve
+ chomp;
+ my $search = $_;
+
+ my $response = get_url(uri_param_munge('http://www.ensembl.org/Homo_sapiens/textview?type=All&x=0&y=0',
+ {q => $search,
+ },
+ )
+ );
+
+ my ($url) = $response =~ m&<blockquote><b>1.\s+Ensembl\s+[^<]+\s+</B>
+ <A\s+HREF="(/Homo[^"]+)">[^\"]+</A><BR>&xis;
+
+ print "NO DATA:1\n" and next if not defined $url;
+
+ $response = get_url("http://www.ensembl.org$url");
+
+ ($url) = $response =~ m{<tr\s+align="left"\s+valign="middle">\s*
+ <th\s+width="20%">Gene</th>\s*
+ <td\s+width="80%"><b><a\s+href="http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/get_data.pl?[^"]+">
+ ([^<]+)</a>\s*</b>\s*<small>\(HUGO\s*ID\)</small> }xis;
+
+ print "NO DATA:2\n" and next if not defined $url;
+
+ $response = get_url("http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/gdlw.pl?title=&col=gd_hgnc_id&col=gd_app_name&col=gd_status&col=gd_aliases&col=gd_pub_chrom_map&col=gd_pub_refseq_ids&status=Approved&status=Approved+Non-Human&status=Entry+Withdrawn&status_opt=3&=on&where=gd_app_sym+like+%27%25${url}%25%27&order_by=gd_app_sym_sort&limit=&format=html&submit=submit&.cgifields=&.cgifields=status&.cgifields=chr");
+
+ if ($LOCATION) {
+ my ($location) = $response =~ m{<th\s+valign="TOP"\s+align="LEFT"\s+bgcolor="\#E6E6FF">
+ Chromosome<a\s+href="[^"]+">
+ \s*\+\s*</a></th><td\s+valign="TOP"\s+align="LEFT">\s*
+ ([^<]+?) # The chromosome location
+ \s*</td><th}xis;
+
+ print "NO LOCATION\n" and next if not defined $location;
+ print $location,"\n";
+ }
+#http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/gdlw.pl?title=&col=gd_hgnc_id&col=gd_app_name&col=gd_status&col=gd_aliases&col=gd_pub_chrom_map&col=gd_pub_refseq_ids&status=Approved&status=Approved+Non-Human&status=Entry+Withdrawn&status_opt=3&=on&where=gd_app_sym+like+%27%25HLA-A%25%27&order_by=gd_app_sym_sort&limit=&format=html&submit=submit&.cgifields=&.cgifields=status&.cgifields=chr
+ else{
+ my ($ref_seq) = $response =~ m{<td><a\s+href="http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi\?val=[^"]+">([^<]+)</a></td></tr>}xis;
+
+ print "NO SEQUENCE\n" and next if not defined $ref_seq;
+ print $ref_seq, "\n";
+ }
+}
+
+
+
+
+
+
+__END__