Skip to content

Instantly share code, notes, and snippets.

@coela
Created March 2, 2011 03:12
Show Gist options
  • Save coela/850403 to your computer and use it in GitHub Desktop.
Save coela/850403 to your computer and use it in GitHub Desktop.
Getting JSON data from Genomes Online Database
use 5.12.2;
use JSON;
use Data::Dumper;
use LWP::Simple;
my @json_places = (
['Complete' , "http://www.genomesonline.org/complete_published.json"],
['Bacteria Ongoing' , "http://www.genomesonline.org/bacterial_ongoing.json"],
['Eukaryal Ongoing' , "http://www.genomesonline.org/eukaryal_ongoing.json"],
['Archaeal Ongoing' , "http://www.genomesonline.org/archaeal_ongoing.json"],
['Metagenome' , "http://www.genomesonline.org/microbial.json"],
);
my $export;
for (@json_places){
my $project_type = $_->[0];
my $url = $_->[1];
my $json = get($url);
$json =~ s/, ]/]/g;
my $gold = decode_json $json;
my %count;
for my $record (@{$gold->{records}}){
for my $sc (@{$record->{'SequencingCenters'}}){
$count{$sc->{'Name'}} ++;
}
$count{'Not Shown'}++ unless @{$record->{'SequencingCenters'}};
}
my $project_number = scalar @{$gold->{records}};
for my $sc_name (keys %count){
if ($count{$sc_name}/$project_number <= 0.01){
delete $count{$sc_name};
$count{'Others'}++;
}
}
for my $sc_name (sort { $count{$b} <=> $count{$a} } keys %count){
push @{$export->{$project_type}}, [$sc_name,$count{$sc_name}];
}
}
say encode_json $export;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment