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