3 # BioPerl module for Bio::Assembly::IO
5 # based on the Bio::SeqIO module
6 # by Ewan Birney <birney@ebi.ac.uk>
7 # and Lincoln Stein <lstein@cshl.org>
9 # Copyright Robson Francisco de Souza
11 # You may distribute this module under the same terms as perl itself
15 # POD documentation - main docs before the code
19 Bio::Assembly::IO - Handler for Assembly::IO Formats
23 use Bio::Assembly::IO;
25 $in = Bio::Assembly::IO->new(-file=>"<inputfilename",
27 $out = Bio::Assembly::IO->new(-file=>">outputfilename",
30 while ( my $scaffold = $in->next_assembly() ) {
31 # do something with Bio::Assembly::Scaffold instance
33 $out->write_assembly(-scaffold => $scaffold);
41 Bio::Assembly::IO is a handler module for formats in the Assembly::IO set
42 (e.g. Bio::Assembly::IO::phrap).
48 User feedback is an integral part of the evolution of this and other
49 Bioperl modules. Send your comments and suggestions preferably to the
50 Bioperl mailing lists Your participation is much appreciated.
52 bioperl-l@bioperl.org - General discussion
53 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 the bugs and their resolution. Bug reports can be submitted via the
61 http://bugzilla.open-bio.org/
65 Robson Francisco de Souza
67 E-mail: rfsouza@citri.iq.usp.br
75 The rest of the documentation details each of the object
76 methods. Internal methods are usually preceded with a _
80 package Bio
::Assembly
::IO
;
85 use base
qw(Bio::Root::Root Bio::Root::IO);
90 Usage : Bio::Assembly::IO->new(-file =>$filename,-format=>'format')
91 Function: Returns a new assembly stream
92 Returns : A Bio::Assembly::IO::Handler initialised
93 with the appropriate format
94 Args : -file => $filename
100 my ($caller,@args) = @_;
101 my $class = ref($caller) || $caller;
103 # or do we want to call SUPER on an object if $caller is an
105 if( $class =~ /Bio::Assembly::IO::(\S+)/ ) {
106 my ($self) = $class->SUPER::new
(@args);
107 $self->_initialize(@args);
112 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
114 $class->throw("Need at least a file name to proceed!")
115 unless (defined $param{'-file'} || defined $ARGV[0]);
117 my $format = $param{'-format'} ||
118 $class->_guess_format( $param{-file
} || $ARGV[0] );
119 $format = "\L$format"; # normalize capitalization to lower case
121 # normalize capitalization
122 return unless( $class->_load_format_module($format) );
123 return "Bio::Assembly::IO::$format"->new(@args);
127 # _initialize is chained for all SeqIO classes
130 my($self, @args) = @_;
131 # initialize the IO part
132 $self->_initialize_io(@args);
137 Title : next_assembly
138 Usage : $cluster = $stream->next_assembly()
139 Function: Reads the next assembly object from the stream and returns it.
140 Returns : a Bio::Assembly::ScaffoldI compliant object
146 my ($self, $seq) = @_;
147 $self->throw("Sorry, you cannot read from a generic Bio::Assembly::IO object.");
150 =head2 write_assembly
152 Title : write_assembly
153 Usage : $ass_io->write_assembly($assembly)
154 Function: Write the assembly object in Phrap compatible ACE format
155 Returns : 1 on success, 0 for error
156 Args : A Bio::Assembly::Scaffold object
161 shift->throw_not_implemented;
164 =head2 _load_format_module
166 Title : _load_format_module
167 Usage : *INTERNAL Assembly::IO stuff*
168 Function: Loads up (like use) a module at run time on demand
175 sub _load_format_module
{
176 my ($self,$format) = @_;
177 my $module = "Bio::Assembly::IO::" . $format;
181 $ok = $self->_load_module($module);
185 $self: could not load $format - for more details on supported formats please see the Assembly::IO docs
195 Title : _guess_format
196 Usage : $obj->_guess_format($filename)
197 Function: guess format based on file suffix
199 Returns : guessed format of filename (lower case)
201 Notes : formats that _filehandle() will guess includes
210 return unless defined($arg);
211 return 'ace' if ($arg =~ /\.ace\.\d+$/i);
212 return 'phrap' if ($arg =~ /\.phrap\.out$/i);
221 # I need some direction on these!! The module works so I haven't fiddled with them!
222 # Me neither! (rfsouza)
225 my ($class,$val) = @_;
226 return bless {'seqio' => $val}, $class;
231 return $self->{'seqio'}->next_seq() unless wantarray;
233 push @list, $obj while $obj = $self->{'seqio'}->next_seq();
239 $self->{'seqio'}->write_seq(@_);