]> git.donarmstrong.com Git - function2gene.git/blob - bin/parse_genecard_results
6024d9bd27e0f9d74618070735532cb6dd051da1
[function2gene.git] / bin / parse_genecard_results
1 #! /usr/bin/perl
2
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
6 # information.
7
8 # Copyright 2004 by Don Armstrong <don@donarmstrong.com>.
9
10 # $Id: ss,v 1.1 2004/06/29 05:26:35 don Exp $
11
12
13 use warnings;
14 use strict;
15
16
17 use Getopt::Long;
18 use Pod::Usage;
19
20 =head1 NAME
21
22   parse_genecard_results [options]
23
24 =head1 SYNOPSIS
25
26
27  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
34
35 =head1 OPTIONS
36
37 =over
38
39 =item B<--debug, -d>
40
41 Debug verbosity. (Default 0)
42
43 =item B<--help, -h>
44
45 Display brief useage information.
46
47 =item B<--man, -m>
48
49 Display this manual.
50
51 =back
52
53 =head1 EXAMPLES
54
55   parse_harvester_results -D ./harvester_results/ -n '${search}_name.html' < search_parameters
56
57 Will pretty much do what you want
58
59 =cut
60
61
62
63 use vars qw($DEBUG $REVISION);
64
65 BEGIN{
66      ($REVISION) = q$LastChangedRevision: 1$ =~ /LastChangedRevision:\s+([^\s]+)/;
67      $DEBUG = 0 unless defined $DEBUG;
68 }
69
70 use IO::File;
71 use IO::Dir;
72
73 my %options = (debug    => 0,
74                help     => 0,
75                man      => 0,
76                dir      => '.',
77                keyword  => undef,
78                keywords => 0,
79               );
80
81 GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m',
82            'keywords',
83           );
84
85
86 pod2usage() if $options{help};
87 pod2usage({verbose=>2}) if $options{man};
88
89 $DEBUG = $options{debug};
90
91 # CSV columns
92 use constant {NAME        => 0,
93               REFSEQ      => 1,
94               LOCATION    => 2,
95               ALIAS       => 3,
96               FUNCTION    => 4,
97               DESCRIPTION => 5,
98               KEYWORD     => 6,
99               DBNAME      => 7,
100               FILENAME    => 8,
101              };
102
103 if ($options{keywords}) {
104      if (@ARGV != 1) {
105           pod2usage("If the --keywords option is used, exactly one argument (the keyword) must be passed");
106      }
107      $option{dir} = "$ARGV[0]_results_genecard";
108 }
109
110 if (not -d $options{dir}) {
111      die "$options{dir} does not exist or is not a directory";
112 }
113
114 my $dir = new IO::Dir $options{dir} or die "Unable to open dir $options{dir}: $!";
115
116 print join(",", map {qq("$_");} qw(Name RefSeq Location Alias Function Description Keyword DBName Filename)),qq(\n);
117
118 while ($_ = $dir->read) {
119      my $file_name = $_;
120      next if $file_name =~ /^\./;
121      next unless -f "$options{dir}/$file_name" and -r "$options{dir}/$file_name";
122
123      my $file = new IO::File "$options{dir}/$file_name", 'r' or die "Unable to open file $file_name";
124
125      local $/;
126      my $result = <$file>;
127
128      my @results;
129
130      # Find gene name
131      ($results[NAME]) = $result =~ m&(?:Lean|Gene)Card\s+for\s+(?:(?:disorder\s+locus|uncategorized|
132                                      hugo\s*reserved\s*symbol|cluster|
133                                      potentially\s*expressed\s*sequence)|(?:predicted\s+|pseudo|rna\s+|)gene)
134                                      \s*(?:with\s*support\s*|)<FONT\s+COLOR=\"[^\"]+\">\s*<FONT\s+SIZE=\+2>\s*([^\s]+)\s*&xis;
135
136      $results[NAME] ||= 'NO NAME';
137      # Find REF SEQ number
138      ($results[REFSEQ]) = $result =~ m|http://www.ncbi.nlm.nih.gov/entrez/query.fcgi\?
139                                cmd=Search\&db=nucleotide\&doptcmdl=GenBank\&term=([^\"]+)\"|xis;
140
141      $results[REFSEQ] ||= 'NO REFSEQ';
142
143      # Find Gene Location
144      ($results[LOCATION]) = $result =~ m&<I>LocusLink\s+cytogenetic\s+band:</I><b>\s+
145                                          <a\s+href="[^\"]+"\s+target\s+=\s+"aaa">\s*([^\<]+?)\s*</a>&xis;
146
147      $results[LOCATION] ||= 'NO LOCATION';
148
149      # Find gene aliases
150      my ($alias_table) = $result =~ m|<b>Aliases and Descriptions</b>(.+?)</TR>|is;
151      $alias_table ||='';
152
153      my @gene_aliases = $alias_table =~ m|<li>\s*([^\(]{0,20}?)\s*\(<FONT|gis;
154
155      $results[ALIAS] = join('; ', @gene_aliases);
156      $results[ALIAS] ||= 'NO ALIASES';
157
158      # Find gene function(s)
159
160      # Swiss prot functions
161      my @functions = $result =~ m&<li><b>Function:</b>\s+(.+?)(?:<li>)|(?:</ul>)&gis;
162
163      # GO Functions
164      push @functions, (map {s#\s*</a>\s*# #g; $_;} $result =~ m&(GO:\d+\s*</a>.+?)(?:<dd>|<p>)&gis);
165      $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions);
166      $results[FUNCTION] ||= 'NO FUNCTION';
167
168      # Figure out the keyword used
169      ($results[KEYWORD]) = $file_name =~ /search=([^&]+)/;
170
171      $results[KEYWORD] ||= 'NO KEYWORD';
172
173      # Figure out what the description is
174      $results[DESCRIPTION] = '';
175
176      # Database searched
177      $results[DBNAME] = 'genecard';
178      $results[FILENAME] = $file_name;
179
180      print join(',',map {qq("$_")} @results),qq(\n);
181 }
182
183
184
185
186
187
188 __END__