File tree Expand file tree Collapse file tree 6 files changed +151
-0
lines changed Expand file tree Collapse file tree 6 files changed +151
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments