#!/usr/bin/perl
# Description: Download genome sequence of a genbank accession no.
# Author: Peter Fischer Hallin
# Email: pfh@cbs.dtu.dk
# Version: Genome Atlas 3.0.ws2
# Date: 2008-02-13

use strict;

# usage getseq.pl [genbank accession no.]

# include standard XML::Compile helper functions (used to initiate WSDL proxys)
require "xml-compile.pl";

# create proxy to genome atlas
my $proxy_genomeatlas = WSDLclient ( 'http://www.cbs.dtu.dk/ws/GenomeAtlas/GenomeAtlas_3_0_ws2.wsdl','getSeq');

my $response = $proxy_genomeatlas->{getSeq}->(  parameters => { parameters => { genbank => $ARGV[0]  }});

# loop through all genomes requesteds
foreach my $sequence ( @{$response->{parameters}->{output}->{sequencedata}->{sequence}} ) {
	my $genome = $sequence->{seq} ;
	my $id = $sequence->{id} ;
	my $comment = $sequence->{comment} ;

	# print as fasta
	print ">$id $comment\n";
	for (my $x = 0 ; $x < length($genome) ; $x += 60 ) {
		print substr($genome,$x,60),"\n";
	}
}
