| 1 | package Bio::Tools::Prepeat; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 5 | 1 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | XSLoader::load 'Bio::Tools::Prepeat'; | |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = qw(random_sequence); | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use String::Random qw(random_string); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | our @amino = qw/A C D E F G H I K L M N P Q R S T V W Y/; | |||||||||||||||||||||||||||
| 17 | 1 | our @extamino = 'A'..'Z'; # extended amino acid | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub random_sequence { ref($_[0]) ? shift : undef;random_string('0'x(shift), \@amino) } | ||||||||||||||||||||||||||
|
Subroutine
random_sequence: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 1 | my $pkg = shift; | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | my $arg = ref($_[0]) ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | die "It exists as a non-directory\n" if -e $arg->{wd} && !-d $arg->{wd}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $arg->{"wd"} and not -d $arg->{"wd"}
MC/DC0%0/2
-e $arg->{"wd"} and not -d $arg->{"wd"}
-e $arg->{"wd"}
not -d $arg->{"wd"}
Truth table33%1/3
A and not(B)
A= -e $arg->{"wd"}B= not -d $arg->{"wd"}
| |||||||||||||||||||||||||||||
| 24 | 1 | mkdir abs_path($arg->{wd}); | |||||||||||||||||||||||||||
| 25 | bless { | ||||||||||||||||||||||||||||
| 26 | 1 | wd => abs_path($arg->{wd}), | |||||||||||||||||||||||||||
| 27 | seqarr => undef, | ||||||||||||||||||||||||||||
| 28 | }, $pkg; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub reset { | ||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 1 | my $pkg = shift; | |||||||||||||||||||||||||||
| 33 | 1 | @{$pkg->{seqarr}} = (); | |||||||||||||||||||||||||||
| 34 | 1 | @{$pkg->{acclen}} = (); | |||||||||||||||||||||||||||
| 35 | 1 | $pkg->{built} = 0; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub feed { push @{(shift)->{seqarr}}, map{uc$_}@_ } | ||||||||||||||||||||||||||
|
Subroutine
feed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # cartesian product over @extamino X @extamino | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub bigram_set { | ||||||||||||||||||||||||||
|
Subroutine
bigram_set: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 2 | my @ret; | |||||||||||||||||||||||||||
| 43 | 2 | foreach my $f (@extamino){ | |||||||||||||||||||||||||||
| 44 | 52 | foreach my $s (@extamino){ | |||||||||||||||||||||||||||
| 45 | 1352 | push @ret, $f.$s; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 2 | @ret; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub loadseq { | ||||||||||||||||||||||||||
|
Subroutine
loadseq: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 1 | my $pkg = shift; | |||||||||||||||||||||||||||
| 53 | 1 | ▶ | open F, $pkg->{wd}."/seqs" or die "Cannot load sequence file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | while(chomp($_=<F>)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 13 | push @{$pkg->{seqarr}}, $_; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 1 | close F; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # accumulating lengths | ||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub acclen { | ||||||||||||||||||||||||||
|
Subroutine
acclen: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 2 | my $pkg = shift; | |||||||||||||||||||||||||||
| 63 | 2 | my $sum; | |||||||||||||||||||||||||||
| 64 | 2 | push @{$pkg->{acclen}}, 0; | |||||||||||||||||||||||||||
| 65 | 2 | for (1..$#{$pkg->{seqarr}}){ | |||||||||||||||||||||||||||
| 66 | 24 | $sum += length $pkg->{seqarr}->[$_-1]; | |||||||||||||||||||||||||||
| 67 | 24 | push @{$pkg->{acclen}}, $sum; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub loadidx { | ||||||||||||||||||||||||||
|
Subroutine
loadidx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 1 | my $pkg = shift; | |||||||||||||||||||||||||||
| 73 | 1 | $pkg->{seqarr} = $pkg->{acclen} = undef; | |||||||||||||||||||||||||||
| 74 | 1 | $pkg->loadseq; | |||||||||||||||||||||||||||
| 75 | 1 | $pkg->acclen; | |||||||||||||||||||||||||||
| 76 | 1 | $pkg->{built} = 1; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub buildidx { | ||||||||||||||||||||||||||
|
Subroutine
buildidx: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 1 | my $pkg = shift; | |||||||||||||||||||||||||||
| 81 | 1 | my %fh; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | $pkg->acclen; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | foreach (bigram_set){ | |||||||||||||||||||||||||||
| 86 | 676 | $fh{$_} = new IO::File $pkg->{wd}."/idx.$_", O_CREAT|O_WRONLY|O_TRUNC; | |||||||||||||||||||||||||||
| 87 | 676 | ▶ | die "Cannot open index file $_ for writing\n" unless defined $fh{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | open F, '>', $pkg->{wd}."/seqs"; | |||||||||||||||||||||||||||
| 91 | 1 | my $cnt = 0; | |||||||||||||||||||||||||||
| 92 | 1 | foreach my $seq (@{$pkg->{seqarr}}){ | |||||||||||||||||||||||||||
| 93 | 13 | print F "$seq\n"; | |||||||||||||||||||||||||||
| 94 | 13 | ▶ | for(my $i = 0; $i < length($seq)-1; $i++){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 4122 | my $bigram = substr($seq, $i, 2); | |||||||||||||||||||||||||||
| 96 | 4122 | my $h = $fh{$bigram}; | |||||||||||||||||||||||||||
| 97 | 4122 | print $h ($pkg->{acclen}->[$cnt] + $i)."\n"; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 13 | $cnt++; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 1 | close F; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | $_->close foreach (values %fh); | |||||||||||||||||||||||||||
| 104 | 1 | $pkg->{built} = 1; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # relative position | ||||||||||||||||||||||||||||
| 108 | 75266 | ▶ | sub relpos { | ||||||||||||||||||||||||||
|
Subroutine
relpos: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 75266 | my ($pkg, $abspos) = @_; | |||||||||||||||||||||||||||
| 110 | 75266 | my ($seqid, $pos) = (0, 0); | |||||||||||||||||||||||||||
| 111 | 75266 | ▶ | for( my $i=$#{$pkg->{acclen}} ; $i>=0 ; $i--){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 481073 | ▶ | if( $abspos >= $pkg->{acclen}->[$i] ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 75266 | $pos = $abspos - $pkg->{acclen}->[$i]; | |||||||||||||||||||||||||||
| 114 | 75266 | $seqid = $i; | |||||||||||||||||||||||||||
| 115 | 75266 | last; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 75266 | return ($seqid, $pos); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # absolute position | ||||||||||||||||||||||||||||
| 122 | 9175 | ▶ | sub abspos { | ||||||||||||||||||||||||||
|
Subroutine
abspos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 9175 | my ($pkg, $seqid, $pos) = @_; | |||||||||||||||||||||||||||
| 124 | 9175 | return $pkg->{acclen}->[$seqid] + $pos; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 37633 | ▶ | sub coincidence_length { | ||||||||||||||||||||||||||
|
Subroutine
coincidence_length: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | 37633 | my ($pkg, $prev, $this) = @_; | |||||||||||||||||||||||||||
| 129 | 37633 | my @prevrel = $pkg->relpos($prev); | |||||||||||||||||||||||||||
| 130 | 37633 | my @thisrel = $pkg->relpos($this); | |||||||||||||||||||||||||||
| 131 | 37633 | my @range = @{$pkg->{length}}; | |||||||||||||||||||||||||||
| 132 | 37633 | my @ret; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 37633 | foreach my $len (@range){ | |||||||||||||||||||||||||||
| 135 | 44045 | my $str_a = substr($pkg->{seqarr}->[$prevrel[0]], $prevrel[1], $len); | |||||||||||||||||||||||||||
| 136 | 44045 | my $str_b = substr($pkg->{seqarr}->[$thisrel[0]], $thisrel[1], $len); | |||||||||||||||||||||||||||
| 137 | # print "$len $str_a $str_b$/" if $str_a =~/^ACL/o || $str_b =~ /^ACL/o; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 44045 | ▶ | last if length $str_a != $len || length $str_b != $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $str_a != $len or length $str_b != $len
MC/DC100%2/2
length $str_a != $len or length $str_b != $len
length $str_a != $len
length $str_b != $len
Truth table100%3/3
A or B
A= length $str_a != $lenB= length $str_b != $len
| |||||||||||||||||||||||||||||
| 140 | 43410 | ▶ | last if $str_a ne $str_b; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | # print "$prev, $this => ", substr($pkg->{seqarr}->[$prevrel[0]], $prevrel[1], $pkg->{length}), '/', substr($pkg->{seqarr}->[$thisrel[0]], $thisrel[1], $pkg->{length}), $/; | ||||||||||||||||||||||||||||
| 142 | 9175 | push @ret, [ \@prevrel, \@thisrel, $len ]; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 37633 | \@ret; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | ▶ | use List::Util qw/min/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub query { | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=17 SCAR=28.5
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 1 | my ($pkg, $length) = @_; | |||||||||||||||||||||||||||
| 150 | 1 | ▶ | die "Index files are not built or loaded. Please use 'buildidx' or 'loadidx' first\n" unless $pkg->{built}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | die "Length of a repeat sequence must exceed 3\n" unless $length >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | $pkg->{length} = ref($length) ? [sort{$a<=>$b}@$length] : [ $length ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 1 | open R, '>', $pkg->{wd}."/result"; | |||||||||||||||||||||||||||
| 154 | 1 | my ($prev, $this); | |||||||||||||||||||||||||||
| 155 | 1 | foreach (bigram_set){ | |||||||||||||||||||||||||||
| 156 | 676 | ▶ | next unless -s $pkg->{wd}."/idx.$_"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 368 | ▶ | open F, $pkg->{wd}."/idx.$_" or die "Cannot open index file $_ for query\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 368 | my @posarr; | |||||||||||||||||||||||||||
| 159 | 368 | ▶ | while ( chomp ($_ = <F>) ){ push @posarr, $_; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 368 | my %checked; | |||||||||||||||||||||||||||
| 162 | 368 | foreach $prev (@posarr){ | |||||||||||||||||||||||||||
| 163 | 4122 | ▶ | next if $checked{$prev}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 4122 | foreach $this (@posarr){ | |||||||||||||||||||||||||||
| 165 | 79724 | ▶ | if($this - $prev > min( @{$pkg->{length}})){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 37633 | my $occs = $pkg->coincidence_length($prev, $this); | |||||||||||||||||||||||||||
| 167 | 37633 | ▶ | if(ref $occs){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 37633 | foreach my $occ (@{$occs}){ | |||||||||||||||||||||||||||
| 169 | 9175 | $checked{$pkg->abspos($occ->[0]->[0], $occ->[0]->[1])} = 1; | |||||||||||||||||||||||||||
| 170 | # print substr($pkg->{seqarr}->[$occ->[0]->[0]],$occ->[0]->[1], $occ->[2]),$/; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | print R | ||||||||||||||||||||||||||||
| 173 | join ' ', | ||||||||||||||||||||||||||||
| 174 | 9175 | substr($pkg->{seqarr}->[$occ->[0]->[0]], | |||||||||||||||||||||||||||
| 175 | $occ->[0]->[1], $occ->[2]), | ||||||||||||||||||||||||||||
| 176 | 9175 | "@{$occ->[0]} @{$occ->[1]}\n"; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 368 | close F; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | 1 | close R; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | open R, $pkg->{wd}."/result" or die "Cannot open result file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 1 | my $ret; | |||||||||||||||||||||||||||
| 188 | 1 | ▶ | while(chomp($_=<R>)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 9175 | my @e = split /\s/, $_; | |||||||||||||||||||||||||||
| 190 | 9175 | $ret->{$e[0]}->{join q/ /,@e[1..2]} = 1; | |||||||||||||||||||||||||||
| 191 | 9175 | $ret->{$e[0]}->{join q/ /,@e[3..4]} = 1; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 1 | close R; | |||||||||||||||||||||||||||
| 194 | 1 | foreach (keys %{$ret}){ | |||||||||||||||||||||||||||
| 195 | $ret->{$_} = [ | ||||||||||||||||||||||||||||
| 196 | 6778 | sort{ $a->[0] <=> $b->[0] } | |||||||||||||||||||||||||||
| 197 | 6552 | sort{ $a->[1] <=> $b->[1] } | |||||||||||||||||||||||||||
| 198 | 7582 | map { [split/ /] } | |||||||||||||||||||||||||||
| 199 | 2692 | keys %{$ret->{$_}} | |||||||||||||||||||||||||||
| 200 | ]; | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 1 | $ret; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 1 | ▶ | sub cleanidx { | ||||||||||||||||||||||||||
|
Subroutine
cleanidx: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 207 | 1 | ▶ | map{unlink $_} glob($_[0]->{wd}."/*"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 208 | 1 | rmdir $_[0]->{wd}; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 1 | 1; | |||||||||||||||||||||||||||
| 214 | __END__ | ||||||||||||||||||||||||||||