[Bioperl-l] Bio::Seq->delete_SeqFeature missing?

Malcolm Cook Malcolm.Cook@ppgx.com
Wed, 9 May 2001 12:55:59 -0700


>
>On Mon, 7 May 2001, Malcolm Cook wrote:
>
>> I note that there are no methods for deleting features from a Bio::Seq
>> object.
>>
>> Am I off base in wanting/expecting to find one?
>>
>> Here's why I want it:
>>
>> I've got to parse files that more-or-less conform to GENBANK
>format, except
>> for that my users have been adding 'funny' features using non-standard
>> terms.
>>
>> Since I don't need to re-write these files with these 'funny features', I
>> simply defined a SeqIO format by creating an object, call it mygb, that
>> inherits from SeqIO::Genbank, with a next_seq method as follows:
>>
>> sub next_seq{
>>   my($self,@args) = @_;
>>   my $seq = $self->SUPER::next_seq(@args);
>>   return unless $seq;
>>   foreach my $feat ($seq->top_SeqFeatures() ) {
>>    .. massage the features
>>
>> After selected features are 'massaged' I want to
>$seq->delete_SeqFeature it.
>
>
>I would do it by creating a new Seq object and adding SeqFeature objects
>that you want - most object environments work far better when you do
>create/destroy cycles rather than edits.
>

Ewan, before I got your advice, I wrote, modelled on add_SeqFeature, the
following:

=head2 delete_SeqFeature

 Title   : delete_SeqFeature - THIS METHOD SEEMS MISSING FROM BIO::SEQ!
 Usage   : $seq->delete_SeqFeature($feat);
           $seq->delete_SeqFeature(@feat);

 Function: Deletes the given feature object (or each of an array of feature
 objects) from the feature array of this sequence. The object passed is
 required to implement the Bio::SeqFeatureI interface.

 Example :

 Returns : TRUE on success

 Args    : A Bio::SeqFeatureI implementing object, or an array of such
objects.

=cut

sub Bio::Seq::delete_SeqFeature {
  my ($self,@feat) = @_;
  my ($fseq,$aseq);
  foreach my $feat ( @feat ) {
	 if ( !$feat->isa("Bio::SeqFeatureI") ) {
	   $self->throw("$feat is not a SeqFeatureI and that's what we expect...");
	 }
       # COMMENTED CODE FROM add_SeqFeature on which this method is
modelled.
       # I have not yet grokked what the correpsonding action on delete
should be (if anything)
	 # 	 if ( $feat->can("entire_seq") ) {
	 # 	   $fseq = $feat->entire_seq;
	 # 	   $aseq = $self->primary_seq;

	 # 	   if ( defined $aseq ) {
	 # 		  if ( defined $fseq ) {
	 # 			 unless ($aseq == $fseq) {
	 # 				$self->warn("$feat has an attached sequence which is not in this
annseq. I worry about this");
	 # 			 }
	 # 		  } else {
	 # 			 if ( $feat->can("attach_seq") ) {
	 # 				# attach it
	 # 				$feat->attach_seq($aseq);
	 # 			 }
	 # 		  }
	 # 	   }								  # end of if aseq
	 # 	 }									  # end of if the feat can entire_seq


	 $self->{'_as_feat'} = [grep {not $_ eq $feat   } @{$self->{'_as_feat'}}];
  }
  return 1;
}
>there is virtually no overhead compared to edits.
>
>
>
>>
>> Make sense?
>>
>> This all works fine except for not being able to delete them features.
>>
>> Thanks,
>>
>> Malcolm Cook