This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindSamples.pl
More file actions
256 lines (174 loc) · 8.38 KB
/
Copy pathfindSamples.pl
File metadata and controls
256 lines (174 loc) · 8.38 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Script that downloads all the samples that are not in Arraymap.
# In order to do that we download all the samples, series and samples that are
# already in Arraymap. After that, we download all the samples related to the
# platform that are in Arraymap and we check which of those are not in Arraymap.
#!/usr/bin/perl
=pod
perl findSamples.pl -randno 200 -randpf 3 -metaroot /Volumes/arrayRAID/arraymapIn/GEOmeta -dataroot /Volumes/arrayRAID/arraymapIn/GEOupdate
=cut
use lib qw(/Library/WebServer/cgi-bin);
use PG;
use geometa;
use File::Fetch;
use Net::FTP;
use Archive::Tar;
use IO::Handle;
STDOUT->autoflush(1);
print <<END;
--------------------------------------------------------------------------------
FIND THE SAMPLES/SERIES/PLATTFORMS IN ARRAYMAP
--------------------------------------------------------------------------------
END
my $start_time = [Time::HiRes::gettimeofday()];
#******** 1. set up for downloading from Arraymap
my %args = @ARGV;
$args{ LOC_USERID } = getlogin();
$args{ LOC_ROOT } = '/Library/WebServer/Documents';
$args{ '-dataroot' } //= '/Users/'.$args{ LOC_USERID }.'/Desktop/GEOupdate';
$args{ '-metaroot' } //= '/Users/'.$args{ LOC_USERID }.'/Desktop/GEOmeta';
$args{ '-arraymap' } //= 'n';
$args{ '-getmeta' } //= 'y';
$args{ '-randno' } //= -1;
$args{ '-randpf' } //= -1;
$args{ '-selpf' } //= 'GPL11157,GPL16131,GPL18637';
$args{pgP} = pgSetPaths(%args);
$args{pgV} = setValueDefaults();
%args = pgModifyArgs(%args);
################################################################################
mkdir $args{ '-dataroot' };
mkdir $args{ '-metaroot' };
################################################################################
my $mongoSamples = pgGetMongoCursor(
%args,
MDB => 'arraymap',
MDBCOLL => 'samples',
QUERY => {},
FIELDS => [ qw(UID PLATFORMID SERIESID) ]
);
#******** 2. download samples/plattforms and series in Arraymap
print "download all the platforms...";
my @arraymapPlatforms = map{ $_->{ PLATFORMID } } (grep{ $_->{ PLATFORMID } =~ /GPL/ } @{ $mongoSamples });
@arraymapPlatforms = uniq(@arraymapPlatforms);
print "done: ".@arraymapPlatforms." platforms found. \n";
if ($args{ '-selpf' } =~ /GPL/) {
push(@arraymapPlatforms , split(',', $args{ '-selpf' }));
print "platforms ".$args{ '-selpf' }.' added; now '.@arraymapPlatforms." platforms. \n";
}
if ($args{ '-randpf' } > 0) {
@arraymapPlatforms = shuffle(@arraymapPlatforms);
@arraymapPlatforms = splice(@arraymapPlatforms, 0, $args{ '-randpf' });
print "-randpf: ".scalar(@arraymapPlatforms)." platforms will be used. \n";
}
# print "download all the series...";
# my %arraymap_series = map{ $_->{ SERIESID } => 1 } (grep{ $_->{ SERIESID } =~ /GSE/ } @{ $mongoSamples });
# @arraymap_series = keys %arraymap_series;
# $size = @arraymap_series;
# print "done: $size series found. \n";
################################################################################
#
# arraymap sample filtering
#
################################################################################
=for comment
The next part first creates an empty array for array ids, which will later be
matched against the new retrievals.
If the parameter '-arraymap' is set to "n" (default), then the array will
be populated with the existing array ids from arraymap.
=cut
my @arraymapSamples = ();
if ($args{ '-arraymap' } !~ /y/) {
print "\n--------------------------------------------------------------------\n";
print "RETRIEVAL OF ARRAYMAP IDS FOR EXCLUSION.\n";
print "--------------------------------------------------------------------\n\n";
print "getting existing arrayMap array ids...";
@arraymapSamples = map{ $_->{ UID } } (grep{ $_->{ UID } =~ /^GSM/ } @{ $mongoSamples });
@arraymapSamples = uniq(@arraymapSamples);
print "done: ".scalar(@arraymapSamples)." arrays found. These will not be retrieved again.\n\n";
}
# TODO: execution time => helper sub
# calculate the time needed for the download and printing it
my $diff = Time::HiRes::tv_interval($start_time);
print sprintf("Execution time: %.1f seconds\n", $diff);
################################################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
################################################################################
#~~~~~~~~~~~~
############# PART 2
#~~~~~~~~~~~~
################################################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
################################################################################
$start_time = [Time::HiRes::gettimeofday()];
my $n_sample = 0; # total number of samples
######### print information
print "download the samples in GEO and check which one are already in arraymap...\n";
print "number of platforms: ".(scalar @arraymapPlatforms)."\n";
print "\n0\% |---------------------------| 100\%\n ";
# variables for printing the progress bar
my $perc = scalar(@arraymapPlatforms) / 30;
my $add = $perc;
my $contt = 0;
my $sampleLogFile = $args{ '-dataroot' }."/new_samples.txt";
open(my $fh, '>', $sampleLogFile) or die "Could not open file '$sampleLogFile' $!";
foreach my $plat (sort @arraymapPlatforms){
my $url = "http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=$plat&targ=self&view=brief&form=text";
my $GSMlist = [ grep{/GSM\d+/} split(/[\n\r]/,get($url))];
foreach my $sample (@$GSMlist){
my $gsm_id = substr("$sample",22);
if (! any { $gsm_id eq $_ } @arraymapSamples) {
print $fh "$plat\t$gsm_id\n";
$n_sample++;
push @{ $args{GSMLIST} }, $gsm_id;
}}
#printing the progress bar
$contt++;
if ($contt > $add-1){
$add = $add + $perc + 1;
print "@";
}}
close $fh;
print "\nnumber of new samples: $n_sample \n\n";
if ($args{ '-randno' }) {
$args{GSMLIST} = [ shuffle(@{ $args{GSMLIST} }) ];
$args{GSMLIST} = [ splice(@{ $args{GSMLIST} }, 0, $args{ '-randno' }) ];
print "\n-randno: number of random new samples: ".(scalar @{ $args{GSMLIST} })." \n\n";
}
# calculate the time needed for the download and printing it
$diff = Time::HiRes::tv_interval($start_time);
$mins = $diff/60;
$hours = $mins/60;
print sprintf("\n\nExecution time: %.0f minutes (%.1f hours)\n", $mins, $hours);
################################################################################
#
# metadata => GSM soft file download & file structure
#
################################################################################
if ($args{ '-getmeta' } !~ /^n/i) {
print "\n------------------------------------------------------------------\n";
print "DOWNLOAD OF THE GSM METADATA FILES.\n";
print "------------------------------------------------------------------\n\n";
$start_time = [Time::HiRes::gettimeofday()];
_d(scalar(@{ $args{GSMLIST} }), 'GSM soft files will be retrieved');
my $gsmData = pgGEOmetaGSM(\%args);
$diff = Time::HiRes::tv_interval($start_time);
$mins = $diff/60;
$hours = $mins/60;
print sprintf("\n\nMetadata download time: %.0f minutes (%.1f hours)\n", $mins, $hours);
my @gsmKeys = sort keys $gsmData->{$args{GSMLIST}->[0]};
my @gsmTable = join("\t", @gsmKeys);
foreach my $gsm (sort @{ $args{GSMLIST} }) {
push(@gsmTable, join("\t", @{ $gsmData->{$gsm} }{ @gsmKeys }));
}
pgWriteFile(
FILE => $args{ '-dataroot' }.'/gsmdata.tab',
CONTENT => join("\n", @gsmTable),
);
_d('wrote', $args{ '-dataroot' }.'/gsmdata.tab');
if (
$args{ '-randno' } < 1
&&
$args{ '-randpf' } < 1
) {
copy($args{ '-dataroot' }.'/gsmdata.tab', $args{ '-dataroot' }.'/gsmdata_'._formatDay().'_'.@{ $args{GSMLIST} }.'.tab');
}
}