1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| #!/usr/local/bin/perl
use strict;
use warnings;
use DBI;
use Bio::DB::GenBank;
use Date::Calc qw(:all);
use Time::localtime;
use Devel::Size qw(total_size);
use Benchmark::Stopwatch;
my $stopwatch = Benchmark::Stopwatch->new->start;
# paramètre de temps
#-------------------------------
my ($start_hour,$start_min,$start_sec) = Now([+1]);
my $Depart = ctime();
my $Annee = localtime->year() + 1900;
my $Mois = localtime->mon() + 1;
my $Jour = localtime->mday();
my $Heure = localtime->hour();
my $Min = localtime->min();
my $Sec = localtime->sec();
# Date pour MySQL (date du jour)
my $Date = sprintf("%04d",$Annee)."-".sprintf("%02d",$Mois)."-".sprintf("%02d",$Jour)." ".sprintf("%02d",$Heure).":".sprintf("%02d",$Min).":".sprintf("%02d",$Sec);
$Date = quotemeta($Date);
$stopwatch->lap('date');
# Connexion DB et création table
#-------------------------------
my $driver = "mysql";
my $server = "localhost";
my $database = "test";
my $url = "DBI:$driver:$database:$server";
my $Table = "test_samson";
my ($user, $password ) = PASS();
my $DBconnect=DBI->connect( $url, $user, $password ) or die "Failure!\n";
# efface la table si elle existe déjà
my$sql0="drop table IF exists $Table;";
my$sth0 = $DBconnect->prepare($sql0) or print "prepare error\n";
$sth0->execute or die "Could not execute SQL0 statement ... maybe invalid?";
$sth0->finish;
# Créer la table
my$sql = "CREATE TABLE $Table (Accession VARCHAR(30) PRIMARY KEY, GI INT(10), Organism VARCHAR(50), Taxon INT(10), Description TEXT, Seq_length SMALLINT(5), Sequence LONGTEXT, Date DATE) ENGINE = InnoDB;";
my$sth = $DBconnect->prepare($sql) or print "prepare error\n";
$sth->execute or die "Could not execute SQL statement ... maybe invalid?";
$sth->finish;
print "\nTABLE $Table cree\n\n\n";
$stopwatch->lap('DB');
# Recherche dans Genbank
#--------------------------
my $gb = new Bio::DB::GenBank;
my $acc = 'AB113023';
print "\nAccession : $acc\n\n";
eval { $gb->get_Seq_by_acc($acc) };
if ($@) {
print "ERREUR : pb accession $acc\n";
}
else{
my $info = $gb->get_Seq_by_acc($acc);
$stopwatch->lap('Info');
my $total_size = total_size($info);
print "\$total_size $total_size\n";
# 23.000 chargement 2 sec to 54.000.000 chargement 3 min
$stopwatch->lap('size');
my $gi = $info->primary_id;
my $desc = $info->description;
my $seq = $info->seq();
my $seq_length = length($seq);
$stopwatch->lap('bases');
my $organism = "";
my $taxon = 0;
my @Features = $info->get_SeqFeatures;
my $FeaturesDNA = $Features[0];
foreach my $k (keys %$FeaturesDNA){
if ($k eq "annotation"){
my $SousObjet1 = ($FeaturesDNA->{$k});
my $SousObjet2 = ($SousObjet1->{"_annotation"});
my $SousObjet3 = ($SousObjet2->{"organism"});
$organism = ${$SousObjet3}[0];
my $SousObjet4 = ($SousObjet2->{"db_xref"});
$taxon = ${$SousObjet4}[0];
$taxon =~ s/\D//g;
last;
} #if
} # foreach my $k (keys %$FeaturesDNA)
$stopwatch->lap('Features Obj');
my $sql2 = "INSERT INTO $Table (Organism, Taxon, Accession, Gi, Description, Seq_length, Sequence, Date) VALUES ('$organism', '$taxon', '$acc', '$gi', '$desc', '$seq_length', '$seq', '$Date')";
my $sth2 = $DBconnect->prepare($sql2) or print "prepare error\n";
$sth2->execute or die "Could not execute SQL statement ... maybe invalid?";
$sth2->finish;
}
# DECONNEXION A LA BASE DE DONNEES
#-----------------------------------
$DBconnect->disconnect();
my ($end_hour,$end_min,$end_sec) = Now([+1]);
my ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) =
Delta_YMDHMS(1, 1, 1, $start_hour, $start_min, $start_sec,
1, 1, 1, $end_hour,$end_min,$end_sec);
print "Temps d'exécution : ".$Dh." h ".$Dm." min ".$Ds." sec\n";
print "\nBenchmark::Stopwatch\n";
print $stopwatch->stop->summary;
sub PASS{
my $password_file = "P:/Perl/InfoPass.txt";
open (FILE, $password_file) or die "Can't open file\n";
my @line = <FILE>;
close (FILE);
chomp($line[0]);
chomp($line[1]);
return ( $line[0], $line[1]);
} |
Partager