[Bioperl-l] Creating and retrieving seqfeatures by name

Jason Stajich jason@cgt.mc.duke.edu
Fri, 22 Feb 2002 13:03:10 -0500 (EST)


Are you iterested in the getting a feature by name part or are you
interested in the getting the sequence for a feature part?

# get sequences for a feature
$seq->subseq($feature->location()) ; # to get back a string
$seq->trunc($feature->location()) ; # to get back a Bio::SeqI

# get features by name
my @feats
foreach my $f ( $seq->top_SeqFeatures() ) {
  if( $f->primary_id eq $name ) {
	push @feats,$f;
  }
}

I guess it would be nice to have a shortcut method so that one
could do this:

# remember that we don't require features to be unique!
my @feats = $seq->get_features_by_id($name);
foreach my $f ( @feats ) {
  print $seq->subseq($f->location);
}

I'm pretty sure that entire_seq is indeed the entire sequence the feature
is attached to but not necessarily the subseq that the feature is on.
Hmm, I need to check this in my code audit... Happening on the plane
tomorrow I hope.

-j
On Fri, 22 Feb 2002, Chad Matsalla wrote:

>
> Hi All,
>
> I would like to create SeqFeatures and retrieve them by name.
>
> Here is some example code:
>
> my $seq = new Bio::Seq( -seq =>
> 	'atatatatatatatatatatatatatatatatatatatataaatatatatatatatatatata',
> 	-primary_id => 'Chad1');
> my $feature = new Bio::SeqFeature::Generic( -start => '10',
> 					-end => '20');
> $feature->attach_seq(
>                new Bio::PrimarySeq(-seq => $sequence,
>                                    -display_id => "Chads_kewl_feature")
> );
> $seq->add_SeqFeature($feature);
>
>
> So, now how can I get the sequence for "Chads_kewl_feature", by name,
> from $seq?
>
> This is what I want:
>
> my $chads_sequence = $seq->get_feature_sequence(-feature_name =>
> 'Chads_kewl_feature");
>
> _or even better_
>
> my $feature = $seq->get_feature_by_name(-name=>'Chads_kewl_feature');
>
> This is what I was doing:
> my @features = $seq->all_SeqFeatures();
> foreach (@features) {
> 	if ($_->seqname() eq "Chads_kewl_feature") {
> 		print("Chads_kewl_feature's sequence is:\n");
>      		print("\t ".$_->entire_seq()->seq()."\n");
> 	}
> }
>
> Thanks for your help,
>
> Chad Matsalla
>
>
>
>

-- 
Jason Stajich
Duke University
jason@cgt.mc.duke.edu