Bioinformatics/Global alignment: Difference between revisions

Content added Content deleted
(added Raku programming solution)
m (→‎{{header|Raku}}: more idiomatic)
Line 523: Line 523:
loop ( my $offset = 0, my \S1 = $ = '' ; ; $offset++ ) {
loop ( my $offset = 0, my \S1 = $ = '' ; ; $offset++ ) {
S1 = s1.substr: $offset ;
S1 = s1.substr: $offset ;
with S1.index(s2.substr(0,1)) -> $p { $offset += $p } else { return 0 }
with S1.index(s2.substr(0,1)) -> $p { $offset += $p } else { return False }
S1 = s1.substr: $offset ;
S1 = s1.substr: $offset ;
return s1.chars - $offset if s2.starts-with: S1
return s1.chars - $offset if s2.starts-with: S1
Line 530: Line 530:


sub deduplicate {
sub deduplicate {
my @sorted = @_.unique.sort: { $^a.chars <=> $^b.chars } ; # by length
my @sorted = @_.unique.sort: *.chars; # by length
gather while ( my $target = shift @sorted ) {
gather while ( my $target = shift @sorted ) {
take $target unless @sorted.grep: { .contains: $target }
take $target unless @sorted.grep: { .contains: $target }
Line 542: Line 542:
my \sup = $ = @perm[0];
my \sup = $ = @perm[0];
for @perm.rotor(2 => -1) -> @duo {
for @perm.rotor(2 => -1) -> @duo {
my \overlapPos = stringCentipede @duo[0], @duo[1];
my \overlapPos = stringCentipede |@duo[0,1];
sup ~= @duo[1].substr: overlapPos;
sup ~= @duo[1].substr: overlapPos;
}
}