[Bioperl-l] Help with manipulating quality objects PLUS write_seq(args)

Hilmar Lapp hlapp@gnf.org
Wed, 23 Oct 2002 12:49:16 -0700


On Wednesday, October 23, 2002, at 12:38 PM, Brian Desany wrote:

> Here's the code:
>
>
> my ($self,%args) = @_;
> my ($source)  = $self->_rearrange([qw(SOURCE)], %args);
>
> if (!$source || ( ref($source) ne "Bio::Seq::SeqWithQuality" &&
> 		      ref($source) ne "Bio::Seq::PrimaryQual")) {
> 	$self->throw("You must pass a Bio::Seq::SeqWithQuality or a
> Bio::Seq::PrimaryQual object to write_seq as a parameter named 
> \"source\"");
> }
>
>
> In my hands, if @_ = ($callerObj, $primaryQualObj), then $source is 
> set to
> the string 'Bio::Seq::PrimaryQual=HASH(0x68aed8)', not an actual 
> object, so
> that ref($source) returns the empty string, so the method throws.

Not sure what $callerObj is (not $self, right?). Generally speaking 
what _rearrange() does it returns the array of arguments unchanged 
if its length is odd or if the first argument doesn't start with a 
hyphen.

So, if you pass in one (1) argument, $source should be set to that 
argument. If you pass in two arguments, but the first one doesn't 
start with a hyphen, $source should be set to the first argument.

Capturing the args as a hash is certainly not a good idea. Not only 
does it cause the 'odd number of elements' warning if you don't use 
named parameters, it will also turn one argument into two once 
turned back into an array (key with an undef value).

What I'm saying is, if you replace %args with @args, and there is 
either an odd number of arguments or the first argument doesn't 
start with hyphen, $source should be set to the first argument, 
which I believe is what you want. Let me know if this is not true on 
1.1.1 (and which arguments were passed).

	-hilmar

>
> (Plus you get odd number of elements in hash assignment warning)
>
> -Brian.
>
>
>> -----Original Message-----
>> From: Hilmar Lapp [mailto:hlapp@gnf.org]
>> Sent: Wednesday, October 23, 2002 12:35 PM
>> To: bdesany@bcm.tmc.edu; bioperl-l@bioperl.org
>> Subject: RE: [Bioperl-l] Help with manipulating quality objects PLUS
>> write_seq(args)
>>
>>
>>
>>
>>> -----Original Message-----
>>> From: Brian Desany [mailto:bdesany@bcm.tmc.edu]
>>> Sent: Wednesday, October 23, 2002 10:06 AM
>>> To: bioperl-l@bioperl.org
>>> Subject: RE: [Bioperl-l] Help with manipulating quality objects PLUS
>>> write_seq(args)
>>>
>> <snip/>
>>>
>>> On a separate note:
>>>
>>> One thing I did notice is that write_seq takes named
>>> arguments, and uses
>>> _rearrange to get SOURCE.  OTOH, Bio::SeqIO::fasta::write_seq
>>> takes an array
>>> of Seq objects.
>>>
>>> In my code I like to have the correct module chosen at
>>> runtime and call
>>> write_seq without necessarily knowing ahead of time whether
>>> it's a fasta or
>>> qual IO. So therefore I would also like to call write_seq in
>>> the same way
>>> for both.
>>>
>>> Does anyone mind if I change qual.pm so that you can write_seq with
>>>
>>> $io->write_seq($qual);
>>>
>>> in addition to
>>>
>>> $io->write_seq('-source'=>$qual);
>>>
>>
>> _rearrange() should take care of that already. Do you see that
>> it doesn't?
>>
>> 	-hilmar
>>
>
>
--
-------------------------------------------------------------
Hilmar Lapp                            email: lapp at gnf.org
GNF, San Diego, Ca. 92121              phone: +1-858-812-1757
-------------------------------------------------------------