[Bioperl-l] Interface of the method

Jun Yin jun.yin at ucd.ie
Fri Jun 18 04:59:29 EDT 2010


Hi, Dave,

Thx a million for your reply. But I have to say I am a bit confused.

In the BioPerl guide, 
http://www.bioperl.org/wiki/Advanced_BioPerl

They say that, Capital word should be used for methods returning objects,
for example

$aln->get_SeqFeatures; #which returns Bio::SeqFeature objects

So, $aln->select() actually returns Bio::LocatableSeq objects, I think it is
probably better to use
$aln->select_Seqs;


For the $new_aln=$aln->select_Seqs([1,3,5..10,15],"toggle");
I am thinking of assigning the first argument of the methods as coordinates
or position of the sequences, 
and the rest of the arguments are parameters. Thus an array reference
[1,3,5..10] seems better than a list (1,3,5..10), 
the latter will be hard to recognize the other parameters.

I plan to write:

Sub select_Seqs {
	my($self, at args)=@_;
	my %params;
	my @new_coords;
	if(ref($args[0] eq "ARRAY") {
		my $coords=shift @args;
		#@newcoords=_cont_coord($coords); #do something with the
cords reference
	}
	else {
		#some warning
	}

	#do something with the other parameters
	if(@args) {
		@{$params{@args}}=undef;
		#do something to recognize the other parameters
	}
	#rest of the code

}

And of course, I can write a method as you suggest
$newaln=$aln->select_Seqs('-seqs' => (1, 3, 5..10,15), -toggle => "yes");
Then maybe I should write all the methods in this package, which receives
multiple arguments, using this way.

Cheers,
Jun Yin
Ph.D. student in U.C.D.

Bioinformatics Laboratory
Conway Institute
University College Dublin


-----Original Message-----
From: Dave Messina [mailto:David.Messina at sbc.su.se] 
Sent: Friday, June 18, 2010 12:49 AM
To: Jun Yin
Cc: bioperl-l at lists.open-bio.org
Subject: Re: [Bioperl-l] Interface of the method

Hi Jun,

Great! Glad to hear you're taking on this project.


> This may cause some confusion.So I propose that we should use a more
> consistent way for similar functions.
> 
> For example, the methods of
> 
> select_Seq
> 
> select_columns
> 
> remove_Seq
> 
> remove_columns
> 
> mask_columns
> 
> .
> 
> should have the same interface.

Agreed, absolutely. Consistency is important. I would further propose that
select_Seq be select_seqs, if indeed multiple seqs are to be selected with
this method. Also, capital letters are typically not used in BioPerl method
names. For example, eachSeq was deprecated in favor of each_seq.



> So I suggest, we can do 
> 
> $new_aln=$aln->select_Seq([1,3,5..10,15],"toggle")
> 
> Or
> 
> $new_aln=$aln->select_columns([2.25,34,52..60])


BioPerl tends to use named parameters passed as a hash, e.g.:

	my $in = Bio::SeqIO->new('-format' => 'fasta', '-file' =>
'my.fasta');


So something more like:

	$new_aln = $aln->select_seqs('-seqs' => (1, 3, 5..10,15), -toggle =>
'yes);
	$new_aln = $aln->select_columns('-columns' => (2, 25, 45, 52..60);


Admittedly, it's redundant to say -seqs when the method is named
select_seqs, and maybe less redundant labels can be chosen.

Also, and this is perhaps a minor point, using () instead of [] here for the
set of seqs or columns is better, since [] implies indexing into an array,
which isn't what's being done.


Dave


__________ Information from ESET Smart Security, version of virus signature
database 5099 (20100509) __________

The message was checked by ESET Smart Security.

http://www.eset.com


 

__________ Information from ESET Smart Security, version of virus signature
database 5099 (20100509) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 




More information about the Bioperl-l mailing list