This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEOrawData.pm
132 lines (96 loc) · 3.28 KB
/
GEOrawData.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package PGXDB::GEOrawData;
use Data::Dumper;
use File::Copy;
use LWP::Simple;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
pgxdb_download_probefiles
pgxdb_filter_downloads
pgxdb_read_GSM_logfile
);
################################################################################
################################################################################
################################################################################
sub pgxdb_filter_downloads {
my $pgxdb = shift;
if ($pgxdb->{parameters}->{probefiles} =~ /\w\w/) {
my @buffer;
foreach my $download (@{ $pgxdb->{downloads} }) {
if (grep{ $download->{probefile_ftp} =~ /$_/i } split(',', $pgxdb->{parameters}->{probefiles})) {
push(@buffer, $download) }
}
$pgxdb->{downloads} = \@buffer;
}
if ($pgxdb->{parameters}->{filters} =~ /\w\w/) {
$pgxdb->{parameters}->{filters} =~ s/[^\w\,\.\-\:]//g;
foreach my $filter (split(',', $pgxdb->{parameters}->{filters})) {
$pgxdb->{downloads} = [ grep{ $_->{probefile_ftp} =~ /$filter/i } @{ $pgxdb->{downloads} } ];
}}
return $pgxdb;
}
################################################################################
sub pgxdb_download_probefiles {
use Archive::Extract;
use File::Fetch;
my $pgxdb = shift;
my $i = 0;
foreach my $gsm_meta (@{ $pgxdb->{downloads} }) {
$i++;
my $gseDir = $pgxdb->{paths}->{georawdir}.'/'.$gsm_meta->{GSE};
my $gsmDir = $gseDir.'/'.$gsm_meta->{GSM};
mkdir $gseDir;
mkdir $gsmDir;
my @ftp_files;
if ($pgxdb->{parameters}->{probefiles} =~ /../) {
foreach my $ftpF (split('::', $gsm_meta->{probefile_ftp})) {
if (grep{ $ftpF =~ /\.$_/i } split(',', $pgxdb->{parameters}->{probefiles})) {
push(@ftp_files, $ftpF ) }
}
} else {
@ftp_files = split('::', $gsm_meta->{probefile_ftp}) }
foreach my $uri (@ftp_files) {
my$probefileLoc = $uri;
$probefileLoc =~ s/^.*?\/([^\/]+?$)/$1/;
$probefileLoc =~ s/\.gz$//i;
$probefileLoc = $gsmDir.'/'.$probefileLoc;
if (-f $probefileLoc) { next }
print "
$i / ".@{ $pgxdb->{downloads} }.": Fetching
$_
=> $probefileLoc\n";
my $fh = File::Fetch->new(uri => $uri);
my $where = $fh->fetch(to => $gsmDir ) or warn $ff->error;
# name of the file downloaded
my $gzDlName = $fh->file;
my $gzDl = $gsmDir.'/'.$gzDlName;
my $ae = Archive::Extract->new( archive => $gzDl );
my $ok = $ae->extract( to => $gsmDir) or warn $ae->error;
if (-f $probefileLoc) {
unlink $gzDl or warn "Could not unlink $gzDl" }
}}
return $pgxdb;
}
################################################################################
sub pgxdb_read_GSM_logfile {
my $pgxdb = shift;
$pgxdb->{downloads} = [];
my @lines;
my $fCont = q{};
open FILE, "$pgxdb->{parameters}->{gsmfile}" or die "$pgxdb->{parameters}->{gsmfile} $!";
local $/; # no input separator
$fCont = <FILE>;
close FILE;
foreach (split(/\r\n?|\n/, $fCont)) { push @lines, $_ }
my @header = split("\t", shift @lines);
my %keyPos = map{ $header[$_] => $_ } 0..$#header;
foreach my $meta (@lines) {
my @current = split("\t", $meta);
push(
@{$pgxdb->{downloads}},
{ map{ $_ => $current[ $keyPos{ $_ } ] } keys %keyPos },
);
}
return $pgxdb;
}
1;