| 1 | package Test::Chado::Role::Helper::WithBcs; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 1 | $Test::Chado::Role::Helper::WithBcs::VERSION = 'v4.1.1'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Other modules: | ||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::late; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use MooX::HandlesVia; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Bio::Chado::Schema; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Data::Perl qw/hash/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Bio::Chado::Schema; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Test::Chado::Types qw/BCS HashiFied DbManager DBIC/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Module::Load qw/load/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Module implementation | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | requires 'namespace'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | has 'dbmanager' => ( is => 'rw', isa => DbManager ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has 'dynamic_schema' => ( | ||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | isa => DBIC, | ||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||
| 30 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 1 | ▶ | if ( $self->dbmanager->can('is_dynamic_schema') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->dbmanager->can("is_dynamic_schema") and $self->dbmanager->is_dynamic_schema
MC/DC0%0/2
$self->dbmanager->can("is_dynamic_schema") and $self->dbmanager->is_dynamic_schema
$self->dbmanager->can("is_dynamic_schema")
$self->dbmanager->is_dynamic_schema
Truth table33%1/3
A and B
A= $self->dbmanager->can("is_dynamic_schema")B= $self->dbmanager->is_dynamic_schema
| |||||||||||||||||||||||||||||
| 32 | and $self->dbmanager->is_dynamic_schema ) | ||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 1 | load 'Test::Chado::Schema::Loader'; | |||||||||||||||||||||||||||
| 35 | return Test::Chado::Schema::Loader->connect( | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub { return $self->dbmanager->dbh } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||
| 40 | 0 | $schema->unregister_source('Sequence::Cvtermsynonym'); | |||||||||||||||||||||||||||
| 41 | 0 | return $schema; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 1 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | has 'schema' => ( | ||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||
| 48 | isa => BCS, | ||||||||||||||||||||||||||||
| 49 | lazy => 1, | ||||||||||||||||||||||||||||
| 50 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | return Bio::Chado::Schema->connect( | ||||||||||||||||||||||||||||
| 53 | 6 | ▶ | sub { return $self->dbmanager->dbh } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 1 | ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | has 'cvrow' => ( | |||||||||||||||||||||||||||
| 58 | is => 'rw', | ||||||||||||||||||||||||||||
| 59 | isa => HashiFied, | ||||||||||||||||||||||||||||
| 60 | handles_via => 'Data::Perl', | ||||||||||||||||||||||||||||
| 61 | builder => 1, | ||||||||||||||||||||||||||||
| 62 | clearer => 1, | ||||||||||||||||||||||||||||
| 63 | lazy => 1, | ||||||||||||||||||||||||||||
| 64 | handles => { | ||||||||||||||||||||||||||||
| 65 | get_cvrow => 'get', | ||||||||||||||||||||||||||||
| 66 | set_cvrow => 'set', | ||||||||||||||||||||||||||||
| 67 | exist_cvrow => 'defined' | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | has 'dbrow' => ( | |||||||||||||||||||||||||||
| 72 | is => 'rw', | ||||||||||||||||||||||||||||
| 73 | isa => HashiFied, | ||||||||||||||||||||||||||||
| 74 | handles_via => 'Data::Perl', | ||||||||||||||||||||||||||||
| 75 | lazy => 1, | ||||||||||||||||||||||||||||
| 76 | clearer => 1, | ||||||||||||||||||||||||||||
| 77 | builder => 1, | ||||||||||||||||||||||||||||
| 78 | handles => { | ||||||||||||||||||||||||||||
| 79 | get_dbrow => 'get', | ||||||||||||||||||||||||||||
| 80 | set_dbrow => 'set', | ||||||||||||||||||||||||||||
| 81 | exist_dbrow => 'defined' | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | has 'cvterm_row' => ( | ||||||||||||||||||||||||||||
| 86 | is => 'rw', | ||||||||||||||||||||||||||||
| 87 | isa => HashiFied, | ||||||||||||||||||||||||||||
| 88 | lazy => 1, | ||||||||||||||||||||||||||||
| 89 | 1 | ▶ | default => sub { return hash( () ); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 1 | handles_via => 'Data::Perl', | |||||||||||||||||||||||||||
| 91 | handles => { | ||||||||||||||||||||||||||||
| 92 | get_cvterm_row => 'get', | ||||||||||||||||||||||||||||
| 93 | set_cvterm_row => 'set', | ||||||||||||||||||||||||||||
| 94 | exist_cvterm_row => 'defined' | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | ▶ | sub _build_dbrow { | ||||||||||||||||||||||||||
|
Subroutine
_build_dbrow: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 99 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 100 | 4 | my %hash = (); | |||||||||||||||||||||||||||
| 101 | 4 | my $name = $self->namespace . '-db'; | |||||||||||||||||||||||||||
| 102 | 4 | my $row = $self->schema->resultset('General::Db') | |||||||||||||||||||||||||||
| 103 | ->find_or_create( { name => $name } ); | ||||||||||||||||||||||||||||
| 104 | 4 | $row->description('database namespace for test-chado fixture'); | |||||||||||||||||||||||||||
| 105 | 4 | $row->update; | |||||||||||||||||||||||||||
| 106 | 4 | $hash{default} = $row; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | ## -- cache entries from database | ||||||||||||||||||||||||||||
| 109 | 4 | my $rs = $self->schema->resultset('General::Db')->search( {} ); | |||||||||||||||||||||||||||
| 110 | 4 | ▶ | while ( my $dbrow = $rs->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | $hash{ $dbrow->name } = $dbrow | ||||||||||||||||||||||||||||
| 112 | 5 | ▶ | if not defined $hash{ $dbrow->name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 4 | return hash(%hash); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub default_db_id { | ||||||||||||||||||||||||||
|
Subroutine
default_db_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 2 | $_[0]->get_dbrow('default')->db_id; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 3 | ▶ | sub find_db_id { | ||||||||||||||||||||||||||
|
Subroutine
find_db_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 3 | my ( $self, $db ) = @_; | |||||||||||||||||||||||||||
| 124 | 3 | ▶ | return $self->get_dbrow($db)->db_id if $self->exist_dbrow($db); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 4 | ▶ | sub find_or_create_db_id { | ||||||||||||||||||||||||||
|
Subroutine
find_or_create_db_id: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 4 | my ( $self, $dbname ) = @_; | |||||||||||||||||||||||||||
| 129 | 4 | my $schema = $self->schema; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 4 | my $dbrow; | |||||||||||||||||||||||||||
| 132 | ## -- check cache | ||||||||||||||||||||||||||||
| 133 | 4 | ▶ | if ( $self->exist_dbrow($dbname) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 134 | 2 | $dbrow = $self->get_dbrow($dbname); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | ## -- check database | ||||||||||||||||||||||||||||
| 137 | elsif ( $dbrow | ||||||||||||||||||||||||||||
| 138 | = $schema->resultset('General::Db')->find( { name => $dbname } ) ) | ||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||
| 140 | 1 | $self->set_dbrow( $dbname, $dbrow ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | ## -- create | ||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||
| 144 | $dbrow = $schema->txn_do( | ||||||||||||||||||||||||||||
| 145 | 1 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | 1 | return $schema->resultset('General::Db')->create( | |||||||||||||||||||||||||||
| 147 | { name => $dbname, | ||||||||||||||||||||||||||||
| 148 | description => | ||||||||||||||||||||||||||||
| 149 | "db namespace for module-build-chado fixture" | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 1 | ); | |||||||||||||||||||||||||||
| 154 | 1 | $self->set_dbrow( $dbname, $dbrow ); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 4 | return $dbrow->db_id; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 3 | ▶ | sub _build_cvrow { | ||||||||||||||||||||||||||
|
Subroutine
_build_cvrow: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 160 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 161 | 3 | my %hash = (); | |||||||||||||||||||||||||||
| 162 | 3 | my $namespace = $self->namespace . '-cv'; | |||||||||||||||||||||||||||
| 163 | 3 | my $cvrow = $self->schema->resultset('Cv::Cv') | |||||||||||||||||||||||||||
| 164 | ->find_or_create( { name => $namespace } ); | ||||||||||||||||||||||||||||
| 165 | 3 | $cvrow->definition( | |||||||||||||||||||||||||||
| 166 | 'Ontology namespace for module-build-chado text fixture'); | ||||||||||||||||||||||||||||
| 167 | 3 | $cvrow->update; | |||||||||||||||||||||||||||
| 168 | 3 | $hash{default} = $cvrow; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | ## -- now create the cache if any | ||||||||||||||||||||||||||||
| 171 | 3 | my $cv_rs = $self->schema->resultset('Cv::Cv')->search( {} ); | |||||||||||||||||||||||||||
| 172 | 3 | ▶ | while ( my $row = $cv_rs->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 4 | ▶ | $hash{ $row->name } = $row if not defined $hash{ $row->name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 3 | return hash(%hash); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 2 | ▶ | sub default_cv_id { | ||||||||||||||||||||||||||
|
Subroutine
default_cv_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 179 | 2 | $_[0]->get_cvrow('default')->cv_id; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 1 | ▶ | sub find_cv_id { | ||||||||||||||||||||||||||
|
Subroutine
find_cv_id: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 1 | my ( $self, $cv ) = @_; | |||||||||||||||||||||||||||
| 184 | 1 | ▶ | $self->get_cvrow($cv)->cv_id if $self->exist_cvrow($cv); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 5 | ▶ | sub find_or_create_cv_id { | ||||||||||||||||||||||||||
|
Subroutine
find_or_create_cv_id: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 5 | my ( $self, $namespace ) = @_; | |||||||||||||||||||||||||||
| 189 | 5 | my $schema = $self->schema; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 5 | my $cvrow; | |||||||||||||||||||||||||||
| 192 | ## -- check in the cache | ||||||||||||||||||||||||||||
| 193 | 5 | ▶ | if ( $self->exist_cvrow($namespace) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 194 | 3 | $cvrow = $self->get_cvrow($namespace); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | ## -- check in the database | ||||||||||||||||||||||||||||
| 197 | elsif ( $cvrow | ||||||||||||||||||||||||||||
| 198 | = $schema->resultset('Cv::Cv')->find( { name => $namespace } ) ) | ||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 1 | $self->set_cvrow( $namespace, $cvrow ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | ## -- create | ||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||
| 204 | $cvrow = $schema->txn_do( | ||||||||||||||||||||||||||||
| 205 | 1 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 206 | 1 | return $schema->resultset('Cv::Cv')->create( | |||||||||||||||||||||||||||
| 207 | { name => $namespace, | ||||||||||||||||||||||||||||
| 208 | definition => | ||||||||||||||||||||||||||||
| 209 | "Ontology namespace for module-build-chado fixture" | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 1 | ); | |||||||||||||||||||||||||||
| 214 | 1 | $self->set_cvrow( $namespace, $cvrow ); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 5 | return $cvrow->cv_id; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 2 | ▶ | sub find_or_create_cvterm_id { | ||||||||||||||||||||||||||
|
Subroutine
find_or_create_cvterm_id: called CC=7 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | 2 | my ( $self, $cvterm, $cv, $db, $dbxref ) = @_; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 2 | ▶ | if ( $self->exist_cvterm_row($cvterm) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | my $row = $self->get_cvterm_row($cvterm); | |||||||||||||||||||||||||||
| 224 | 0 | ▶ | return $row->cvterm_id if $row->cv->name eq $cv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | #otherwise try to retrieve from database | ||||||||||||||||||||||||||||
| 228 | 2 | ▶ | my $cv_id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | = $cv | ||||||||||||||||||||||||||||
| 230 | ? $self->find_or_create_cv_id($cv) | ||||||||||||||||||||||||||||
| 231 | : $self->get_cvrow('default')->cv_id; | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 2 | my $rs = $self->schema->resultset('Cv::Cvterm') | |||||||||||||||||||||||||||
| 234 | ->search( { 'name' => $cvterm, 'cv_id' => $cv_id }, ); | ||||||||||||||||||||||||||||
| 235 | 2 | ▶ | if ( $rs->count > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 1 | $self->set_cvterm_row( $cvterm, $rs->first ); | |||||||||||||||||||||||||||
| 237 | 1 | return $rs->first->cvterm_id; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 1 | ▶ | my $db_id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | = $db | ||||||||||||||||||||||||||||
| 242 | ? $self->find_or_create_db_id($db) | ||||||||||||||||||||||||||||
| 243 | : $self->get_dbrow('default')->db_id; | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | #otherwise create one cvterm | ||||||||||||||||||||||||||||
| 246 | 1 | ▶ | $dbxref ||= $cvterm; | ||||||||||||||||||||||||||
|
Condition33%1/3
$dbxref ||= $cvterm
MC/DC0%0/2
$dbxref ||= $cvterm
$dbxref
$cvterm
Truth table33%1/3
A ||= B
A= $dbxrefB= $cvterm
| |||||||||||||||||||||||||||||
| 247 | 1 | my $row = $self->schema->resultset('Cv::Cvterm')->create( | |||||||||||||||||||||||||||
| 248 | { name => $cvterm, | ||||||||||||||||||||||||||||
| 249 | cv_id => $cv_id, | ||||||||||||||||||||||||||||
| 250 | dbxref => { | ||||||||||||||||||||||||||||
| 251 | accession => $dbxref, | ||||||||||||||||||||||||||||
| 252 | db_id => $db_id | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | ); | ||||||||||||||||||||||||||||
| 256 | 1 | $self->set_cvterm_row( $cvterm, $row ); | |||||||||||||||||||||||||||
| 257 | 1 | return $row->cvterm_id; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 4 | ▶ | sub find_cvterm_id { | ||||||||||||||||||||||||||
|
Subroutine
find_cvterm_id: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 261 | 4 | my ( $self, $cvterm, $cv ) = @_; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 4 | ▶ | if ( $self->exist_cvterm_row($cvterm) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 3 | my $row = $self->get_cvterm_row($cvterm); | |||||||||||||||||||||||||||
| 265 | 3 | ▶ | if ($cv) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 2 | ▶ | return $row->cvterm_id if $row->cv->name eq $cv; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||
| 269 | 1 | return $row->cvterm_id; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | #otherwise try to retrieve from database | ||||||||||||||||||||||||||||
| 274 | 1 | ▶ | my $rs | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | = $cv | ||||||||||||||||||||||||||||
| 276 | ? $self->schema->resultset('Cv::Cvterm') | ||||||||||||||||||||||||||||
| 277 | ->search( { 'me.name' => $cvterm, 'cv.name' => $cv }, | ||||||||||||||||||||||||||||
| 278 | { join => 'cv', cache => 1 } ) | ||||||||||||||||||||||||||||
| 279 | : $self->schema->resultset('Cv::Cvterm') | ||||||||||||||||||||||||||||
| 280 | ->search( { 'name' => $cvterm, cache => 1 } ); | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if ( $rs->count > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 1 | $self->set_cvterm_row( $cvterm => $rs->first ); | |||||||||||||||||||||||||||
| 284 | 1 | return $rs->first->cvterm_id; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 2 | ▶ | sub search_cvterm_ids_by_namespace { | ||||||||||||||||||||||||||
|
Subroutine
search_cvterm_ids_by_namespace: called CC=3 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||
| 289 | 2 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 2 | ▶ | if ( $self->exist_cvrow($name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 2 | my $ids = [ map { $_->cvterm_id } $self->get_cvrow($name)->cvterms ]; | |||||||||||||||||||||||||||
| 293 | 2 | return $ids; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 0 | my $rs = $self->schema->resultset('Cv::Cv')->search( { name => $name } ); | |||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( $rs->count > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | my $row = $rs->first; | |||||||||||||||||||||||||||
| 299 | 0 | $self->set_cvrow( $name, $row ); | |||||||||||||||||||||||||||
| 300 | 0 | my $ids = [ map { $_->cvterm_id } $row->cvterms ]; | |||||||||||||||||||||||||||
| 301 | 0 | return $ids; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 0 | croak "the given cv namespace $name does not exist : create one\n"; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 1 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | __END__ | ||||||||||||||||||||||||||||