接了任務,要從 http://www.ebi.ac.uk/ena/ 下載序列數據,原本直接所有導出 fasta 就行了,惋惜網絡很差,總是下到一半就掛掉。瀏覽器
因而寫了這麼個小腳本,用 Perl 的 LWP::Simple
來慢慢下載。網絡
很簡單,也可能有 bug。less
#!/usr/bin/perl # by lhtk : lhtk80t7@gmail.com use strict; use warnings; use LWP::Simple; # http://www.ebi.ac.uk/ena/data/view/FKKI010000001&display=fasta # 瀏覽器上打開它,會直接返回文本類型的結果 my $s = $ARGV[0]; # start my $e; # end die "不正確\n" unless (defined $s and $s > 0); while ($s <= 1581707) { $e = $s + 1000; # 一批 1000 個,能夠改 if ($e > 1581707) { $e = 1581707; } my $url; if ($s == $e) { $url = sprintf "http://www.ebi.ac.uk/ena/data/view/FKKI01%07d&display=fasta", $s; } else { $url = sprintf "http://www.ebi.ac.uk/ena/data/view/FKKI01%07d-FKKI01%07d&display=fasta", $s, $e; } #print "$url\n"; # 測試 #last if $n == 2; if (is_success( getprint($url) )) { print STDERR "$s - $e\n"; $s = $e + 1; } else { sleep 1; } }
而後從外部調用:測試
./xxx.pl 1 >>xxxxx.fa
存個檔,備忘。url