3 # parse_harvester_results retreives files of search results from ncbi,
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 2004 by Don Armstrong <don@donarmstrong.com>.
10 # $Id: ss,v 1.1 2004/06/29 05:26:35 don Exp $
22 parse_harvester_results [options]
28 --dir, -D directory to stick results into [default .]
29 --name, -n file naming scheme [default ${search}_results.$format]
30 --terms, -t file of search terms [default -]
31 --debug, -d debugging level [default 0]
32 --help, -h display this help
33 --man, -m display manual
41 Debug verbosity. (Default 0)
45 Display brief useage information.
55 parse_harvester_results -D ./harvester_results/ -n '${search}_name.html' < search_parameters
57 Will pretty much do what you want
63 use vars qw($DEBUG $REVISION);
66 ($REVISION) = q$LastChangedRevision: 1$ =~ /LastChangedRevision:\s+([^\s]+)/;
67 $DEBUG = 0 unless defined $DEBUG;
73 # XXX parse config file
75 my %options = (debug => 0,
83 GetOptions(\%options,'keyword|k=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};
94 use constant {NAME => 0,
105 if ($options{keywords}) {
107 pod2usage("If the --keywords option is used, exactly one argument (the keyword) must be passed");
109 $options{dir} = "$ARGV[0]_results_harvester";
114 if (not -d $options{dir}) {
115 die "$options{dir} does not exist or is not a directory";
118 my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
120 print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
122 my ($keyword) = $options{keyword} || $options{dir} =~ m#(?:^|/)([^\/]+)_results_harvester#;
124 while ($_ = $dir->read) {
126 next if $file_name =~ /^\./;
127 next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
129 my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
132 my $result = <$file>;
137 ($results[NAME]) = $result =~ m&<img\s+src=\"http://genome-www5.stanford.edu/images/SOURCE/hsgr.gif\"\s*/>
138 </td><td\s+bgcolor="tomato"\s+colspan="1"><center><font\s+size="\+5"
139 \s+color="white">([^<]+)</font></center>&xis;
141 if (not defined $results[NAME]) {
142 ($results[NAME]) = $result =~ m&<TR>\s*<TD\s*BGCOLOR="\#FEFE99"\s*VALIGN="top"\s*NOWRAP>Entry\s*name</TD>\s*
143 <TD\s*VALIGN="top"\s*COLSPAN="5">\s*<b>\s*([^<]+?)\s*</b></TD>\s*</TR>&xis;
146 $results[NAME] ||= 'NO NAME';
148 # Find REF SEQ number
149 ($results[REFSEQ]) = $result =~ m&<a\s+href="http://www.ncbi.nlm.nih.gov/entrez/
150 query.fcgi\?db=Nucleotide\&cmd=Search\&term=([^\&]+)\&doptcmdl=GenBank">&xis;
152 $results[REFSEQ] ||= 'NO REFSEQ';
154 # Find Chromosomal Location
155 ($results[LOCATION]) = $result =~ m&Chromosomal\s+Location</font></td></tr>\s+<tr><td\s+colspan="1"\s+bgcolor="beige"><dl>
156 <dd><b>Chromosome/Cytoband</b></td><td\s+width="525"><center>\s*([^\<]+?)\s*</center>&xis;
158 $results[LOCATION] ||= 'NO LOCATION';
161 my ($alias_table) = $result =~ m|Aliases</font></td></tr>\s*<tr><td\s+bgcolor=\"beige\"\s+colspan=\"2\">
162 <font\s+size=\"-1\"\s*/>\s+<ul>(.+?)</ul>|xis;
165 my @gene_aliases = $alias_table =~ m&<li>\s*([^\(\<]{0,30}?)\s*(?:\<|\()&gis;
168 push @gene_aliases, $result =~ m&<TR>\s*<TD\s+BGCOLOR=\"\#CECFCE\"\s+VALIGN=\"top\"\s+NOWRAP>\s*Synonym\(s\)\s*</TD>\s*
169 <TD\s+VALIGN=\"top\"\s+COLSPAN=\"\d\">\s*([^<]+?)\s*</TD>\s*</TR>&xis;
170 push @gene_aliases, $result =~ m&<TD\s+BGCOLOR=\"\#CECFCE\"\s+VALIGN=\"top\"\s*>\s*Description\s*</TD>\s*
171 <TD\s+VALIGN=\"top\"\s+COLSPAN=\"\d\">\s*([^<]+?)\s*</TD>\s*</TR>&xis;
173 $results[ALIAS] = join('; ', @gene_aliases);
174 $results[ALIAS] ||= 'NO ALIASES';
176 # Find gene function(s)
178 # Stanford GO functions
179 my ($gene_ontology) = $result =~ m&<table\s+width="100%"\s+cellspacing="0"\s+border="1"><tr>\s*
180 <th\s+valign="middle"\s+align="left"\s+bgcolor="\#CCCCCC">Ontology</th>\s*(.+?)</table>&xis;
183 push @functions, map {s#\s*\"\>\s*# #g; $_;} $gene_ontology =~ m&<a\s+href="http://godatabase.org/cgi-bin/go.cgi\?view=details
184 \&depth=1\&query=([^\"]+\">[^\<]+)</a>&gxis
185 if defined $gene_ontology;
187 # UNIPROT GO Functions
188 push @functions, map {s#\s*</a>\;?\s*# #g; $_;} m&<TD\s+VALIGN="top"\s+COLSPAN="5">
189 <a\s+href="http://www.ebi.ac.uk/ego/GSearch\?query=[^\&+]\&mode=id">
190 (GO\:\d+</a>\;\s+[^\<]+?)\s*</TD>&xgis;
192 $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
193 $results[FUNCTION] ||= 'NO FUNCTION';
195 # Figure out the keyword used
196 $results[KEYWORD] = $keyword;
198 $results[KEYWORD] ||= 'NO KEYWORD';
200 # Figure out what the description is
201 ($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;
202 if (not defined $results[DESCRIPTION]) {
203 ($results[DESCRIPTION]) = map{s#\n# #g; $_;} $result =~ m&<TD\s+BGCOLOR="\#CECFCE"\s+VALIGN="center"\s+COLSPAN="2">
204 <FONT\s+face="verdana,helvetica,arial,sans-serif"><B>FUNCTION</B></TD>\s*
205 <TD\s+VALIGN="top"\s+COLSPAN="4">([^\<]+)</TD>\s*</TR>&xis;
207 $results[DESCRIPTION] ||= '';
210 $results[DBNAME] = 'harvester';
211 $results[FILENAME] = $file_name;
213 print join(',',map {qq("$_")} @results),qq(\n);