From: Don Armstrong Date: Fri, 6 Jan 2017 19:21:25 +0000 (-0600) Subject: add acro_gene command X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=commitdiff_plain;h=1bcc23e58e26c3e071a7168748072572eb52004a add acro_gene command --- diff --git a/acro_gene b/acro_gene new file mode 100755 index 0000000..46c9621 --- /dev/null +++ b/acro_gene @@ -0,0 +1,112 @@ +#!/usr/bin/perl +# acro_gene outputs gene acronym definitions for use with acro +# and is released under the terms of the GNU GPL version 3, or any +# later version, at your option. See the file README and COPYING for +# more information. +# Copyright 2016 by Don Armstrong . + + +use warnings; +use strict; + +use Getopt::Long; +use Pod::Usage; + +=head1 NAME + +acro_gene - outputs gene acronym definitions for use with acro + +=head1 SYNOPSIS + +acro_gene [options] [gene1] [[gene2]...] + + Options: + --debug, -d debugging level (Default 0) + --help, -h display this help + --man, -m display manual + +=head1 OPTIONS + +=over + +=item B<--debug, -d> + +Debug verbosity. (Default 0) + +=item B<--help, -h> + +Display brief usage information. + +=item B<--man, -m> + +Display this manual. + +=back + +=head1 EXAMPLES + +acro_gene + +=cut + + +use vars qw($DEBUG); + +my %options = (debug => 0, + help => 0, + man => 0, + hgnc_db => 'ftp://ftp.ebi.ac.uk/pub/databases/genenames/new/tsv/non_alt_loci_set.txt', + gene_db => [glob("~/.acro_gene_db")]->[0], + ); + +GetOptions(\%options, + 'gene_db|gene-db=s', + 'hgnc_db|hgnc-db=s', + 'debug|d+','help|h|?','man|m'); + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + +$DEBUG = $options{debug}; + +my @USAGE_ERRORS; +if (not @ARGV) { + push @USAGE_ERRORS,"You must provide a gene name"; +} + +pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS; + + +if (! -e $options{gene_db}) { + system('wget','-O',$options{gene_db},$options{hgnc_db}); +} + +my $fh; +open($fh,'<',$options{gene_db}) or + die "Unable to open $options{gene_db} for reading: $!"; + +my @header; +my %genes; +while (<$fh>) { + chomp; + my @r = split /\t/; + if (not @header) { + @header = @r; + next; + } + my %r; + @r{@header} = @r; + $genes{$r{symbol}} = $r{name}; +} + +for (@ARGV) { + my $gene = $_; + my $name = $genes{$gene}; + print '\DeclareAcronym{'. + $gene.'}{short=\href{http://www.genenames.org/cgi-bin/gene_symbol_report?match='. + $gene.'}{'.$gene.'},long={'.$name. + '},first-style=reversed}'."\n"; +} + + +__END__