lomSpace has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I am using Bio::Graphics and Bio::SeqIO modules to process a genbank file.
How do I process some and not all of the values from an array reference?
# sorts each feature by its primary tag into a hash # of array references named %sorted_features my %sorted_features; for my $f (@features) { #get cds, primer_bind, and genes features only my $tag = $f->primary_tag; # create a hash of $f keys and $tag values push @{$sorted_features{$tag}},$f; }
There are several features: CDS,exons, genes, mRNAs, misc_RNAs
primer_binds,repeat_regions, and sources. I am only interested in processing
CDS, genes, and primer_binds, and sources.

Presently, all of the features are processed and output to the graphics file.

Any examples would be greatly appreciated.
Lom Space

Replies are listed 'Best First'.
Re: processing data from an array reference
by graff (Chancellor) on Jul 23, 2009 at 05:28 UTC
    Do you mean that when you do this step:
    my $tag = $f->primary_tag;
    the value of $tag is one of: CDS, exons, genes, mRNAs, misc_RNAs, primer_binds, repeat_regions, or sources?

    If that's what is happening, all you need to do is place a condition on the following "push" -- only do the push if the value of $tag is one that you want:

    push @{$sorted_features{$tag}}, $f if ($tag =~ /CDS|genes|primer_b +inds|sources/);
    Or, if you prefer, you can create a hash whose keys are the desired set of feature names, and then the condition can check for the hash key, instead of doing a regex match:
    my %sorted_features; my %want = map { $_ => 1 } qw/CDS genes primer_binds sources/; for my $f ( @features ) { my $tag = $f->primary_tag; push @{$sorted_features{$tag}}, $f if( $want{$tag} ); }
Re: processing data from an array reference
by Anonymous Monk on Jul 23, 2009 at 05:05 UTC