Skip to content

Commit 63fcde6

Browse files
author
grondilu
committed
Merge pull request #5 from grondilu/master
adding six other solutions for Rosalind
2 parents c4d576b + 4d5084a commit 63fcde6

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

rosalind/cons-grondilu.pl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use v6;
2+
my @s = $*IN.lines;
3+
my \N = @s.pick.chars;
4+
5+
my %profile;
6+
%profile{$_} = [0 xx N] for <A C G T>;
7+
8+
for @s[] {
9+
my @dna = .comb;
10+
for kv classify { @dna[$_] }, ^@dna -> $k, $v {
11+
%profile{$k}[$v[]]»++;
12+
}
13+
}
14+
my @profile = %profile<A C G T>;
15+
16+
say my $consensus = [~] gather
17+
for ^N -> \c {
18+
my $max = max map { @profile[$_][c] }, ^4;
19+
take <A C G T>[$_] given first { @profile[$_][c] == $max }, ^4;
20+
}
21+
22+
say .key, ': ', @profile[.value] for enum <A C G T>;
23+
24+
# vim: ft=perl6

rosalind/conv-grondilu.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/perl
2+
use v6;
3+
my ($a, $b) = $*IN.lines;
4+
5+
my %conv; %conv{$_}++ for $a.split(/\s+/) X- $b.split(/\s+/);
6+
.say for max(:by(*.value), %conv).kv.reverse;
7+
8+
# vim: ft=perl6

rosalind/mrna-grondilu.pl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use v6;
2+
constant RNA-codon = Hash.new: <
3+
UUU F CUU L AUU I GUU V
4+
UUC F CUC L AUC I GUC V
5+
UUA L CUA L AUA I GUA V
6+
UUG L CUG L AUG M GUG V
7+
UCU S CCU P ACU T GCU A
8+
UCC S CCC P ACC T GCC A
9+
UCA S CCA P ACA T GCA A
10+
UCG S CCG P ACG T GCG A
11+
UAU Y CAU H AAU N GAU D
12+
UAC Y CAC H AAC N GAC D
13+
UAA Stop CAA Q AAA K GAA E
14+
UAG Stop CAG Q AAG K GAG E
15+
UGU C CGU R AGU S GGU G
16+
UGC C CGC R AGC S GGC G
17+
UGA Stop CGA R AGA R GGA G
18+
UGG W CGG R AGG R GGG G
19+
>;
20+
21+
sub mrna($rna) {
22+
my %count;
23+
%count{.value}++ for RNA-codon;
24+
25+
my $count = 1;
26+
for $rna.comb, 'Stop' {
27+
$count *= %count{$_};
28+
$count %= 1_000_000;
29+
}
30+
return $count;
31+
}
32+
33+
say mrna $*IN.get;
34+
35+
# vim: ft=perl6

rosalind/orf-grondilu.pl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use v6;
2+
constant DNA-codon = Hash.new: <
3+
TTT F CTT L ATT I GTT V
4+
TTC F CTC L ATC I GTC V
5+
TTA L CTA L ATA I GTA V
6+
TTG L CTG L ATG M GTG V
7+
TCT S CCT P ACT T GCT A
8+
TCC S CCC P ACC T GCC A
9+
TCA S CCA P ACA T GCA A
10+
TCG S CCG P ACG T GCG A
11+
TAT Y CAT H AAT N GAT D
12+
TAC Y CAC H AAC N GAC D
13+
TAA Stop CAA Q AAA K GAA E
14+
TAG Stop CAG Q AAG K GAG E
15+
TGT C CGT R AGT S GGT G
16+
TGC C CGC R AGC S GGC G
17+
TGA Stop CGA R AGA R GGA G
18+
TGG W CGG R AGG R GGG G
19+
>;
20+
sub revc($dna) {
21+
$dna.comb.reverse.join.trans:
22+
[<A C T G>] => [<T G A C>]
23+
}
24+
25+
sub orf($dna) {
26+
my %match;
27+
my @match = gather for $dna, revc $dna {
28+
take .match: rx/ ATG [ <[ACGT]>**3 ]*? <before TAA|TAG|TGA> /, :overlap;
29+
};
30+
%match{
31+
[~] map { DNA-codon{$_} }, .match: rx/ <[ACGT]>**3 /, :g
32+
}++ for @match;
33+
return %match.keys;
34+
}
35+
36+
.say for orf $*IN.get;
37+
38+
# vim: ft=perl6

rosalind/spec-grondilu.pl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use v6;
2+
constant monoisotopic-mass-table = Hash.new: <
3+
A 71.03711
4+
C 103.00919
5+
D 115.02694
6+
E 129.04259
7+
F 147.06841
8+
G 57.02146
9+
H 137.05891
10+
I 113.08406
11+
K 128.09496
12+
L 113.08406
13+
M 131.04049
14+
N 114.04293
15+
P 97.05276
16+
Q 128.05858
17+
R 156.10111
18+
S 87.03203
19+
T 101.04768
20+
V 99.06841
21+
W 186.07931
22+
Y 163.06333
23+
>;
24+
25+
sub spec(@weight, :$accuracy = .01) {
26+
my @a = my @b = sort *.Num, @weight;
27+
join '', gather
28+
for @b[1..*] Z- @b[0..*] -> $mass {
29+
take .key given
30+
first { abs($_.value - $mass) < $accuracy },
31+
monoisotopic-mass-table;
32+
}
33+
}
34+
print spec $*IN.lines;
35+
36+
# vim: ft=perl6

rosalind/sseq-grondilu.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use v6;
2+
my ($dna, $search) = $*IN.lines;
3+
4+
my $pos = 0;
5+
say gather for $search.comb -> $c {
6+
$dna ~~ m:c($pos)/$c/;
7+
take $pos = $/.from + 1;
8+
}
9+
10+
# vim: ft=perl6

0 commit comments

Comments
 (0)