Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Created June 22, 2015 07:31
Show Gist options
  • Save ktnyt/c2da8134ac47b80906e4 to your computer and use it in GitHub Desktop.
Save ktnyt/c2da8134ac47b80906e4 to your computer and use it in GitHub Desktop.
Batch download GENBANK entries via TogoWS.
#!/usr/bin/env perl
use strict;
use warnings;
my $base = "togows.dbcls.jp/entry/nucleotide";
my ($prefix, $from_id, $to_id) = (@ARGV);
if($from_id > $to_id) {
($from_id, $to_id) = ($to_id, $from_id);
}
my $seq = "";
foreach my $id (map{$prefix.$_}($from_id..$to_id)) {
my $url = sprintf("http://$base/$id");
print "$id\n";
$seq .= `curl -L $url`;
sleep(1);
}
open my $fh, ">", sprintf("%s_%d-%d.fasta", $prefix, $from_id, $to_id);
print $fh $seq;
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment