3 # parse_genecard_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_genecard_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 use HTML::TreeBuilder;
74 use HTML::ElementTable;
76 my %options = (debug => 0,
84 GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m',
89 pod2usage() if $options{help};
90 pod2usage({verbose=>2}) if $options{man};
92 $DEBUG = $options{debug};
95 use constant {NAME => 0,
106 if ($options{keywords}) {
108 pod2usage("If the --keywords option is used, exactly one argument (the keyword) must be passed");
110 $options{dir} = "$ARGV[0]_results_ensembl";
113 if (not -d $options{dir}) {
114 die "$options{dir} does not exist or is not a directory";
117 my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
119 print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
121 my ($keyword) = $options{keyword} || $options{dir} =~ m#(?:^|/)([^\/]+)_results_ensembl#;
123 while ($_ = $dir->read) {
125 next if $file_name =~ /^\./;
126 next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
128 my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
131 my $result = <$file>;
132 next if $result =~ m/is not present in the current release/;
137 ($results[NAME]) = $result =~ m{a\s+href=\"[^"]+genenames.org[^"]+">\s*([^<]+?)\s*</a>}xis;
139 $results[NAME] ||= 'NO NAME';
140 # strip of leading : bits
141 $results[NAME] =~ s/^[^\:]+\://;
142 # Find REF SEQ number
143 ($results[REFSEQ]) = $result =~ m{for\s*(ENSG\d+)}xis;
145 $results[REFSEQ] ||= 'NO REFSEQ';
148 my @location = $result =~ m{on\s+Chromosome\s+([\dX]+)\s+at\s+location\s+<[^>]+>([\d,]+)}xis;
150 $results[LOCATION] = "$location[0] $location[1]";
152 $results[LOCATION] ||= 'NO LOCATION';
155 my @gene_aliases = map {split/,\s+/;} $result =~ m{<b>Synonyms:\s+</b>\s*([^<]+)\s*</td>}gxis;
157 $results[ALIAS] = join('; ', @gene_aliases);
158 $results[ALIAS] ||= 'NO ALIASES';
160 # Find gene function(s)
164 # push @functions, (map {s/\n//g; $_;}
165 # map {s#\s*</a>(?:</td><td>\s*)?\s*# #g; $_;}
166 # $result =~ m{(GO:\d+\s*</a>(?:</td><td>\s*)?.+?)(?:</font>|</td>|<dd>|<p>)}gis
168 # $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
169 $results[FUNCTION] ||= 'NO FUNCTION';
171 # Figure out the keyword used
172 $results[KEYWORD] ||= $keyword || 'NO KEYWORD';
174 my @description = (map {s/\n/ /g;
178 $result =~ m{<th\s*class="two-column">\s*
181 <td\s*class="two-column">\s*
184 # Figure out what the description is
185 $results[DESCRIPTION] = join('; ',
186 map {(defined $_)?($_):()}
190 $results[DBNAME] = 'ensembl';
191 $results[FILENAME] = $file_name;
193 print join(',',map {qq("$_")} @results),qq(\n);