#!/usr/local/bin/perl -w #use strict; #use warnings; use DBI; use Net::MySQL; use HTTP::Request::Common; use LWP::UserAgent; use CGI qw(header -no_debug); use XML::Twig; #==============================database connection================================================ print "trying to connect to database \n"; my $database = ''; my $host = ''; my $user = ''; my $password = ''; my $mysql = Net::MySQL->new( hostname => $host, database => $database, user => $user, password => $password, ); print "Connection established \n"; #=============================end database connection================================================== $mysql->query(qq{SELECT accession_code FROM protein}); my $record_set = $mysql->create_record_iterator; while (my $record = $record_set->each) { print "Accession ID: $record->[0] \n"; #For retrieving data from a url post in perl, we will use the LWP module "get" function use LWP::Simple; #supports the "get" function $baseurl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/"; $eutil="esearch.fcgi?"; $parameters="db=protein&term=$record->[0]&retmode=xml"; #db=protein&id=gi_id db=taxonomy&id=tax_id $url=$baseurl.$eutil.$parameters; &nb sp; &nb sp;#term=$record->[0] $raw=get($url); open(FILE, ">$record->[0]"); &n bsp; #$record->[0] print FILE $raw; close FILE; $xml_file = $record->[0]; &n bsp; #$record->[0] my $twig= XML::Twig->new( TwigHandlers => { IdList => \&id_Tag } ); #actually parse the file $twig->parsefile($xml_file) or die "cannot parse [$xml_file]: $!"; ########################################### sub id_Tag { ########################################### my($t, $idTag)= @_; unless($idTag->first_child('Id')->text) { print "ID-tag leer\n"; } my $id = $idTag->first_child('Id')->text; print "GI_ID: ",$id,"\n"; # Release memory of processed tree up to here $t->purge(); } unlink($record->[0]); }