#!/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; my %aliases; while (<$fh>) { chomp; my @r = split /\t/; if (not @header) { @header = @r; next; } my %r; @r{@header} = @r; $genes{$r{symbol}} = $r{name}; my $alias = $r{alias_symbol}; $alias =~ s/"//g; my @aliases = split /\|/,$alias; $aliases{@aliases} = ($r{name}) x @aliases; } for (@ARGV) { my $gene = $_; my $name = $genes{$gene}; if (not defined $name) { $gene = $aliases{$gene}; next unless defined $gene; $name = $genes{$gene}; } my $url = 'http://www.genenames.org/cgi-bin/gene_symbol_report?match='.$gene; print '\DeclareAcronym{'. $gene.'}{short=\href{'.$url. '}{\textit{'.$gene.'}},long={'.$name. '},first-style=reversed,single={'. '\href{'.$url.'}{\textit{'.$gene.'}} ('.$name.')'. '}}'."\n"; } __END__