lib/Bio/ViennaNGS/FeatureChain.pm

filter: Statementstmt 30.3% 27 / 89 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 6 / 15 Podpod 50.0% 2 / 4 totaltotal 28.6% 35 / 122 CC 8 SCAR 22.8
CC
8
Cov
26%
as_bed12_line
30.0
as_bed6_array
12.0
BUILD
6.0
CRAP 9.8
« lib/Bio/ViennaNGS/Fasta.pm ↑ Summary lib/Bio/ViennaNGS/Bed.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2017-06-10 19:02:34 michl>
3  
4 package Bio::ViennaNGS::FeatureChain;
5  
6 1 ▶use Bio::ViennaNGS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'MooseX::Clone';
13  
14 1 has 'type' => (
15 is => 'rw',
16 isa => 'Str', # [exon,intron,SJ,promoter,TSS,...]
17 );
18  
19 has 'chain' => (
20 is => 'rw',
21 traits => ['Array', 'Clone' => {to=>'ArrayRef'}],
22 isa => 'ArrayRef[Bio::ViennaNGS::Feature]',
23 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 1 predicate => 'has_chain',
25 auto_deref => 1,
26 handles => {
27 all => 'elements',
28 count => 'count',
29 add => 'push',
30 pop => 'pop',
31 shift_chain => 'shift',
32 sip => 'sort_in_place',
33 },
34 );
35  
36 1 has 'start' => (
37 is => 'ro',
38 isa => 'Int',
39 predicate => 'has_start',
40 );
41  
42 1 has '_entries' => (
43 is => 'rw',
44 isa => 'Int',
45 predicate => 'nr_entries',
46 init_arg => undef, # make this unsettable via constructor
47 builder => 'count_entries',
48 lazy => 1,
49 );
50  
51 1 with 'Bio::ViennaNGS::FeatureBase';
52  
53 0 ▶sub BUILD {
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
54 0 my $self = shift;
55 0 my $this_function = (caller(0))[3];
56  
57 0 ▶ confess "ERROR [$this_function] \$self->chain not available"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_chain 0 0 0
58 unless ($self->has_chain);
59 0 $self->count_entries();
60 }
61  
62 0 ▶sub count_entries {
Subroutine count_entries: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $self = shift;
64 0 my $cnt = scalar @{$self->chain};
65 0 $self->_entries($cnt);
66 }
67  
68 0 ▶before 'as_bed12_line' => sub {
Subroutine __ANON__: not called CC=1 SCAR=4.1
69 0 my $self = shift;
70 0 my $this_function = (caller(0))[3];
71 0 ▶ $self->sip( sub { $_[0]->start <=> $_[1]->start} )
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 };
73  
74 0 ▶sub sort_chain_ascending {
Subroutine sort_chain_ascending: not called CC=1 SCAR=6.9
Pod documented
75 0 my $self = shift;
76 0 my $this_function = (caller(0))[3];
77 0 ▶ $self->sip( sub { $_[0]->start <=> $_[1]->start} )
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 }
79  
80 0 ▶sub as_bed12_line{
Subroutine as_bed12_line: not called CC=5 SCAR=34.0
81 0 my ($self,$name,$score,$strand) = @_;
82 0 my ($i,$chr,$start,$end,$feat,$bed12,$bsizes,$bstarts);
83 0 my $count=0;
84 0 my @blockSizes = ();
85 0 my @blockStarts = ();
86 # TODO check whether all features have the same chromosome id
87 0 $chr = @{$self->chain}[0]->chromosome;
88 0 $start = @{$self->chain}[0]->start;
89 0 $end = @{$self->chain}[$#{$self->chain}]->end;
90 0 ▶ unless (defined $name){$name=@{$self->chain}[0]->name;}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 0 0
91 0 ▶ unless (defined $score){$score=@{$self->chain}[0]->score;}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $score) 0 0 0
92 0 ▶ unless (defined $strand){$strand=@{$self->chain}[0]->strand;}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $strand) 0 0 0
93  
94 # TODO populate blockSizes and blockStarts
95 0 ▶ for ($i=0;$i<=$#{$self->chain};$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$self->chain;}) 0 0 0
96 0 $count++;
97 0 $feat = @{$self->chain}[$i];
98 0 push @blockSizes, eval($feat->end - $feat->start);
99 0 push @blockStarts, ($feat->start - $start);;
100 }
101 0 $bsizes = join (",",@blockSizes);
102 0 $bstarts = join (",", @blockStarts);
103 0 $bed12 = join ("\t",$chr,$start,$end,$name,$score,$strand,$start,$end,"0",$count,$bsizes,$bstarts);
104 0 return $bed12;
105 }
106  
107 0 ▶sub as_bed6_array{
Subroutine as_bed6_array: not called CC=3 SCAR=24.8
Pod documented
108 0 my $self = shift;
109 0 $self->count_entries();
110 0 my @bed6array=();
111 0 ▶ return 0 unless ($self->has_chain);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_chain 0 0 0
112 0 ▶ for (my $i=0;$i<$self->_entries;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->_entries) 0 0 0
113 push @bed6array, join ("\t",
114 0 @{$self->chain}[$i]->chromosome,
115 0 @{$self->chain}[$i]->start,
116 0 @{$self->chain}[$i]->end,
117 0 @{$self->chain}[$i]->name,
118 0 @{$self->chain}[$i]->score,
119 0 @{$self->chain}[$i]->strand);
120 }
121 0 return \@bed6array;
122 }
123  
124 #sub clone {
125 # my ( $self, %params ) = @_;
126 # $self->meta->clone_object($self, %params);
127 # return $self;
128 #}
129  
130 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 1 1;
133  
134 __END__
« lib/Bio/ViennaNGS/Fasta.pm ↑ Summary lib/Bio/ViennaNGS/Bed.pm »