]> git.donarmstrong.com Git - imprinted_genes.git/blob - parse_geneimprint.pl
add code to calculate the imprinted genes of mouse
[imprinted_genes.git] / parse_geneimprint.pl
1 #!/usr/bin/perl
2 # parse_geneimprint.pl Parses output from the geneimprint website and returns a table of imprinted genes
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 2014 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 parse_geneimprint.pl - Parses output from the geneimprint website and returns a table of imprinted genes
18
19 =head1 SYNOPSIS
20
21 parse_geneimprint.pl [options]
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 parse_geneimprint.pl geneimprint_human.html > geneimprint_human.txt
49
50 =cut
51
52
53 use vars qw($DEBUG);
54
55 use HTML::Tree;
56
57 my %options = (debug           => 0,
58                help            => 0,
59                man             => 0,
60               );
61
62 GetOptions(\%options,
63            'debug|d+','help|h|?','man|m');
64
65 pod2usage() if $options{help};
66 pod2usage({verbose=>2}) if $options{man};
67
68 $DEBUG = $options{debug};
69
70 my @USAGE_ERRORS;
71 if (@ARGV != 1) {
72     push @USAGE_ERRORS,"You must provide a single html file";
73 }
74
75 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
76
77 my $t = HTML::Tree->new_from_file($ARGV[0]) or
78     die "Unable to parse $ARGV[0]";
79
80 # the table we want is currently the first table
81 my $table = $t->look_down(_tag=>'table');
82 for my $row ($table->look_down(_tag=>'tr')) {
83     print join("\t",map{my $a = $_->as_text(); $a =~ s/[\xA0\t]/ /g; $a;} $row->look_down(_tag => qr/^(?:th|td)$/))."\n";
84 }
85
86
87
88
89
90
91 __END__