2 # geo_downloader downloads expression files from GEO (NCBI)
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
6 # Copyright 2013 by Don Armstrong <don@donarmstrong.com>.
17 geo_downloader - downloads expression files from GEO (NCBI)
21 geo_downloader [options] [GSE...]
24 --debug, -d debugging level (Default 0)
25 --help, -h display this help
26 --man, -m display manual
34 Debug verbosity. (Default 0)
38 Display brief usage information.
48 geo_downloader GSE20400
56 my %options = (debug => 0,
59 host => 'ftp.ncbi.nlm.nih.gov',
63 'debug|d+','help|h|?','man|m');
65 pod2usage() if $options{help};
66 pod2usage({verbose=>2}) if $options{man};
68 $DEBUG = $options{debug};
72 push @USAGE_ERRORS,"You must give at least one GEO accession";
75 if (@ARGV != grep {/^(gpl|gse|gsm|gds)\d+$/i} @ARGV) {
76 push @USAGE_ERRORS,"Invalid GEO accession(s): ".
77 join(',',grep {$_ !~ /^(gpl|gse|gsm)\d+$/} @ARGV);
81 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
83 my $ftp = Net::FTP->new($options{host},Debug=>$DEBUG,Passive=>1) or
84 die "Unable to create new Net::FTP object";
85 print STDERR "Connected\n" if $DEBUG;
87 $ftp->login('anonymous') or
88 die "Unable to login";
89 print STDERR "logged in\n" if $DEBUG;
92 print STDERR "binary\n" if $DEBUG;
96 for my $geo_acc (@ARGV) {
97 my $geo_directory = geo_directory($geo_acc);
98 $ftp->cwd($geo_directory);
99 print STDERR "changed to $geo_directory\n" if $DEBUG;
100 print STDERR "(really) changed to ".$ftp->pwd()."\n" if $DEBUG;
101 my @files = $ftp->ls();
102 print map {$_."\n"} @files;
103 print STDERR "transferred listing\n" if $DEBUG;
108 $geo_acc = uc($geo_acc);
109 my $geo_acc_dir = $geo_acc;
110 $geo_acc_dir =~ s/\d{3}$/nnn/;
111 my $geo_type_dir = undef;
112 if ($geo_acc =~ /^GSE/) {
113 $geo_type_dir = 'series';
114 } elsif ($geo_acc =~ /^GDS/) {
115 $geo_type_dir = 'datasets';
116 } elsif ($geo_acc =~ /^GPL/) {
117 $geo_type_dir = 'platforms';
118 } elsif ($geo_acc =~ /^GSM/) {
119 $geo_type_dir = 'samples';
121 return "/geo/".$geo_type_dir.'/'.$geo_acc_dir.'/'.$geo_acc;