]> git.donarmstrong.com Git - bin.git/blob - acro_gene
add reset usb bus command
[bin.git] / acro_gene
1 #!/usr/bin/perl
2 # acro_gene outputs gene acronym definitions for use with acro
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 acro_gene - outputs gene acronym definitions for use with acro
18
19 =head1 SYNOPSIS
20
21 acro_gene [options] [gene1] [[gene2]...]
22
23  Options:
24    --debug, -d debugging level (Default 0)
25    --help, -h display this help
26    --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief usage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48 acro_gene
49
50 =cut
51
52
53 use vars qw($DEBUG);
54
55 my %options = (debug           => 0,
56                help            => 0,
57                man             => 0,
58                hgnc_db         => 'ftp://ftp.ebi.ac.uk/pub/databases/genenames/new/tsv/non_alt_loci_set.txt',
59                gene_db         => [glob("~/.acro_gene_db")]->[0],
60               );
61
62 GetOptions(\%options,
63            'gene_db|gene-db=s',
64            'hgnc_db|hgnc-db=s',
65            'debug|d+','help|h|?','man|m');
66
67 pod2usage() if $options{help};
68 pod2usage({verbose=>2}) if $options{man};
69
70 $DEBUG = $options{debug};
71
72 my @USAGE_ERRORS;
73 if (not @ARGV) {
74     push @USAGE_ERRORS,"You must provide a gene name";
75 }
76
77 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
78
79
80 if (! -e $options{gene_db}) {
81     system('wget','-O',$options{gene_db},$options{hgnc_db});
82 }
83
84 my $fh;
85 open($fh,'<',$options{gene_db}) or
86     die "Unable to open $options{gene_db} for reading: $!";
87
88 my @header;
89 my %genes;
90 my %aliases;
91 while (<$fh>) {
92     chomp;
93     my @r = split /\t/;
94     if (not @header) {
95         @header = @r;
96         next;
97     }
98     my %r;
99     @r{@header} = @r;
100     $genes{$r{symbol}} = $r{name};
101     my $alias = $r{alias_symbol};
102     $alias =~ s/"//g;
103     my @aliases = split /\|/,$alias;
104     $aliases{@aliases} = ($r{name}) x @aliases;
105 }
106
107 for (@ARGV) {
108     my $gene = $_;
109     my $name = $genes{$gene};
110     if (not defined $name) {
111         $gene = $aliases{$gene};
112         next unless defined $gene;
113         $name = $genes{$gene};
114     }
115     my $url = 'http://www.genenames.org/cgi-bin/gene_symbol_report?match='.$gene;
116     print '\DeclareAcronym{'.
117         $gene.'}{short=\href{'.$url.
118         '}{\textit{'.$gene.'}},long={'.$name.
119         '},first-style=reversed,single={'.
120         '\href{'.$url.'}{\textit{'.$gene.'}} ('.$name.')'.
121         '}}'."\n";
122 }
123
124
125 __END__