From d09b67e0af77d6f2818e41d6b4d648cff651c79d Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 12 May 2007 05:23:43 +0000 Subject: [PATCH] add bin files for search routines git-svn-id: file:///srv/svn/function2gene/trunk@2 a0738b58-4706-0410-8799-fb830574a030 --- bin/combine_results | 172 ++++++++++++++++++++++++++++ bin/get_genecard_results | 139 ++++++++++++++++++++++ bin/get_harvester_results | 139 ++++++++++++++++++++++ bin/get_location_from_uniprot | 143 +++++++++++++++++++++++ bin/get_ncbi_xml_results | 172 ++++++++++++++++++++++++++++ bin/name_chooser.pl | 16 +++ bin/parse_genecard_results | 180 +++++++++++++++++++++++++++++ bin/parse_harvester_results | 209 ++++++++++++++++++++++++++++++++++ bin/parse_ncbi_results | 198 ++++++++++++++++++++++++++++++++ bin/stupid_missing_names.pl | 117 +++++++++++++++++++ 10 files changed, 1485 insertions(+) create mode 100755 bin/combine_results create mode 100755 bin/get_genecard_results create mode 100755 bin/get_harvester_results create mode 100755 bin/get_location_from_uniprot create mode 100755 bin/get_ncbi_xml_results create mode 100644 bin/name_chooser.pl create mode 100755 bin/parse_genecard_results create mode 100755 bin/parse_harvester_results create mode 100755 bin/parse_ncbi_results create mode 100644 bin/stupid_missing_names.pl diff --git a/bin/combine_results b/bin/combine_results new file mode 100755 index 0000000..8125c11 --- /dev/null +++ b/bin/combine_results @@ -0,0 +1,172 @@ +#! /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 . + +# $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__ diff --git a/bin/get_genecard_results b/bin/get_genecard_results new file mode 100755 index 0000000..6345227 --- /dev/null +++ b/bin/get_genecard_results @@ -0,0 +1,139 @@ +#! /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 . + +# $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#\s+Display\s*\s*
\s*the\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__ diff --git a/bin/get_harvester_results b/bin/get_harvester_results new file mode 100755 index 0000000..c6b4f0b --- /dev/null +++ b/bin/get_harvester_results @@ -0,0 +1,139 @@ +#! /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 . + +# $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##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__ diff --git a/bin/get_location_from_uniprot b/bin/get_location_from_uniprot new file mode 100755 index 0000000..f4582e0 --- /dev/null +++ b/bin/get_location_from_uniprot @@ -0,0 +1,143 @@ +#! /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 . + +# $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{\s*\s* +  \s* + \s* + Gene\s+name:[^\&]+  Location:([^\<]+)\s* + \s* + }xis; + ($gene[FULLNAME]) = $response =~ m{>Protein\s+name\s* + \s*\s* + ([^\<]+)\s* + \s*\s*}xis; + print STDOUT join(',', map {if (defined $_) {qq("$_");} else {qq("NO DATA");}} @gene[0..2]),qq(\n); + sleep 2; +} + + + + + + +__END__ diff --git a/bin/get_ncbi_xml_results b/bin/get_ncbi_xml_results new file mode 100755 index 0000000..3ee4778 --- /dev/null +++ b/bin/get_ncbi_xml_results @@ -0,0 +1,172 @@ +#! /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 . + +# $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/\</ and suffix a ditch them. + $response =~ s/^\s*
//gso;
+	  $response =~ s#
\s*$##gso; + + $response =~ s#<\?xml[^>]+>##gso; + $response =~ s#]+>##gso; + + print {$xml_file} $response; + sleep 10; + } + undef $xml_file; +} + + + + + + +__END__ diff --git a/bin/name_chooser.pl b/bin/name_chooser.pl new file mode 100644 index 0000000..9651fb2 --- /dev/null +++ b/bin/name_chooser.pl @@ -0,0 +1,16 @@ +#! /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); +} diff --git a/bin/parse_genecard_results b/bin/parse_genecard_results new file mode 100755 index 0000000..4c00d9b --- /dev/null +++ b/bin/parse_genecard_results @@ -0,0 +1,180 @@ +#! /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 . + +# $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*|)\s*\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&LocusLink\s+cytogenetic\s+band:\s+ + \s*([^\<]+?)\s*&xis; + + $results[LOCATION] ||= 'NO LOCATION'; + + # Find gene aliases + my ($alias_table) = $result =~ m|Aliases and Descriptions(.+?)|is; + $alias_table ||=''; + + my @gene_aliases = $alias_table =~ m|
  • \s*([^\(]{0,20}?)\s*\(Function:\s+(.+?)(?:
  • )|(?:)&gis; + + # GO Functions + push @functions, (map {s#\s*\s*# #g; $_;} $result =~ m&(GO:\d+\s*.+?)(?:
    |

    )&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__ diff --git a/bin/parse_harvester_results b/bin/parse_harvester_results new file mode 100755 index 0000000..29d0719 --- /dev/null +++ b/bin/parse_harvester_results @@ -0,0 +1,209 @@ +#! /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 . + +# $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& +

    ([^<]+)
    &xis; + + if (not defined $results[NAME]) { + ($results[NAME]) = $result =~ m&\s*Entry\s*name\s* + \s*\s*([^<]+?)\s*\s*&xis; + } + + $results[NAME] ||= 'NO NAME'; + + # Find REF SEQ number + ($results[REFSEQ]) = $result =~ m&&xis; + + $results[REFSEQ] ||= 'NO REFSEQ'; + + # Find Chromosomal Location + ($results[LOCATION]) = $result =~ m&Chromosomal\s+Location\s+
    +
    Chromosome/Cytoband
    \s*([^\<]+?)\s*
    &xis; + + $results[LOCATION] ||= 'NO LOCATION'; + # Find gene aliases + # SOURCE ALIASES + my ($alias_table) = $result =~ m|Aliases\s* + \s+
      (.+?)
    |xis; + $alias_table ||=''; + + my @gene_aliases = $alias_table =~ m&
  • \s*([^\(\<]{0,30}?)\s*(?:\<|\()&gis; + + # UNIPROT ALIASES + push @gene_aliases, $result =~ m&\s*\s*Synonym\(s\)\s*\s* + \s*([^<]+?)\s*\s*&xis; + push @gene_aliases, $result =~ m&\s*Description\s*\s* + \s*([^<]+?)\s*\s*&xis; + + $results[ALIAS] = join('; ', @gene_aliases); + $results[ALIAS] ||= 'NO ALIASES'; + + # Find gene function(s) + + # Stanford GO functions + my ($gene_ontology) = $result =~ m&\s* + Ontology\s*(.+?)&xis; + + my @functions; + push @functions, map {s#\s*\"\>\s*# #g; $_;} $gene_ontology =~ m&[^\<]+)&gxis + if defined $gene_ontology; + + # UNIPROT GO Functions + push @functions, map {s#\s*\;?\s*# #g; $_;} m& + + (GO\:\d+\;\s+[^\<]+?)\s*&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&Locus\s+Link\s+Summary(.+?)\s*\s*&is; + if (not defined $results[DESCRIPTION]) { + ($results[DESCRIPTION]) = map{s#\n# #g; $_;} $result =~ m& + FUNCTION\s* + ([^\<]+)\s*&xis; + } + $results[DESCRIPTION] ||= ''; + + # Database searched + $results[DBNAME] = 'harvester'; + $results[FILENAME] = $file_name; + + print join(',',map {qq("$_")} @results),qq(\n); +} + + + + + + +__END__ diff --git a/bin/parse_ncbi_results b/bin/parse_ncbi_results new file mode 100755 index 0000000..51d339d --- /dev/null +++ b/bin/parse_ncbi_results @@ -0,0 +1,198 @@ +#! /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 . + +# $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__ diff --git a/bin/stupid_missing_names.pl b/bin/stupid_missing_names.pl new file mode 100644 index 0000000..b248f9f --- /dev/null +++ b/bin/stupid_missing_names.pl @@ -0,0 +1,117 @@ +#! /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&
    1.\s+Ensembl\s+[^<]+\s+ + [^\"]+
    &xis; + + print "NO DATA:1\n" and next if not defined $url; + + $response = get_url("http://www.ensembl.org$url"); + + ($url) = $response =~ m{\s* + Gene\s* + + ([^<]+)\s*\s*\(HUGO\s*ID\) }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{ + Chromosome + \s*\+\s*\s* + ([^<]+?) # The chromosome location + \s*([^<]+)}xis; + + print "NO SEQUENCE\n" and next if not defined $ref_seq; + print $ref_seq, "\n"; + } +} + + + + + + +__END__ -- 2.39.2