#!/usr/bin/perl use Tk; require Tk::DialogBox; use Tk::ROText; use Tk::Bitmap; use SOAP::Lite; use Bio::SeqIO; use IO::String; ## global variables my $return_result="Welcome to SubLoc!"; $wsdl = 'http://www.bioinfo.tsinghua.edu.cn/~tigerchen/SubLoc.wsdl'; $server = SOAP::Lite->service($wsdl); #main window my $main = MainWindow->new(); $main->geometry('800x600'); $main->title("SubLocSOAPClient"); #menu bar my $menu=$main->Frame(-relief=>'groove', -borderwidth=>3, -background=>'gray',) ->pack(-side=>'top',-fill=>'x'); # File Menu my $button_file = $menu->Menubutton(-text=>'File', -background=>'gray', -activebackground=>'blue', -foreground=>'black',) ->pack(-side=>'left'); $button_file -> command(-label=>'Open Fasta File', -activebackground=>'blue', -foreground=>'black', -command=>\&open_file, -accelerator=>'Ctrl-o'); $button_file -> command(-label=>'Save Result', -activebackground=>'blue', -foreground=>'black', -command=>\&save_file, -accelerator=>'Ctrl-s'); $button_file -> command(-label=>'Exit', -activebackground=>'blue', -foreground=>'black', -command=>sub{$main->destroy}, -accelerator=>'Ctrl-q'); #Search Menu my $button_search = $menu->Menubutton(-text=>'Search', -background=>'gray', -activebackground=>'blue', -foreground=>'black',) ->pack(-side=>'left'); $button_search -> command(-label=>'Search by Id', -activebackground=>'blue', -foreground=>'black', -command=>\&search_by_id, -accelerator => 'Ctrl-i'); $button_search -> command(-label=>'Search by Name', -activebackground=>'blue', -foreground=>'black', -command=>\&search_by_name, -accelerator =>'Ctrl-n'); $button_search -> command(-label=>'Search by Blast', -activebackground=>'blue', -foreground=>'black', -command=>\&search_by_blast, -accelerator => 'Ctrl-b'); #Prediction Menu my $button_predict = $menu->Menubutton(-text=>'Predict', -background=>'gray', -activebackground=>'blue', -foreground=>'black',) ->pack(-side=>'left'); $button_predict -> command(-label=>'SVM prediction', -activebackground=>'blue', -foreground=>'black', -command=>\&predict_by_svm, -accelerator => 'Alt-s'); $button_predict -> command(-label=>'PSORT prediction', -activebackground=>'blue', -foreground=>'black', -command=>\&predict_by_psort, -accelerator => 'Alt-p'); #Feed menu my $button_feed = $menu->Menubutton(-text=>'Feed', -background=>'gray', -activebackground=>'blue', -foreground=>'black',) ->pack(-side=>'left'); $button_feed -> command(-label=>'Feed', -activebackground=>'blue', -foreground=>'black', -command=>\&feed_entry, -accelerator=>'Ctrl-f'); #Help Menu my $button_help = $menu->Menubutton(-text=>'Help', -background=>'gray', -activebackground=>'blue', -foreground=>'black',) ->pack(-side=>'left'); $button_help -> command(-label=>'Help', -activebackground=>'blue', -foreground=>'black', -command=>\&help_text); $button_help -> command(-label=>'About', -activebackground=>'blue', -foreground=>'black', -command=>\&about_text); # main frame my $mainframe = $main-> Frame(-relief=>'groove', -borderwidth=>3, -background=>'gray') ->pack(-expand=>1,-side=>'top',-fill=>'both'); my $seq_label= $mainframe -> Label( -text=>'The Result Output Area: you could use "save to file" in menu to save. ', -background=>'gray') ->pack(-side=>'top'); my $res_area= $mainframe -> Scrolled('ROText')-> pack(-expand=>1,-fill=>'both'); my $seq_label= $mainframe -> Label( -text=>'Sequence Area: your Sequences (fasta format) here, Open a fasta file or mannually input sequences Log Area: Your operations', -background=>"gray") ->pack(-side=>'top',-anchor=>'nw'); my $seq_area= $mainframe -> Scrolled('Text') ->pack(-side=>'left',-expand=>1,-fill=>'both'); my $log_area= $mainframe -> Scrolled('ROText') ->pack(-side=>'right',-expand=>1,-fill=>'both'); ## key binding $main -> bind('' => \&open_file); $main -> bind('' => \&save_file); $main -> bind('' => sub{$main->destroy}); $main -> bind('' => \&search_by_id); $main -> bind('' => \&search_by_name); $main -> bind('' => \&search_by_blast); $main -> bind('' => \&predict_by_svm); $main -> bind('' => \&predict_by_psort); $main -> bind('' => \&feed_entry); MainLoop(); ## subs sub about_text { my $popup=$main->DialogBox(-title=>"ABOUT",-buttons=>["OK"],); $popup->add("Label", -text=>"SubLocSOAPClient--A Client for SubLoc SOAP Server:\n http://www.bioinfo.tsinghua.edu.cn/dbsubloc.html\nversion 1.0\nby Tiger Chen")->pack; $popup->Show; } sub help_text { my $popup=$main->DialogBox(-title=>"HELP", -buttons=>["OK"],); $popup->add("Label", -text=>"lol, you need help?!\nPlease read the Readme file\nor\nsee http://www.bioinfo.tsinghua.edu.cn/dbsubloc.html",)->pack; $popup->Show; } sub open_file { #my $types = [['All Files', '*.*', ]]; my $openfile = $main-> getOpenFile(); my $file_content=""; open f,$openfile; while () { $file_content.=$_; } close(f); $seq_area -> delete('1.0','end'); $seq_area -> insert('end',$file_content); return 1; } sub save_file { #my $types = [['All Files', '*.*', ]]; my $savefile = $main -> getSaveFile(); my $file_content = $res_area-> get('1.0','end'); open f, ">$savefile"; print f $file_content; close(f); return 1; } sub search_by_id { my $dbname="SWISSPROT"; my ($id,$de,$lc,$cx,$os,$sq)=(1,0,1,0,0,0); my @pl = qw/-side top -pady 2 -anchor w/; my $popup=$main->DialogBox(-title=>"search by id",-buttons => ['OK','Cancel']); $popup -> geometry("250x410"); $popup -> add('Label',-text=>'select id type')->pack(@pl); $popup -> add('Radiobutton',-text => 'SWISSPROT',-variable => \$dbname,-relief =>'flat',-anchor=>'w',-value=>'SWISSPROT')->pack(@pl); $popup -> add('Radiobutton',-text => 'GO', -variable => \$dbname, -relief => 'flat',-anchor=>'w',-value=>'GO')->pack(@pl); $popup -> add('Radiobutton',-text => 'DBSUBLOC', -variable => \$dbname, -relief=>'flat',-anchor=>'w',-value=>'DBSUBLOC') ->pack(@pl); $popup -> add('Label',-text=>'Input the id')->pack(@pl); my $id_entry = $popup -> add('Entry')->pack(@pl); #$popup -> add('Button',-text=>'Search')->pack(); #$popup -> add('Button',-text=>'Cancel ',-command=>sub{$popup->destroy})->pack(); $popup -> add('Label',-text=>'Select what fields you want to display')->pack(@pl); $popup -> add('Checkbutton',-text=>'DBSubLoc ID',-variable=>\$id,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'SubCellular Location',-variable=>\$lc,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Cross Database Reference',-variable=>\$cx,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Description',-variable=>\$de,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Organism',-variable=>\$os,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Sequence',-variable=>\$sq,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Label',-text=>"Note that the Search maybe quite slow\nPlease be patient")->pack(@pl); my $button = $popup->Show; if($button eq "OK") { my $id = $id_entry ->get; $log_area->insert('end',"Your Search by id: type=$dbname, id=$id\n"); #my $search_result="DBSubLoc ID\tDescription\tSubCellular Location\tOrganism\tCross Database Reference\tSequence\n"; my $search_result=""; my $returnValue = $server -> id_search($dbname,$id); for(my $index=0;$index<=$#$returnValue;$index++){ $returnValue->[$index]->{ID} =~ s/\n/ /g; $returnValue->[$index]->{DE} =~ s/\n/ /g; $returnValue->[$index]->{OS} =~ s/\n/ /g; $returnValue->[$index]->{SQ} =~ s/\n/ /g; $returnValue->[$index]->{LC} =~ s/\n/ /g; $returnValue->[$index]->{CX} =~ s/\n/ /g; if($id){ $search_result.= "ID\t".$returnValue->[$index]->{ID}."\n"; } if($de){ $search_result.= "DE\t".$returnValue->[$index]->{DE}."\n"; } if($lc){ $search_result.= "LC\t".$returnValue->[$index]->{LC}."\n"; } if($os){ $search_result.= "OS\t".$returnValue->[$index]->{OS}."\n"; } if($cx){ $search_result.= "CX\t".$returnValue->[$index]->{CX}."\n"; } if($sq){ $search_result.= "SQ\t".$returnValue->[$index]->{SQ}."\n"; } $search_result.="//\n"; } $res_area->delete('1.0','end'); $res_area->insert('end',$search_result); } if($button eq 'Cancel'){ $log_area->insert('end',"Job canceled\n"); } } sub search_by_name { my $name=""; my @pl = qw/-side top -pady 2 -anchor w/; my ($id,$de,$lc,$os,$cx,$sq)=(1,0,1,0,0,0); my $popup=$main->DialogBox(-title=>"search by name",-buttons => ['OK','Cancel']); $popup -> geometry("250x350"); $popup -> add('Label',-text=>'Input the name')->pack(@pl); my $name_entry = $popup -> add('Entry')->pack(@pl); #$popup -> add('Button',-text=>'Search')->pack(); #$popup -> add('Button',-text=>'Cancel ',-command=>sub{$popup->destroy})->pack(); $popup -> add('Label',-text=>'Select what fields you want to display')->pack(@pl); $popup -> add('Checkbutton',-text=>'DBSubLoc ID',-variable=>\$id,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'SubCellular Location',-variable=>\$lc,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Cross Database Reference',-variable=>\$cx,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Description',-variable=>\$de,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Organism',-variable=>\$os,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Checkbutton',-text=>'Sequence',-variable=>\$sq,-relief=>'flat',-anchor=>'w',-onvalue=>1,-offvalue=>0)->pack(@pl); $popup -> add('Label',-text=>"Note that the Search maybe quite slow\nPlease be patient")->pack(@pl); my $button = $popup->Show; if($button eq "OK") { my $name = $name_entry ->get; $log_area->insert('end',"Your Search by name: name=$name\n"); my $search_result="DBSubLoc ID\tDescription\tSubCellular Location\tOrganism\tCross Database Reference\tSequence\n"; my $returnValue = $server -> name_search($name); for(my $index=0;$index<=$#$returnValue;$index++){ $returnValue->[$index]->{ID} =~ s/\n/ /g; $returnValue->[$index]->{DE} =~ s/\n/ /g; $returnValue->[$index]->{OS} =~ s/\n/ /g; $returnValue->[$index]->{SQ} =~ s/\n/ /g; $returnValue->[$index]->{LC} =~ s/\n/ /g; $returnValue->[$index]->{CX} =~ s/\n/ /g; if($id){ $search_result.= "ID\t".$returnValue->[$index]->{ID}."\n"; } if($de){ $search_result.= "DE\t".$returnValue->[$index]->{DE}."\n"; } if($lc){ $search_result.= "LC\t".$returnValue->[$index]->{LC}."\n"; } if($os){ $search_result.= "OS\t".$returnValue->[$index]->{OS}."\n"; } if($cx){ $search_result.= "CX\t".$returnValue->[$index]->{CX}."\n"; } if($sq){ $search_result.= "SQ\t".$returnValue->[$index]->{SQ}."\n"; } $search_result.="//\n"; } $res_area->delete('1.0','end'); $res_area->insert('end',$search_result); } if($button eq 'Cancel'){ $log_area->insert('end',"Job canceled\n"); } } sub search_by_blast { #my $name=""; my @pl = qw/-side top -pady 2 -anchor w/; my $isplain= 1; my $popup=$main->DialogBox(-title=>"search by blast",-buttons => ['Ready','Wait']); $popup -> geometry("320x300"); $popup -> add('Label',-text=>"Please input the sequences in fasta format\ninto the Sequence Area,\nyou can mannually input them or\nyour can load a fasta file using \nOpen File command of the top menubar")->pack(@pl); $popup -> add('Label',-text=>"Note that the Search maybe quite slow\nPlease be patient")->pack(@pl); $popup -> add('Label',-text=>'Select what kind of output you want to display:')->pack(@pl); $popup -> add('Radiobutton',-text => 'BLAST ORIGINAL OUTPUT',-variable => \$isplain,-relief =>'flat',-anchor=>'w',-value=>1)->pack(@pl); $popup -> add('Radiobutton',-text => 'PARSED OUTPUT',-variable => \$isplain,-relief =>'flat',-anchor=>'w',-value=>0)->pack(@pl); $popup -> add('Label',-text=>"Input the e-value threshold")->pack(@pl); my $evalue_entry = $popup -> add('Entry')->pack(@pl); my $button = $popup->Show; if($button eq "Ready") { my $evalue=$evalue_entry->get; my $seqio = IO::String -> new($seq_area ->get('1.0','end')); my $fasta = Bio::SeqIO -> new('-fh'=>$seqio,'-format'=>'fasta'); $res_area->delete('1.0','end'); while (my $seq = $fasta->next_seq){ $log_area->insert('end',"Your Search by blast\n"); $log_area->insert('end',($seq->id()).($seq->desc())."evalue:".$evalue.("\n")); $res_area->insert('end',"Your Blast Result for ".($seq->id())." ".($seq->desc())." evalue: ".$evalue.("\n")); if($isplain){ $res_area->insert('end',$server-> blast_search('all','full',$seq->seq(),$evalue)->{plain}); } else{ $res_area->insert('end',$server-> blast_search('all','full',$seq->seq(),$evalue)->{parsed}); } } } if($button eq 'Wait'){ $log_area->insert('end',"Waiting for your sequences...,please fill the sequence area above with a fasta file\n"); } } sub predict_by_svm { my $organism="prokaryote"; my @pl = qw/-side top -pady 2 -anchor w/; my $popup=$main->DialogBox(-title=>"predict by svm",-buttons => ['Ready','Wait']); $popup -> geometry("350x250"); $popup -> add('Label',-text=>"Please input the sequences in fasta format\ninto the Sequence Area,\nyou can mannually input them or\nyour can load a fasta file using \nOpen File command of the top menubar")->pack(@pl); $popup -> add('Label',-text=>"Note that the Search maybe quite slow\nPlease be patient")->pack(@pl); $popup -> add('Label',-text=>'select organism type')->pack(@pl); $popup -> add('Radiobutton',-text => 'prokaryote',-variable => \$organism,-relief =>'flat',-anchor=>'w',-value=>'prokaryote')->pack(@pl); $popup -> add('Radiobutton',-text => 'eukaryote', -variable => \$organism, -relief => 'flat',-anchor=>'w',-value=>'eukaryote')->pack(@pl); my $button = $popup->Show; if($button eq "Ready") { my $seqio = IO::String -> new($seq_area ->get('1.0','end')); my $fasta = Bio::SeqIO -> new('-fh'=>$seqio,'-format'=>'fasta'); $res_area->delete('1.0','end'); while (my $seq = $fasta->next_seq){ $log_area->insert('end',"Your predict by svm\n"); $log_area->insert('end',($seq->id()).($seq->desc()).("\n")); $res_area->insert('end',"Prediction Result for ". ($seq->id()).($seq->desc()).("\n")); if ($organism eq "prokaryote"){ $res_area->insert('end',"Prediction\t".$server-> pro_predict($seq->seq())->{Prediction}."\n"); $res_area->insert('end',"Expected Accuracy\t".$server-> pro_predict($seq->seq())->{ExpectAcc}."\n"); $res_area->insert('end',"Reliability Index\t".$server-> pro_predict($seq->seq())->{RI}."\n"); } if ($organism eq "eukaryote"){ $res_area->insert('end',"Prediction\t".$server-> eu_predict($seq->seq())->{Prediction}."\n"); $res_area->insert('end',"Expected Accuracy\t".$server-> eu_predict($seq->seq())->{ExpectAcc}."\n"); $res_area->insert('end',"Reliability Index\t".$server-> eu_predict($seq->seq())->{RI}."\n"); } } } if($button eq 'Wait'){ $log_area->insert('end',"Waiting for your sequences...,please fill the sequence area above with a fasta file\n"); } } sub predict_by_psort { #my $organism="prokaryotic"; my @pl = qw/-side top -pady 2 -anchor w/; my $popup=$main->DialogBox(-title=>"predict by psort",-buttons => ['Ready','Wait']); $popup -> geometry("350x250"); $popup -> add('Label',-text=>"Please input the sequences in fasta format\ninto the Sequence Area,\nyou can mannually input them or\nyour can load a fasta file using \nOpen File command of the top menubar")->pack(@pl); $popup -> add('Label',-text=>"Note that the Search maybe quite slow\nPlease be patient")->pack(@pl); #$popup -> add('Label',-text=>'select organism type')->pack(@pl); #$popup -> add('Radiobutton',-text => 'prokaryotic',-variable => \$organism,-relief =>'flat',-anchor=>'w',-value=>'prokaryotic')->pack(@pl); #$popup -> add('Radiobutton',-text => 'eukaryotic', -variable => \$organism, -relief => 'flat',-anchor=>'w',-value=>'eukaryotic')->pack(@pl); my $button = $popup->Show; if($button eq "Ready") { my $seqio = IO::String -> new($seq_area ->get('1.0','end')); my $fasta = Bio::SeqIO -> new('-fh'=>$seqio,'-format'=>'fasta'); $res_area->delete('1.0','end'); while (my $seq = $fasta->next_seq){ $log_area->insert('end',"Your predict by psort\n"); $log_area->insert('end',($seq->id()).($seq->desc()).("\n")); $res_area->insert('end',"Prediction Result for ". ($seq->id()).($seq->desc()).("\n")); $res_area->insert('end',"Predicted Location: ".$server-> psort_predict($seq->seq())->{Prediction}."\n"); $res_area->insert('end',"Details: ".$server-> psort_predict($seq->seq())->{Detail}."\n"); } } if($button eq 'Wait'){ $log_area->insert('end',"Waiting for your sequences...,please fill the sequence area above with a fasta file\n"); } } sub feed_entry { my @pl = qw/-side top -pady 2 -anchor w/; my $popup=$main->DialogBox(-title=>"Submit your own sequences to DBSubLoc",-buttons => ['Ready','Wait']); $popup -> geometry("350x250"); $popup -> add('Label',-text=>"Please input the sequences and information\ninto the Sequence Area,\nyou can mannually input them or\nyour can load from a file using \nOpen File command of the top menubar")->pack(@pl); my $button = $popup->Show; if($button eq "Ready"){ my $feeddata=$seq_area -> get('1.0','end'); $res_area->insert('end',$server->feed_entry($feeddata,"","","","","")); } if($button eq "Wait"){ $log_area->insert('end',"Waiting for your own sequences and information...\n"); } }