| 1 | package Test::Chado::Common; | ||||||||||
| 2 | { | ||||||||||
| 3 | 1 | $Test::Chado::Common::VERSION = 'v4.1.1'; | |||||||||
| 4 | } | ||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooX::ClassAttribute; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Test::Chado::Types qw/TB/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Test::Builder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Sub::Exporter -setup => { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | exports => { | ||||||||||
| 11 | 'has_cv' => \&_has_cv, | ||||||||||
| 12 | 'has_feature' => \&_has_feature, | ||||||||||
| 13 | 'has_cvterm' => \&_has_cvterm, | ||||||||||
| 14 | 'has_dbxref' => \&_has_dbxref, | ||||||||||
| 15 | 'has_featureloc' => \&_has_featureloc, | ||||||||||
| 16 | }, | ||||||||||
| 17 | groups => { | ||||||||||
| 18 | 'default' => | ||||||||||
| 19 | [qw/has_cv has_dbxref has_cvterm has_feature has_featureloc/] | ||||||||||
| 20 | } | ||||||||||
| 21 | 1 | }; | |||||||||
| 22 | |||||||||||
| 23 | class_has 'test_builder' => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | lazy => 1, | ||||||||||
| 26 | isa => TB, | ||||||||||
| 27 | 0 | ▶ | default => sub { Test::Builder->new } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 1 | ); | |||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub _has_cv { | ||||||||
|
Subroutine
_has_cv: called CC=1 SCAR=5.4
| |||||||||||
| 31 | 1 | my ($class) = @_; | |||||||||
| 32 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 33 | 0 | my ( $schema, $cv, $msg ) = @_; | |||||||||
| 34 | 0 | my $test_builder = $class->test_builder; | |||||||||
| 35 | 0 | ▶ | $test_builder->croak('need a schema') if !$schema; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | $test_builder->croak('need a cv name') if !$cv; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | my $result_class; | |||||||||
| 39 | 0 | ▶ | if ( $schema->isa('Bio::Chado::Schema') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | $result_class = 'Cv::Cv'; | |||||||||
| 41 | } | ||||||||||
| 42 | else { | ||||||||||
| 43 | 0 | $result_class = 'Cv'; | |||||||||
| 44 | } | ||||||||||
| 45 | 0 | my $count | |||||||||
| 46 | = $schema->resultset($result_class)->count( { name => $cv } ); | ||||||||||
| 47 | 0 | $test_builder->ok( $count, $msg ); | |||||||||
| 48 | 0 | return $count; | |||||||||
| 49 | 1 | }; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub _has_feature { | ||||||||
|
Subroutine
_has_feature: called CC=1 SCAR=5.4
| |||||||||||
| 53 | 1 | my ($class) = @_; | |||||||||
| 54 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 55 | 0 | my ( $schema, $name, $msg ) = @_; | |||||||||
| 56 | 0 | my $test_builder = $class->test_builder; | |||||||||
| 57 | 0 | ▶ | $test_builder->croak('need a schema') if !$schema; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | ▶ | $test_builder->croak('need a cv name') if !$name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 0 | my $result_class; | |||||||||
| 61 | 0 | ▶ | if ( $schema->isa('Bio::Chado::Schema') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | $result_class = 'Sequence::Feature'; | |||||||||
| 63 | } | ||||||||||
| 64 | else { | ||||||||||
| 65 | 0 | $result_class = 'Feature'; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | my $count = $schema->resultset($result_class) | |||||||||
| 68 | ->count( { uniquename => $name } ); | ||||||||||
| 69 | 0 | $test_builder->ok( $count, $msg ); | |||||||||
| 70 | 0 | return $count; | |||||||||
| 71 | 1 | }; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | ▶ | sub _has_dbxref { | ||||||||
|
Subroutine
_has_dbxref: called CC=1 SCAR=5.4
| |||||||||||
| 75 | 1 | my ($class) = @_; | |||||||||
| 76 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 77 | 0 | my ( $schema, $xref, $msg ) = @_; | |||||||||
| 78 | 0 | my $test_builder = $class->test_builder; | |||||||||
| 79 | 0 | ▶ | $test_builder->croak('need a schema') if !$schema; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | ▶ | $test_builder->croak('need a dbxref name') if !$xref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 0 | my $result_class; | |||||||||
| 83 | 0 | ▶ | if ( $schema->isa('Bio::Chado::Schema') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | $result_class = 'General::Dbxref'; | |||||||||
| 85 | } | ||||||||||
| 86 | else { | ||||||||||
| 87 | 0 | $result_class = 'Dbxref'; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | my $count | |||||||||
| 91 | = $schema->resultset($result_class) | ||||||||||
| 92 | ->count( { accession => $xref } ); | ||||||||||
| 93 | 0 | $test_builder->ok( $count, $msg ); | |||||||||
| 94 | 0 | return $count; | |||||||||
| 95 | 1 | }; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 1 | ▶ | sub _has_cvterm { | ||||||||
|
Subroutine
_has_cvterm: called CC=1 SCAR=5.4
| |||||||||||
| 99 | 1 | my ($class) = @_; | |||||||||
| 100 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 101 | 0 | my ( $schema, $cvterm, $msg ) = @_; | |||||||||
| 102 | 0 | my $test_builder = $class->test_builder; | |||||||||
| 103 | 0 | ▶ | $test_builder->croak('need a schema') if !$schema; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 0 | ▶ | $test_builder->croak('need a feature name') if !$cvterm; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | |||||||||||
| 106 | 0 | my $result_class; | |||||||||
| 107 | 0 | ▶ | if ( $schema->isa('Bio::Chado::Schema') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | $result_class = 'Cv::Cvterm'; | |||||||||
| 109 | } | ||||||||||
| 110 | else { | ||||||||||
| 111 | 0 | $result_class = 'Cvterm'; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 0 | my $count | |||||||||
| 115 | = $schema->resultset($result_class)->count( { name => $cvterm } ); | ||||||||||
| 116 | 0 | $test_builder->ok( $count, $msg ); | |||||||||
| 117 | 0 | return $count; | |||||||||
| 118 | 1 | }; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 1 | ▶ | sub _has_featureloc { | ||||||||
|
Subroutine
_has_featureloc: called CC=1 SCAR=5.4
| |||||||||||
| 122 | 1 | my ($class) = @_; | |||||||||
| 123 | 0 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 124 | 0 | my ( $schema, $name, $msg ) = @_; | |||||||||
| 125 | 0 | my $test_builder = $class->test_builder; | |||||||||
| 126 | 0 | ▶ | $test_builder->croak('need a schema') if !$schema; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | 0 | ▶ | $test_builder->croak('need a feature name') if !$name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | |||||||||||
| 129 | 0 | my $result_class; | |||||||||
| 130 | 0 | ▶ | if ( $schema->isa('Bio::Chado::Schema') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | $result_class = 'Sequence::Feature'; | |||||||||
| 132 | } | ||||||||||
| 133 | else { | ||||||||||
| 134 | 0 | $result_class = 'Feature'; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 0 | my $count | |||||||||
| 138 | = $schema->resultset($result_class) | ||||||||||
| 139 | ->search( { uniquename => $name } ) | ||||||||||
| 140 | ->search_related( 'featureloc_features', {} )->count; | ||||||||||
| 141 | 0 | $test_builder->ok( $count, $msg ); | |||||||||
| 142 | 0 | return $count; | |||||||||
| 143 | 1 | }; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | 1 | 1; | |||||||||
| 147 | |||||||||||
| 148 | __END__ | ||||||||||