]> git.donarmstrong.com Git - bin.git/commitdiff
add acro_gene command
authorDon Armstrong <don@donarmstrong.com>
Fri, 6 Jan 2017 19:21:25 +0000 (13:21 -0600)
committerDon Armstrong <don@donarmstrong.com>
Fri, 6 Jan 2017 19:21:25 +0000 (13:21 -0600)
acro_gene [new file with mode: 0755]

diff --git a/acro_gene b/acro_gene
new file mode 100755 (executable)
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 <don@donarmstrong.com>.
+
+
+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__