Another way is to use the BioInfo modules that I am working on that already have bag compulsion :)
use v6; use BioInfo; my @sequences = ` >seqid AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC `; for @sequences -> $seq { say $seq.Bag; }
In the above code, you are importing a special bioinformatic slang that understands that the string literals between `` are FASTA literals. DNA / RNA / Amino acids are automatically detected, and for this you get a certain class. The object has its own .Bag, which does what you want. In addition to my own modules, there is also a BioPerl6 project.
If you want to read from a file, the following should work for you:
use v6; use BioInfo::Parser::FASTA; use BioInfo::IO::FileParser;
source share