サンプル3. Tkを使って入力画面を作る

Bioperl-guiの使い方はまだわかりませんが、Tkをインストールしたので、Tkで入力画面を表示するようにしてみました。
サンプルはGenBankを検索して、日時フォルダの中にヒットしたデータをfasta形式で保存してます。実行は、X11上で。私は、使っているエディタmiから実行してます。
1度目の検索はうまくいくのですが、2度目がうまくいきません。なぜだろう・・・。



#
#BLAST in Tk
#
#!/usr/bin/perl -w

use Tk;

use Bio::SeqIO;
use Bio::DB::GenBank;
use Bio::DB::Query::GenBank;

# グローバル関数
$orgn = ''; #[ORGN]
$titl = ''; #[TITL]
$slen1 = 0; #[SLEN]1
$slen2 = 0; #[SLEN]2

# ドキュメントの表示
sub display {
# 前のドキュメントを消去
$t0->configure( -state => 'normal' );
$t0->delete( '1.0', 'end' );

#blastの実行
$query = '';

if ($orgn){
$query = $orgn."[ORGN]";
}
if ($titl){
$query = $query." AND ".$titl."[TITL]";
}
if ($slen2){
$query = $query." AND ".$slen1.":".$slen2."[SLEN]";
}

$t0->insert('end', $query."?n");
$query_obj = Bio::DB::Query::GenBank->new(-db => $db, -query => $query );
$gb_obj = Bio::DB::GenBank->new;
$stream_obj = $gb_obj->get_Stream_by_query($query_obj);
$now = &get_now();
$t0->insert('end', $now."?n");
mkdir("./$now", 0755);
open (OUT,'>'.$now.'/'.$now.'.log');
print OUT "Query : ".$query."?n?n";

while ($seq_obj = $stream_obj->next_seq) {
$seqio_obj = Bio::SeqIO->new(-file => '>'.$now.'/'.$seq_obj->accession.'.fas',
-format => 'fasta' );
$seqio_obj->write_seq($seq_obj);
$t0->insert('end', $seq_obj->accession."\t".$seq_obj->length."\t".$seq_obj->desc."\n");
print OUT $seq_obj->accession."\t".$seq_obj->length."\t".$seq_obj->desc."\n";
}
close OUT;

$t0->configure( -state => 'disable' );
$t0->focusForce();

return();
}

sub get_now(){

($min,$hour,$mday,$mon,$year) = (localtime(time))[1..5];

$year += 1900;
$year = sprintf("%.2d",$year);
$mon++;
$mon = sprintf("%.2d",$mon);
$mday = sprintf("%.2d",$mday);
$hour = sprintf("%.2d",$hour);
$min = sprintf("%.2d",$min);

$r = "$year$mon$mday-$hour$min";

return $r;
}

# ***** 画面の設定 *****

# メインウィンドウ
$top = MainWindow->new();

# フレーム
$f0 = $top->Frame();
$f1 = $top->Frame();
$f2 = $top->Frame();
$f3 = $top->Frame();
$f4 = $top->Frame();

# フレーム $f0 内の配置
$l0 = $f0->Label( -text => 'ORGN : ' )->pack(-side => 'left');
$e0 = $f0->Entry( -textvariable => ?$orgn )->pack(-side => 'left');
$e0->bind("", ?&display );
$f0->pack( -anchor => 'w' );

# フレーム $f1 内の配置
$l1 = $f1->Label( -text => 'TITL : ' )->pack(-side => 'left');
$e1 = $f1->Entry( -textvariable => ?$titl )->pack(-side => 'left');
$e1->bind("", ?&display );
$f1->pack( -anchor => 'w' );

# フレーム $f2 内の配置
$l2 = $f2->Label( -text => 'SLEN1 : ' )->pack(-side => 'left');
$e2 = $f2->Entry( -textvariable => ?$slen1 )->pack(-side => 'left');
$e2->bind("", ?&display );
$f2->pack( -anchor => 'w' );

# フレーム $f3 内の配置
$l3 = $f3->Label( -text => 'SLEN2 : ' )->pack(-side => 'left');
$e3 = $f3->Entry( -textvariable => ?$slen2 )->pack(-side => 'left');
$e3->bind("", ?&display );
$f3->pack( -anchor => 'w' );

# フレーム $f4 内の配置
$r0 = $f4->Radiobutton( -text => 'protein',
-variable => ?$db, -value => 'protein')->pack( -side => 'left' );
$r1 = $f4->Radiobutton( -text => 'nucleotide',
-variable => ?$db, -value => 'nucleotide')->pack( -side => 'left' );
$f4->pack( -anchor => 'w' );

# テキストウィジェット
$t0 = $top->Scrolled( 'Text', -scrollbars => 'se', -wrap => 'none' )
->pack(-expand => 1, -fill => 'both');

$e0->focus;

MainLoop();