X-Git-Url: https://git.donarmstrong.com/?p=function2gene.git;a=blobdiff_plain;f=bin%2Fparse_genecard_results;h=b42371957a229b4423cd8b89ac152eb2094f7134;hp=4c00d9b47b85b44ef07adb66042f224cd6513e45;hb=a4b9214b7939fbe990f2373684dfd7aa1f9e77e2;hpb=d09b67e0af77d6f2818e41d6b4d648cff651c79d diff --git a/bin/parse_genecard_results b/bin/parse_genecard_results index 4c00d9b..b423719 100755 --- a/bin/parse_genecard_results +++ b/bin/parse_genecard_results @@ -70,16 +70,20 @@ BEGIN{ use IO::File; use IO::Dir; -# XXX parse config file +use HTML::TreeBuilder; +use HTML::ElementTable; my %options = (debug => 0, help => 0, man => 0, dir => '.', keyword => undef, + keywords => 0, ); -GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m'); +GetOptions(\%options,'keyword|k=s','dir|D=s','debug|d+','help|h|?','man|m', + 'keywords', + ); pod2usage() if $options{help}; @@ -99,6 +103,13 @@ use constant {NAME => 0, FILENAME => 8, }; +if ($options{keywords}) { + if (@ARGV != 1) { + pod2usage("If the --keywords option is used, exactly one argument (the keyword) must be passed"); + } + $options{dir} = "$ARGV[0]_results_genecard"; +} + if (not -d $options{dir}) { die "$options{dir} does not exist or is not a directory"; } @@ -120,40 +131,38 @@ while ($_ = $dir->read) { 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]) = $result =~ m{(?:Lean|Gene)Card\s+for\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]) = $result =~ m{http://www.ncbi.nlm.nih.gov/entrez/query.fcgi\? + (?:cmd=Search\&db=nucleotide|db=nucleotide\&cmd=search) + \&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]) = $result =~ m{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*\(]+>]+>Aliases.+?)}is; + $alias_table ||= ''; + my @gene_aliases = map {s/\s*$//; $_;} $alias_table =~ m{\s*([^<]+)<}gis; $results[ALIAS] = join('; ', @gene_aliases); $results[ALIAS] ||= 'NO ALIASES'; # Find gene function(s) - # Swiss prot functions - my @functions = $result =~ m&
  • Function:\s+(.+?)(?:
  • )|(?:)&gis; - + my @functions; # GO Functions - push @functions, (map {s#\s*\s*# #g; $_;} $result =~ m&(GO:\d+\s*.+?)(?:
    |

    )&gis); + push @functions, (map {s/\n//g; $_;} + map {s#\s*(?:\s*)?\s*# #g; $_;} + $result =~ m{(GO:\d+\s*(?:\s*)?.+?)(?:||

    |

    )}gis + ); $results[FUNCTION] = join('; ', map {(defined $_)?($_):()} @functions); $results[FUNCTION] ||= 'NO FUNCTION'; @@ -162,8 +171,19 @@ while ($_ = $dir->read) { $results[KEYWORD] ||= 'NO KEYWORD'; + # Swiss prot functions + my @description = (map {s/<[^>]+>/ /g; + s/\s+/ /g; + $_; + } + $result =~ m{<(?:dd|li)>Function(?::|:)\s+ + (.+?)<(?:/dd|li)>}xgis + ); + # Figure out what the description is - $results[DESCRIPTION] = ''; + $results[DESCRIPTION] = join('; ', + map {(defined $_)?($_):()} + @description); # Database searched $results[DBNAME] = 'genecard';