1# BioPerl module for Bio::Tools::Run::Genscan 2# 3# Please direct questions and support issues to <bioperl-l@bioperl.org> 4# 5# Cared for by 6# 7# Copyright Balamurugan Kumarasamy 8# 9# You may distribute this module under the same terms as perl itself 10# POD documentation - main docs before the code 11 12=head1 NAME 13 14Bio::Tools::Run::Genscan - Object for identifying genes in a 15given sequence given a matrix(for appropriate organisms). 16 17=head1 SYNOPSIS 18 19 # Build a Genscan factory 20 my $param = ('MATRIX'=>HumanIso.smat); 21 my $factory = Bio::Tools::Run::Genscan->new($param); 22 23 # Pass the factory a Bio::Seq object 24 #@genes is an array of Bio::Tools::Predictions::Gene objects 25 my @genes = $factory->run($seq); 26 27=head1 DESCRIPTION 28 29Genscan is a gene identifying program developed by Christopher Burge 30http://genes.mit.edu/burgelab/ 31 32By default it looks for an executable called I<genscan> and data/parameter files 33in the directory specified by the I<GENSCANDIR> environmental variable. 34 35=head1 FEEDBACK 36 37=head2 Mailing Lists 38 39User feedback is an integral part of the evolution of this and other 40Bioperl modules. Send your comments and suggestions preferably to one 41of the Bioperl mailing lists. Your participation is much appreciated. 42 43 bioperl-l@bioperl.org - General discussion 44 http://bioperl.org/wiki/Mailing_lists - About the mailing lists 45 46=head2 Support 47 48Please direct usage questions or support issues to the mailing list: 49 50I<bioperl-l@bioperl.org> 51 52rather than to the module maintainer directly. Many experienced and 53reponsive experts will be able look at the problem and quickly 54address it. Please include a thorough description of the problem 55with code and data examples if at all possible. 56 57=head2 Reporting Bugs 58 59Report bugs to the Bioperl bug tracking system to help us keep track 60the bugs and their resolution. Bug reports can be submitted via the 61web: 62 63 http://redmine.open-bio.org/projects/bioperl/ 64 65=head1 AUTHOR - Bala 66 67Email savikalpa@fugu-sg.org 68 69=head1 APPENDIX 70 71The rest of the documentation details each of the object 72methods. Internal methods are usually preceded with a _ 73 74=cut 75 76package Bio::Tools::Run::Genscan; 77 78use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR 79 $PROGRAMNAME @GENSCAN_PARAMS %OK_FIELD); 80use strict; 81use Bio::Seq; 82use Bio::SeqIO; 83use Bio::Root::Root; 84use Bio::Root::IO; 85use Bio::Factory::ApplicationFactoryI; 86use Bio::Tools::Genscan; 87use Bio::Tools::Run::WrapperBase; 88 89@ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase); 90 91BEGIN { 92 @GENSCAN_PARAMS=qw(MATRIX VERBOSE QUIET); 93 foreach my $attr ( @GENSCAN_PARAMS) 94 { $OK_FIELD{$attr}++; } 95} 96 97=head2 program_name 98 99 Title : program_name 100 Usage : $factory>program_name() 101 Function: holds the program name 102 Returns: string 103 Args : None 104 105=cut 106 107sub program_name { 108 return 'genscan'; 109} 110 111=head2 program_dir 112 113 Title : program_dir 114 Usage : $factory->program_dir(@params) 115 Function: returns the program directory, obtained from ENV variable. 116 Returns: string 117 Args : 118 119=cut 120 121sub program_dir { 122 return Bio::Root::IO->catfile($ENV{GENSCANDIR}); 123} 124 125 126 sub AUTOLOAD { 127 my $self = shift; 128 my $attr = $AUTOLOAD; 129 $attr =~ s/.*:://; 130 $attr = uc $attr; 131 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr}; 132 $self->{$attr} = shift if @_; 133 return $self->{$attr}; 134} 135 136sub new { 137 my ($class,@args) = @_; 138 my $self = $class->SUPER::new(@args); 139 my ($attr, $value); 140 while (@args) { 141 $attr = shift @args; 142 $value = shift @args; 143 next if( $attr =~ /^-/ ); # don't want named parameters 144 $self->$attr($value); 145 } 146 return $self; 147} 148 149=head2 predict_genes() 150 151 Title : predict_genes() 152 Usage : DEPRECATED: use $obj->run($seq) instead 153 Function: Runs genscan and creates an array of Genes 154 Returns : An array of Bio::Tools::Prediction::Gene objects 155 Args : A Bio::PrimarySeqI 156 157=cut 158 159sub predict_genes{ 160 return shift->run(@_); 161} 162 163=head2 run 164 165 Title : run 166 Usage : $obj->run($seq) 167 Function: Runs genscan and creates an array of Genes 168 Returns : An array of Bio::Tools::Prediction::Gene objects 169 Args : A Bio::PrimarySeqI 170 171=cut 172 173sub run { 174 my ($self,$seq) = @_; 175 my $infile1 = $self->_writeSeqFile($seq); 176 $self->_set_input($infile1); 177 my @feat = $self->_run(); 178 return @feat; 179} 180 181=head2 _run 182 183 Title : _run 184 Usage : $obj->_run() 185 Function: Internal(not to be used directly) 186 Returns : An array of Bio::Tools::Prediction::Gene objects 187 Args : 188 189=cut 190 191sub _run { 192 193 my ($self) = @_; 194 my @genes; 195 my $gene; 196 197 my $str = $self->executable.' '.$self->MATRIX.' '.$self->{'input'}; 198 if($self->verbose){ 199 $str.=" -v "; 200 } 201 if($self->quiet){ 202 my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null'; 203 open(STDERR,">$null"); 204 } 205 unless (open(GENSCAN, "$str |")){ 206 $self->warn("Cannot run $str"); 207 } 208 close(STDERR); 209 my $genScanParser = Bio::Tools::Genscan->new(-fh=> \*GENSCAN); 210 211 212 while( $gene = $genScanParser->next_prediction()){ 213 push(@genes, $gene); 214 } 215 $self->cleanup(); 216 return @genes; 217} 218 219=head2 _set_input() 220 221 Title : _set_input 222 Usage : obj->_set_input($matrixFile,$seqFile) 223 Function: Internal(not to be used directly) 224 Returns : 225 Args : 226 227=cut 228 229sub _set_input() { 230 my ($self,$infile1) = @_; 231 $self->{'input'}=$infile1; 232} 233 234=head2 _writeSeqFile() 235 236 Title : _writeSeqFile 237 Usage : obj->_writeSeqFile($seq) 238 Function: Internal(not to be used directly) 239 Returns : 240 Args : 241 242=cut 243 244 245sub _writeSeqFile(){ 246 my ($self,$seq) = @_; 247 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir); 248 my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'fasta'); 249 $in->write_seq($seq); 250 $in->close(); 251 close($tfh); 252 undef $tfh; 253 return $inputfile; 254} 255 2561; 257