And on fetching the various chunks, what do you need to do with them? How do you want to organize, manipulate or summarize them? Is each "candidate" uniquely identified by the "candidate number"? If so, do you want a simple listing that shows, e.g.
What you intend to do with the data is an important issue, because it should determine how you set up the appropriate data structure for the task. For example, if the candidate numbers are unique and sequential, you probably want an array of hashes:candidate-number R-score [protein-name ...]
If you're still learning about data structures and references, I'm sure the relevant man pages will supply any other details you may need (perlreftut, perldsc). Use Data::Dumper as well, of course.my @candidates; # should use a hash instead, if my $c_id; # the numbering has lots of big gaps while (<>) { if ( /CANDIDATE\s+(\d+)/ ) { $c_id = $1; } elsif ( /DNA\s+.Note.\s*(\S*.*)/ ) { my $proteins = $1; my @p_set = (); while ( $proteins =~ /\[(NP\s+\d+)\]/g ) { push @p_set, $1; } $candidates[$c_id]{proteins} = [ @pset ]; } elsif ( /R-score\s*=\s*([.\d]+)/ ) { $candidates[$c_id]{rscore} = $1; } }
In reply to Re: regex with variable input
by graff
in thread regex with variable input
by BioGeek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |