in reply to Count the sequence length of each entry in the file
G'day davi54,
"I want to count the number of alphabets in each entry, length of each entry, etc."
That's confusing as you combine the counts for all entries in @count. Other variables, outside the while loop, appear misplaced as they look like they're associated with individual entries: I'd expect them to be inside the while loop.
The following code collects all the data that I believe you want. You can combine values for all entries if necessary.
#!/usr/bin/env perl use strict; use warnings; my %results; { local $/ = ''; while (my $record = <DATA>) { $record =~ s/\A>(.+?)$//m; my $entry = $1; $record =~ s/\s//gm; $results{$entry}{len} = length $record; for (0 .. $results{$entry}{len} - 1) { ++$results{$entry}{count}{substr $record, $_, 1}; } } } use Data::Dump; dd \%results; __DATA__ >sp_0005 VQLQESGGGLVQAGGSLRLSCAASGRAVSMYNMGWFRQAPGQERELVAAISRGGSIYYA DSVKGRFTISRDNAKNTLYLQMNNLKPEDTGVYQCRQGSTLGQGTQVTVSS >sp_0017 HVQLVESGGGSVQAGGSLRLTCAASGFTFSNYYMSWVRQAPGKGLEWVSSIYSVGSNGYY ADSVKGRSTISRDNAKNTLYLQMNSLKPEDTAVYYCAAEPGGSWWDAYSYWGQGTQVTVS S
Extract of output:
{ sp_0005 => { count => { A => 9, C => 2, ..., W => 1, Y => 5, }, len => 110, }, sp_0017 => { count => { A => 10, C => 2, ..., W => 5, Y => 10, }, len => 121, }, }
Notes:
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Count the sequence length of each entry in the file
by davi54 (Sexton) on Oct 02, 2020 at 16:54 UTC | |
by kcott (Archbishop) on Oct 03, 2020 at 04:47 UTC |