Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is fasta file https://raw.githubusercontent.com/sumanstats/Coding-Biology-in-Raku/master/data/GCF_000006945.2_ASM694v2_genomic.fna
- # has a single line with >
- # If it has more > I wish to store the line with > as key and sequence below as string in a hash table
- # This is the function I wrote
- # Any faster alternative?
- sub open_and_parse_fasta($filepath) {
- my @lines = $filepath.IO.lines;
- my %FASTA_hash;
- my $FASTA_label = "";
- for @lines {
- my $line = $_.trim-trailing;
- if $line.starts-with(">") {
- $FASTA_label = $line.substr(1,);
- %FASTA_hash{$FASTA_label} = "";
- } else {
- %FASTA_hash{$FASTA_label} = %FASTA_hash{$FASTA_label} ~ $line;
- }
- }
- return %FASTA_hash
- }
- say open_and_parse_fasta('GCF_000006945.2_ASM694v2_genomic.fna').keys
- # It takes 9 secs in my machine windows 10 !
Add Comment
Please, Sign In to add comment