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 # XXX parse config file
75 my %options = (debug => 0,
82 GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m');
85 pod2usage() if $options{help};
86 pod2usage({verbose=>2}) if $options{man};
88 $DEBUG = $options{debug};
91 use constant {NAME => 0,
102 if (not -d $options{dir}) {
103 die "$options{dir} does not exist or is not a directory";
106 my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
108 print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
110 while ($_ = $dir->read) {
112 next if $file_name =~ /^\./;
113 next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
115 my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
118 my $result = <$file>;
123 ($results[NAME]) = $result =~ m&(?:Lean|Gene)Card\s+for\s+(?:(?:disorder\s+locus|uncategorized|
124 hugo\s*reserved\s*symbol|cluster|
125 potentially\s*expressed\s*sequence)|(?:predicted\s+|pseudo|rna\s+|)gene)
126 \s*(?:with\s*support\s*|)<FONT\s+COLOR=\"[^\"]+\">\s*<FONT\s+SIZE=\+2>\s*([^\s]+)\s*&xis;
128 $results[NAME] ||= 'NO NAME';
129 # Find REF SEQ number
130 ($results[REFSEQ]) = $result =~ m|http://www.ncbi.nlm.nih.gov/entrez/query.fcgi\?
131 cmd=Search\&db=nucleotide\&doptcmdl=GenBank\&term=([^\"]+)\"|xis;
133 $results[REFSEQ] ||= 'NO REFSEQ';
136 ($results[LOCATION]) = $result =~ m&<I>LocusLink\s+cytogenetic\s+band:</I><b>\s+
137 <a\s+href="[^\"]+"\s+target\s+=\s+"aaa">\s*([^\<]+?)\s*</a>&xis;
139 $results[LOCATION] ||= 'NO LOCATION';
142 my ($alias_table) = $result =~ m|<b>Aliases and Descriptions</b>(.+?)</TR>|is;
145 my @gene_aliases = $alias_table =~ m|<li>\s*([^\(]{0,20}?)\s*\(<FONT|gis;
147 $results[ALIAS] = join('; ', @gene_aliases);
148 $results[ALIAS] ||= 'NO ALIASES';
150 # Find gene function(s)
152 # Swiss prot functions
153 my @functions = $result =~ m&<li><b>Function:</b>\s+(.+?)(?:<li>)|(?:</ul>)&gis;
156 push @functions, (map {s#\s*</a>\s*# #g; $_;} $result =~ m&(GO:\d+\s*</a>.+?)(?:<dd>|<p>)&gis);
157 $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
158 $results[FUNCTION] ||= 'NO FUNCTION';
160 # Figure out the keyword used
161 ($results[KEYWORD]) = $file_name =~ /search=([^&]+)/;
163 $results[KEYWORD] ||= 'NO KEYWORD';
165 # Figure out what the description is
166 $results[DESCRIPTION] = '';
169 $results[DBNAME] = 'genecard';
170 $results[FILENAME] = $file_name;
172 print join(',',map {qq("$_")} @results),qq(\n);