Seq/Utils.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 18 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 100% 75 / 75 CC 12 SCAR 14.5
CC
12
Cov
100%
build_ORF_regex
6.0
all_orfs
6.0
rev_com
2.0
CRAP 4.3
« Seq.pm ↑ Summary Seq/Stream/TwoBit.pm »
1 package BioX::Seq::Utils;
2  
3 3 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our @EXPORT_OK = qw/
10 build_ORF_regex
11 all_orfs
12 rev_com
13 is_nucleic
14 /;
15  
16 4 ▶sub build_ORF_regex {
Subroutine build_ORF_regex: called CC=6 SCAR=17.9
Pod documented
17  
18 4 my ($mode, $min_len) = @_;
19  
20 4 ▶ die "Missing mode"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 1 3 4
21 if (! defined $mode);
22 3 ▶ die "Missing minimum length"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min_len 1 2 3
23 if (! defined $min_len);
24
25 # mode 0 : any set of codons not STOP
26 # mode 1 : must end with STOP codon
27 # mode 2 : must start with START codon
28 # mode 3 : START -> STOP
29  
30  
31 2 my $aasize = int($min_len/3);
32 2 ▶ my $tail_size = $aasize - 1 - ($mode & 0x2 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2 ? : 1 1 2
33 2 my $codon = ".{3}";
34 2 ▶ my $first_codon = $mode & 0x2 ? 'A[TU]G' : '';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2 ? : 1 1 2
35 2 my $stop_codon = "[TU](?:AA|AG|GA|AR|RA)";
36 2 ▶ my $last_codon = $mode & 0x1 ? $stop_codon : '';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 1 ? : 1 1 2
37 2 my $re_orf = qr/
38 \G # anchor at pos() - forces codon boundaries
39 (?:$codon)*? # discard codons before start codon
40 ( # begin matching ORF
41 $first_codon # match start codon
42 (?! $stop_codon ) # (but only if not followed by stop codon)
43 (?: $codon # match codon(s)
44 (?! $stop_codon ) # (but only if not followed by stop codon)
45 ) {$tail_size,} # any only if >= $tail_size codons long
46 $codon # add final codon
47 ) # end matching ORF
48 $last_codon
49 /ix;
50  
51 2 return $re_orf;
52  
53 }
54  
55 4 ▶sub all_orfs {
Subroutine all_orfs: called CC=6 SCAR=17.9
Pod documented
56  
57 4 my ($seq, $mode, $min_len) = @_;
58  
59 4 my $orf_re = build_ORF_regex($mode, $min_len);
60  
61 2 my $len = length $seq;
62 2 my @orfs;
63 2 for my $strand (0..1) {
64 4 ▶ my $str = $strand ? rev_com($seq) : $seq;
Branch: 1 branch
BranchTrueFalseTotal
$strand ? : 2 2 4
65 4 for my $frame (0..2) {
66 12 pos($str) = $frame;
67 12 ▶ while ($str =~ /$orf_re/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$orf_re/g) 9 12 21
68 9 ▶ my ($s, $e) = map {$strand ? $len-$_+1 : $_} ($-[1]+1, $+[1]);
Branch: 1 branch
BranchTrueFalseTotal
$strand ? : 14 4 18
69 9 push @orfs, [$1, $s, $e];
70 }
71 }
72 }
73  
74 2 return @orfs;
75  
76 }
77  
78 6 ▶sub is_nucleic {
Subroutine is_nucleic: called CC=1 SCAR=0.0
Pod documented
79  
80 6 my ($seq) = @_;
81 6 return $seq !~ /[^ACGTUMRWSYKVHDBN.-]/i;
82  
83 }
84  
85 4 ▶sub rev_com {
Subroutine rev_com: called CC=2 SCAR=6.9
Pod documented
86  
87 4 my ($seq) = @_;
88 4 $seq =~ tr/Xx/Nn/;
89 4 ▶ die "Bad input sequence" if (! is_nucleic($seq));
Branch: 1 branch
BranchTrueFalseTotal
unless is_nucleic($seq) 1 3 4
90 3 $seq = reverse $seq;
91 3 $seq =~ tr
92 {ACGTMRWSYKVHDBNacgtmrwsykvhdbn}
93 {TGCAKYWSRMBDHVNtgcakywsrmbdhvn};
94  
95 3 return $seq;
96  
97 }
98  
99 3 1;
100  
101  
102 __END__
« Seq.pm ↑ Summary Seq/Stream/TwoBit.pm »