| 1 | # BioPerl module for Bio::Factory::EMBOSS | ||
| 2 | # | ||
| 3 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||
| 4 | # | ||
| 5 | # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org> | ||
| 6 | # | ||
| 7 | # Copyright Heikki Lehvaslaiho | ||
| 8 | # | ||
| 9 | # You may distribute this module under the same terms as perl itself | ||
| 10 | |||
| 11 | # POD documentation - main docs before the code | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | Bio::Factory::EMBOSS - EMBOSS application factory class | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | # Get an EMBOSS factory | ||
| 20 | use Bio::Factory::EMBOSS; | ||
| 21 | $f = Bio::Factory::EMBOSS -> new(); | ||
| 22 | # Get an EMBOSS application object from the factory | ||
| 23 | $water = $f->program('water') || die "Program not found!\n"; | ||
| 24 | |||
| 25 | # Here is an example of running the application - water can | ||
| 26 | # compare 1 sequence against 1 or more sequences using Smith-Waterman. | ||
| 27 | # Pass a Sequence object and a reference to an array of objects. | ||
| 28 | |||
| 29 | my $wateroutfile = 'out.water'; | ||
| 30 | $water->run({-asequence => $seq_object, | ||
| 31 | -bsequence => \@seq_objects, | ||
| 32 | -gapopen => '10.0', | ||
| 33 | -gapextend => '0.5', | ||
| 34 | -outfile => $wateroutfile}); | ||
| 35 | |||
| 36 | # Now you might want to get the alignment | ||
| 37 | use Bio::AlignIO; | ||
| 38 | my $alnin = Bio::AlignIO->new(-format => 'emboss', | ||
| 39 | -file => $wateroutfile); | ||
| 40 | |||
| 41 | while ( my $aln = $alnin->next_aln ) { | ||
| 42 | # process the alignment -- these will be Bio::SimpleAlign objects | ||
| 43 | } | ||
| 44 | |||
| 45 | =head1 DESCRIPTION | ||
| 46 | |||
| 47 | The EMBOSS factory class encapsulates access to EMBOSS programs. A | ||
| 48 | factory object allows creation of only known applications. | ||
| 49 | |||
| 50 | If you want to check command line options before sending them to the | ||
| 51 | program set $prog-E<gt>verbose to positive integer. The value is | ||
| 52 | passed on to programs objects and the ADC description of the available | ||
| 53 | command line options is parsed and compared to input. | ||
| 54 | |||
| 55 | See also L<Bio::Tools::Run::EMBOSSApplication> and | ||
| 56 | L<Bio::Tools::Run::EMBOSSacd>. | ||
| 57 | |||
| 58 | =head1 FEEDBACK | ||
| 59 | |||
| 60 | =head2 Mailing Lists | ||
| 61 | |||
| 62 | User feedback is an integral part of the evolution of this and other | ||
| 63 | Bioperl modules. Send your comments and suggestions preferably to the | ||
| 64 | Bioperl mailing lists Your participation is much appreciated. | ||
| 65 | |||
| 66 | bioperl-l@bioperl.org - General discussion | ||
| 67 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||
| 68 | |||
| 69 | =head2 Support | ||
| 70 | |||
| 71 | Please direct usage questions or support issues to the mailing list: | ||
| 72 | |||
| 73 | I<bioperl-l@bioperl.org> | ||
| 74 | |||
| 75 | rather than to the module maintainer directly. Many experienced and | ||
| 76 | reponsive experts will be able look at the problem and quickly | ||
| 77 | address it. Please include a thorough description of the problem | ||
| 78 | with code and data examples if at all possible. | ||
| 79 | |||
| 80 | =head2 Reporting Bugs | ||
| 81 | |||
| 82 | Report bugs to the Bioperl bug tracking system to help us keep track | ||
| 83 | the bugs and their resolution. Bug reports can be submitted via the | ||
| 84 | web: | ||
| 85 | |||
| 86 | http://redmine.open-bio.org/projects/bioperl/ | ||
| 87 | |||
| 88 | =head1 AUTHOR - Heikki Lehvaslaiho | ||
| 89 | |||
| 90 | Email heikki-at-bioperl-dot-org | ||
| 91 | |||
| 92 | =head1 APPENDIX | ||
| 93 | |||
| 94 | The rest of the documentation details each of the object | ||
| 95 | methods. Internal methods are usually preceded with a _ | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | # Let the code begin... | ||
| 100 | |||
| 101 | package Bio::Factory::EMBOSS; | ||
| 102 | use vars qw(@ISA $EMBOSSVERSION); | ||
| 103 | use strict; | ||
| 104 | |||
| 105 | use Bio::Root::Root; | ||
| 106 | use Bio::Tools::Run::EMBOSSApplication; | ||
| 107 | use Bio::Factory::ApplicationFactoryI; | ||
| 108 | @ISA = qw(Bio::Root::Root Bio::Factory::ApplicationFactoryI ); | ||
| 109 | |||
| 110 | $EMBOSSVERSION = "2.0.0"; | ||
| 111 | |||
| 112 | sub new { | ||
| 113 | my($class,@args) = @_; | ||
| 114 | my $self = $class->SUPER::new(@args); | ||
| 115 | # set up defaults | ||
| 116 | |||
| 117 | my($location) = $self->_rearrange([qw(LOCATION )], @args); | ||
| 118 | |||
| 119 | $self->{ '_programs' } = {}; | ||
| 120 | $self->{ '_programgroup' } = {}; | ||
| 121 | $self->{ '_groups' } = {}; | ||
| 122 | |||
| 123 | $self->location($location) if $location; | ||
| 124 | |||
| 125 | $self->_program_list; # retrieve info about available programs | ||
| 126 | |||
| 127 | return $self; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | =head2 location | ||
| 132 | |||
| 133 | Title : location | ||
| 134 | Usage : $embossfactory->location | ||
| 135 | Function: get/set the location of EMBOSS programs. | ||
| 136 | Valid values are 'local' and 'novella'. | ||
| 137 | Returns : string, defaults to 'local' | ||
| 138 | Args : string | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | sub location { | ||
| 143 | my ($self, $value) = @_; | ||
| 144 | my %location = ('local' => '1', | ||
| 145 | 'novella' => '1' | ||
| 146 | ); | ||
| 147 | if (defined $value) { | ||
| 148 | $value = lc $value; | ||
| 149 | if ($location{$value}) { | ||
| 150 | $self->{'_location'} = $value; | ||
| 151 | } else { | ||
| 152 | $self->warn("Value [$value] not a valid value for ". | ||
| 153 | "location(). Defaulting to [local]"); | ||
| 154 | $self->{'_location'} = 'local'; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | $self->{'_location'} ||= 'local'; | ||
| 158 | return $self->{'_location'}; | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | =head2 program | ||
| 163 | |||
| 164 | Title : program | ||
| 165 | Usage : $embossfactory->program('program_name') | ||
| 166 | Function: Creates a representation of a single EMBOSS program and issues a | ||
| 167 | warning if the program was not found. | ||
| 168 | Returns : Bio::Tools::Run::EMBOSSApplication object or undef | ||
| 169 | Args : string, program name | ||
| 170 | |||
| 171 | =cut | ||
| 172 | |||
| 173 | sub program { | ||
| 174 | my ($self, $value) = @_; | ||
| 175 | |||
| 176 | unless( $self->{'_programs'}->{$value} ) { | ||
| 177 | $self->warn("Application [$value] is not available!"); | ||
| 178 | return undef; | ||
| 179 | } | ||
| 180 | my $attr = {}; | ||
| 181 | $attr->{name} = $value; | ||
| 182 | $attr->{verbose} = $self->verbose; | ||
| 183 | |||
| 184 | my $appl = Bio::Tools::Run::EMBOSSApplication->new($attr); | ||
| 185 | return $appl; | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | =head2 version | ||
| 190 | |||
| 191 | Title : $self->version | ||
| 192 | Usage : $embossfactory->version() | ||
| 193 | Function: gets the version of EMBOSS programs | ||
| 194 | Throws : if EMBOSS suite is not accessible | ||
| 195 | Returns : version value | ||
| 196 | Args : None | ||
| 197 | |||
| 198 | =cut | ||
| 199 | |||
| 200 | sub version { | ||
| 201 | my ($self) = @_; | ||
| 202 | my $version = `embossversion -auto`; | ||
| 203 | $self->throw("EMBOSS suite of programs is not available") if $?; | ||
| 204 | chop $version; | ||
| 205 | |||
| 206 | # compare versions | ||
| 207 | $self->throw("EMBOSS has to be at least version $EMBOSSVERSION got $version\n") | ||
| 208 | if $version lt $EMBOSSVERSION; | ||
| 209 | |||
| 210 | return $version; | ||
| 211 | } | ||
| 212 | |||
| 213 | |||
| 214 | =head2 Programs | ||
| 215 | |||
| 216 | These methods allow the programmer to query the EMBOSS suite and find | ||
| 217 | out which program names can be used and what arguments can be used. | ||
| 218 | |||
| 219 | =head2 program_info | ||
| 220 | |||
| 221 | Title : program_info | ||
| 222 | Usage : $embossfactory->program_info('emma') | ||
| 223 | Function: Finds out if the program is available. | ||
| 224 | Returns : definition string of the program, undef if program name not known | ||
| 225 | Args : string, prgramname | ||
| 226 | |||
| 227 | =cut | ||
| 228 | |||
| 229 | sub program_info { | ||
| 230 | my ($self, $value) = @_; | ||
| 231 | return $self->{'_programs'}->{$value}; | ||
| 232 | } | ||
| 233 | |||
| 234 | |||
| 235 | =head2 Internal methods | ||
| 236 | |||
| 237 | Do not call these methods directly | ||
| 238 | |||
| 239 | =head2 _program_list | ||
| 240 | |||
| 241 | Title : _program_list | ||
| 242 | Usage : $embossfactory->_program_list() | ||
| 243 | Function: Finds out what programs are available. | ||
| 244 | Writes the names into an internal hash. | ||
| 245 | Returns : true if successful | ||
| 246 | Args : None | ||
| 247 | |||
| 248 | =cut | ||
| 249 | |||
| 250 | sub _program_list { | ||
| 251 | my ($self) = @_; | ||
| 252 | if( $^O =~ /Mac/i ) { return; } | ||
| 253 | { | ||
| 254 | my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null'; | ||
| 255 | local * SAVERR; | ||
| 256 | open SAVERR, ">&STDERR"; | ||
| 257 | open STDERR, ">$null"; | ||
| 258 | open(WOSSOUT, "wossname -auto |") || return; | ||
| 259 | open STDERR, ">&SAVERR"; | ||
| 260 | |||
| 261 | } | ||
| 262 | local $/ = "\n\n"; | ||
| 263 | while(<WOSSOUT> ) { | ||
| 264 | my ($groupname) = (/^([A-Z][A-Z0-9 ]+)$/m); | ||
| 265 | #print $groupname, "\n" if $groupname; | ||
| 266 | $self->{'_groups'}->{$groupname} = [] if $groupname; | ||
| 267 | while ( /^([a-z]\w+) +(.+)$/mg ) { | ||
| 268 | #print "$1\t$2 \n" if $1; | ||
| 269 | $self->{'_programs'}->{$1} = $2 if $1; | ||
| 270 | $self->{'_programgroup'}->{$1} = $groupname if $1; | ||
| 271 | push @{$self->{'_groups'}->{$groupname}}, $1 if $1; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | close(WOSSOUT); | ||
| 275 | |||
| 276 | } | ||
| 277 | |||
| 278 | 1; |