[Bioperl-l] genbank parsing of multiple 'function' tags within primary tag
Fields, Christopher J
cjfields at illinois.edu
Thu Sep 8 18:27:06 UTC 2011
On Sep 8, 2011, at 12:51 PM, galeb abu-ali wrote:
> thanks, Chris! works perfect.
> To make sure I understand what's going on, forcing list context on $locus allows me to get one value at a time,...
You have to be careful in this circumstance; doing this:
my $foo = @bar;
is scalar context on a list, which returns the number of elements in @bar. The following
my ($foo) = @bar;
forces list context and assigns the first value in @bar to $foo but tosses the rest. If you are sure there is only one value in @bar anyway, the above is fine (and is a common perl idiom).
> which is then concatenated with \t to concatenated functions.
I'm just using a simple join() to print off the results. Note the second element in the join list is an embedded join() with comma-sep values for functions.
chris
> thanks again!
>
> galeb
>
> On Thu, Sep 8, 2011 at 12:51 PM, Fields, Christopher J <cjfields at illinois.edu> wrote:
> There is no need to do that if one is using the Bio::SeqFeatureI interface. Note that get_tag_values always returns a list, so to snag a single value for a tag in a scalar, force list context on the LHS by enclosing the variable in ().
>
> chris
>
> -----------------------------
> #!/usr/bin/env perl
>
> use Modern::Perl;
> use Bio::SeqIO;
>
> my $in = Bio::SeqIO->new(-format => 'genbank',
> -file => shift);
>
> while (my $seq = $in->next_seq) {
> for my $feat ($seq->get_SeqFeatures) {
> next unless $feat->primary_tag eq 'CDS';
> my ($locus) = $feat->has_tag('locus_tag') ?
> $feat->get_tag_values('locus_tag') : '';
> my @funcs = $feat->has_tag('function') ?
> $feat->get_tag_values('function') : ();
> say join("\t", $locus, join(',', at funcs));
> }
> }
>
>
>
More information about the Bioperl-l
mailing list