| 1 | package BioX::SeqUtils::RandomSequence; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Class::Std; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Class::Std::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Bio::Tools::CodonTable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use version; our $VERSION = qv('0.9.4'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||
| 13 | 2 | my %type_of :ATTR( :get<type> :set<type> :default<'2'> :init_arg<y> ); | |||||||||||||||||||||||||||
| 14 | 2 | my %length_of :ATTR( :get<length> :set<length> :default<'2'> :init_arg<l> ); | |||||||||||||||||||||||||||
| 15 | 2 | my %table_of :ATTR( :get<table> :set<table> :default<'1'> :init_arg<s> ); | |||||||||||||||||||||||||||
| 16 | 2 | my %a_freq_of :ATTR( :get<a_freq> :set<a_freq> :default<'1'> :init_arg<a> ); | |||||||||||||||||||||||||||
| 17 | 2 | my %c_freq_of :ATTR( :get<c_freq> :set<c_freq> :default<'1'> :init_arg<c> ); | |||||||||||||||||||||||||||
| 18 | 2 | my %g_freq_of :ATTR( :get<g_freq> :set<g_freq> :default<'1'> :init_arg<g> ); | |||||||||||||||||||||||||||
| 19 | 2 | my %t_freq_of :ATTR( :get<t_freq> :set<t_freq> :default<'1'> :init_arg<t> ); | |||||||||||||||||||||||||||
| 20 | 2 | my %tmpl_of :ATTR( :get<tmpl> :set<tmpl> :default<''> ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | sub START { | ||||||||||||||||||||||||||
|
Subroutine
START: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 1 | my ($self, $ident, $arg_ref) = @_; | |||||||||||||||||||||||||||
| 24 | 1 | $self->_check_type(); | |||||||||||||||||||||||||||
| 25 | 1 | $self->_reset_tmpl(); | |||||||||||||||||||||||||||
| 26 | 1 | return; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub rand_seq { | ||||||||||||||||||||||||||
|
Subroutine
rand_seq: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $type; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( defined $arg_ref->{type} ) { $type = $arg_ref->{type}; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | 0 | elsif ( defined $arg_ref->{length} ) { $type = 'dna'; } # Type not defined but length is = DNA | |||||||||||||||||||||||||||
| 35 | 0 | else { $type = $self->get_type(); } | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $type =~ m/^2/ ) { $arg_ref->{length} = 2; return $self->rand_dna( $arg_ref ); } | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 38 | 0 | elsif ( $type =~ m/^d/ ) { return $self->rand_dna( $arg_ref ); } | |||||||||||||||||||||||||||
| 39 | 0 | elsif ( $type =~ m/^r/ ) { return $self->rand_rna( $arg_ref ); } | |||||||||||||||||||||||||||
| 40 | 0 | elsif ( $type =~ m/^p/ ) { return $self->rand_pro( $arg_ref ); } | |||||||||||||||||||||||||||
| 41 | 0 | elsif ( $type =~ m/^s/ ) { return $self->rand_pro_set( $arg_ref ); } | |||||||||||||||||||||||||||
| 42 | 0 | return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6 | ▶ | sub rand_dna { | ||||||||||||||||||||||||||
|
Subroutine
rand_dna: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 6 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Set parameters redefined by this method | ||||||||||||||||||||||||||||
| 49 | 6 | $self->_args_to_attributes( $arg_ref ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Create random nucleotide sequence of specified length | ||||||||||||||||||||||||||||
| 52 | 6 | my $tmpl_length = $self->get_length(); | |||||||||||||||||||||||||||
| 53 | 6 | my $nucleotides = $self->randomize_tmpl(); | |||||||||||||||||||||||||||
| 54 | 6 | ▶ | while ( length($nucleotides) < $tmpl_length ) { $nucleotides .= $self->randomize_tmpl(); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 6 | $nucleotides =~ s/^([ACGT]{$tmpl_length}).*$/$1/; | |||||||||||||||||||||||||||
| 56 | 6 | return $nucleotides; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | sub rand_rna { | ||||||||||||||||||||||||||
|
Subroutine
rand_rna: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 1 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 61 | 1 | my $nucleotides = $self->rand_dna( $arg_ref ); | |||||||||||||||||||||||||||
| 62 | 1 | $nucleotides =~ s/T/U/g; | |||||||||||||||||||||||||||
| 63 | 1 | return $nucleotides; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub rand_pro { | ||||||||||||||||||||||||||
|
Subroutine
rand_pro: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 1 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Set parameters redefined by this method | ||||||||||||||||||||||||||||
| 70 | 1 | $self->_args_to_attributes( $arg_ref ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | my $opt_l = $arg_ref->{l} ? $arg_ref->{l} * 3 : $self->get_length() * 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 1 | my $seq = $self->rand_dna({ l => $opt_l }); | |||||||||||||||||||||||||||
| 74 | 1 | my $codon_table = Bio::Tools::CodonTable->new( -id => $self->get_table() ); | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $codon_table->name() eq '' ) { print " Error: Codon Table " . $self->get_table() . " not defined.\n"; exit; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | my $protein = $codon_table->translate( $seq ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | return $protein; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | ▶ | sub rand_pro_set { | ||||||||||||||||||||||||||
|
Subroutine
rand_pro_set: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 2 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # Set parameters redefined by this method | ||||||||||||||||||||||||||||
| 85 | 2 | $self->_args_to_attributes( $arg_ref ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | ▶ | my $opt_l = $arg_ref->{l} ? $arg_ref->{l} * 3 : $self->get_length() * 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 2 | my $seq = $self->rand_dna({ l => $opt_l + 1 }); | |||||||||||||||||||||||||||
| 89 | 2 | my $seq1 = $seq; $seq1 =~ s/.$//; # Remove the last base | |||||||||||||||||||||||||||
| 90 | 2 | my $seq2 = $seq; $seq2 =~ s/^.//; # Remove the first base | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | my $codon_table = Bio::Tools::CodonTable->new( -id => $self->get_table() ); | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( $codon_table->name() eq '' ) { print " Error: Codon Table " . $self->get_table() . " not defined.\n"; exit; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 2 | my $protein1 = $codon_table->translate( $seq1 ); | |||||||||||||||||||||||||||
| 95 | 2 | my $protein2 = $codon_table->translate( $seq2 ); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | return wantarray() ? ( $protein1, $protein2 ) : [ $protein1, $protein2 ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2053 | ▶ | sub randomize_tmpl { | ||||||||||||||||||||||||||
|
Subroutine
randomize_tmpl: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 2053 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 102 | 2053 | my $tmpl = $self->get_tmpl(); | |||||||||||||||||||||||||||
| 103 | 2053 | my @tmpl = @$tmpl; | |||||||||||||||||||||||||||
| 104 | 2053 | ▶ | for ( my $i = @tmpl; $i >= 0; --$i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 10265 | my $j = int rand ($i + 1); | |||||||||||||||||||||||||||
| 106 | 10265 | ▶ | next if $i == $j; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 5617 | @tmpl[$i,$j] = @tmpl[$j,$i]; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 2 | ▶ | no warnings 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 2053 | return join("", @tmpl); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 9 | ▶ | sub _args_to_attributes { | ||||||||||||||||||||||||||
|
Subroutine
_args_to_attributes: called CC=10 SCAR=30.8
| |||||||||||||||||||||||||||||
| 114 | 9 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( defined $arg_ref->{y} ) { $self->set_type( $arg_ref->{y} ); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 9 | ▶ | if ( defined $arg_ref->{l} ) { $self->set_length( $arg_ref->{l} ); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 9 | my $freq_changed = 0; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( defined $arg_ref->{a} ) { $self->set_a_freq( $arg_ref->{a} ); $freq_changed++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( defined $arg_ref->{c} ) { $self->set_c_freq( $arg_ref->{c} ); $freq_changed++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ( defined $arg_ref->{g} ) { $self->set_g_freq( $arg_ref->{g} ); $freq_changed++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( defined $arg_ref->{t} ) { $self->set_t_freq( $arg_ref->{t} ); $freq_changed++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # All frequencies must be set together or they are all reset to 1 | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $freq_changed && $freq_changed < 4 ) { $self->set_a_freq( 1 ); $self->set_c_freq( 1 ); $self->set_g_freq( 1 ); $self->set_t_freq( 1 ); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$freq_changed and $freq_changed < 4
MC/DC0%0/2
$freq_changed and $freq_changed < 4
$freq_changed
$freq_changed < 4
Truth table33%1/3
A and B
A= $freq_changedB= $freq_changed < 4
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 9 | $self->_check_type(); | |||||||||||||||||||||||||||
| 130 | 9 | ▶ | $self->_reset_tmpl() if $freq_changed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 9 | return; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 10 | ▶ | sub _check_type { | ||||||||||||||||||||||||||
|
Subroutine
_check_type: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||
| 135 | 10 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 136 | 10 | my $type = $self->get_type(); | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ( $type =~ m/^[^2drps]/ ) { print STDERR " Error: Type (y) must be 2, d, r, p, or s.\n"; exit; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 10 | return; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub _reset_tmpl { | ||||||||||||||||||||||||||
|
Subroutine
_reset_tmpl: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | 1 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||
| 143 | 1 | my @tmpl = split( //, 'A' x $self->get_a_freq() . | |||||||||||||||||||||||||||
| 144 | 'C' x $self->get_c_freq() . | ||||||||||||||||||||||||||||
| 145 | 'G' x $self->get_g_freq() . | ||||||||||||||||||||||||||||
| 146 | 'T' x $self->get_t_freq() ); | ||||||||||||||||||||||||||||
| 147 | 1 | $self->set_tmpl( \@tmpl ); | |||||||||||||||||||||||||||
| 148 | 1 | return; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||