-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathascp-utils
137 lines (96 loc) · 2.58 KB
/
ascp-utils
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
#!/usr/bin/perl -w
use strict;
use warnings;
use Switch;
use File::Basename;
use Cwd 'abs_path';
my $usage = <<_EOUSAGE_;
Usage: ascp-utils <command> <arguments>
version: 0.0.1
supports:
sra <list>
ftp <list>
ena <list>
Licenced:
(c) 2018-2020 - LEI ZHANG
Logic Informatics Co.,Ltd.
zhanglei\@logicinformatics.com
_EOUSAGE_
;
if( ( scalar @ARGV) < 1){
printf STDERR $usage;
exit;
}
my $which = "";
for my $exe (qw/prefetch ascp/) {
$which = qx(which $exe 2> /dev/null);
$which or print STDERR qq{[ERR]: can not find required '$exe' in PATH\n};
chomp $which;
}
my $ascp = dirname( $which ) . '/..';
my $cmd = shift @ARGV;
switch($cmd){
case 'sra' { sra_run(); };
case 'ftp' { ftp_run(); };
case 'ena' { ena_run(); };
}
exit;
sub sra_run{
if(@ARGV < 1){
printf STDERR qq{\n[ERR] arguments number error!\n$usage};
exit;
}
my $cmd = qq{prefetch \
-t fasp \
-a "$ascp/bin/ascp|$ascp/etc/asperaweb_id_dsa.openssh" \
--ascp-options " --overwrite=diff -QTr -l6000m " \
-L debug -O . } . join(" ", @ARGV) . "\n";
$cmd =~ s/\s+\n\s+/ /msg;
print $cmd;
system $cmd;
}
sub ftp_run{
if(@ARGV < 1){
printf STDERR qq{\n[ERR] arguments number error!\n$usage};
exit;
}
foreach my $acc (@ARGV) {
ftp( $acc );
}
}
sub ftp {
my $url = shift;
$url =~ s/ftp:\/\/.+.ncbi.nlm.nih.gov//;
$url =~ s/https:\/\/.+.ncbi.nlm.nih.gov//;
$url =~ s/https:\/\/ftp.ncbi.nih.gov//;
my $ftp = qq{$ascp/bin/ascp -i $ascp/etc/asperaweb_id_dsa.openssh --overwrite=diff -QTr -l6000m anonftp\@ftp.ncbi.nlm.nih.gov:};
my $ascp = $ftp . $url . " .\n";
print $ascp;
system $ascp;
}
sub ena_run{
if(@ARGV < 1){
printf STDERR qq{\n[ERR] arguments number error!\n$usage};
exit;
}
my $list = shift @ARGV;
ascp_ena( $list );
}
sub ascp_ena {
my $list = shift;
open( ENA, $list ) || die "[ERR]: can't open $list. \n";
while(<ENA>){
$_ =~ s/\s+$//;
next if(/study_accession/);
my @t = split /\t/, $_;
ena($t[-1]);
}
close ENA;
}
sub ena{
my $url = shift;
$url =~ s/ftp.sra.ebi.ac.uk\///;
my $ftp = qq{$ascp/bin/ascp -i $ascp/etc/asperaweb_id_dsa.openssh -QT -P33001 -QT -l6000m era-fasp\@fasp.sra.ebi.ac.uk:};
my $ascp = $ftp . $url . " .\n";
print $ascp;
}