| 1 | package PomBase::Chobo::Role::ChadoStore; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | PomBase::Chobo::Role::ChadoStore - Code for storing terms in Chado | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 AUTHOR | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | Kim Rutherford C<< <kmr44@cam.ac.uk> >> | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 BUGS | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Please report any bugs or feature requests to C<kmr44@cam.ac.uk>. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 SUPPORT | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | perldoc PomBase::Chobo::Role::ChadoStore | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =over 4 | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =back | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | Copyright 2012 Kim Rutherford, all rights reserved. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 32 | under the same terms as Perl itself. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 FUNCTIONS | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | our $VERSION = '0.041'; # VERSION | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | use Mouse::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | 1 | ▶ | use Text::CSV::Encoded; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | requires 'dbh'; | |||||||||||||||||||
| 45 | 1 | requires 'ontology_data'; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | ▶ | use PomBase::Chobo::ChadoData; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 1 | ▶ | use PomBase::Chobo::OntologyConf; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | our @relationship_cv_names; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | @relationship_cv_names = @PomBase::Chobo::OntologyConf::relationship_cv_names; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub _copy_to_table | ||||||||||||||||||||
| 57 | 18 | ▶ | { | ||||||||||||||||||
|
Subroutine
_copy_to_table: called CC=5 SCAR=16.7
| |||||||||||||||||||||
| 58 | 18 | my $self = shift; | |||||||||||||||||||
| 59 | 18 | my $table_name = shift; | |||||||||||||||||||
| 60 | 18 | my $column_names_ref = shift; | |||||||||||||||||||
| 61 | 18 | my @column_names = @$column_names_ref; | |||||||||||||||||||
| 62 | 18 | my $data_ref = shift; | |||||||||||||||||||
| 63 | 18 | my @data = @$data_ref; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 18 | my $dbh = $self->dbh(); | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 18 | my $column_names = join ',', @column_names; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 18 | ▶ | $dbh->do("COPY $table_name($column_names) FROM STDIN CSV") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | or die "failed to COPY into $table_name: ", $dbh->errstr, "\n"; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 18 | my $csv = Text::CSV::Encoded->new({ encoding => "utf8" }); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 18 | for my $row (@data) { | |||||||||||||||||||
| 75 | 67 | $csv->combine(@$row); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 67 | ▶ | if (!$dbh->pg_putcopydata($csv->string() . "\n")) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 0 | die $dbh->errstr(); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 18 | ▶ | if (!$dbh->pg_putcopyend()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | die $dbh->errstr(); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | sub _get_relationship_terms | ||||||||||||||||||||
| 88 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
_get_relationship_terms: called CC=5 SCAR=16.6
| |||||||||||||||||||||
| 89 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 2 | my @cvterm_data = $chado_data->get_all_cvterms(); | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | my @rel_terms = | ||||||||||||||||||||
| 94 | sort { | ||||||||||||||||||||
| 95 | 2 | ▶ | if ($a->{id} =~ /:/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 1 | ▶ | if ($b->{id} =~ /:/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 1 | $a->{id} cmp $b->{id}; | |||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||
| 99 | 0 | -1; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||
| 102 | 1 | ▶ | if ($b->{id} =~ /:/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 1 | 1; | |||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||
| 105 | 0 | $a->{id} cmp $b->{id}; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | grep { | ||||||||||||||||||||
| 110 | 2 | $_->is_relationshiptype(); | |||||||||||||||||||
| 111 | } @cvterm_data; | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 2 | my %terms_by_name = (); | |||||||||||||||||||
| 114 | 2 | my %terms_by_termid = (); | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | map { | ||||||||||||||||||||
| 117 | 2 | ▶ | if (exists $terms_by_name{$_->name()}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | warn 'two relationship terms with the same name ("' . | ||||||||||||||||||||
| 119 | $_->id() . '" and "' . $terms_by_name{$_->name()}->id() . '") - ' . | ||||||||||||||||||||
| 120 | 0 | 'using: ' . $terms_by_name{$_->name()}->id(), "\n"; | |||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||
| 122 | 4 | $terms_by_name{$_->name()} = $_; | |||||||||||||||||||
| 123 | 4 | $terms_by_name{$_->name() =~ s/\s+/_/gr} = $_; | |||||||||||||||||||
| 124 | 4 | $terms_by_termid{$_->id()} = $_; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | } @rel_terms; | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 2 | return (\%terms_by_name, \%terms_by_termid); | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | my %row_makers = ( | ||||||||||||||||||||
| 133 | 2 | ▶ | db => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 134 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 135 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 2 | my %chado_db_names = (); | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | map { | ||||||||||||||||||||
| 140 | 2 | $chado_db_names{$_} = 1; | |||||||||||||||||||
| 141 | } $chado_data->get_db_names(); | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | return map { | ||||||||||||||||||||
| 144 | 12 | [$_]; | |||||||||||||||||||
| 145 | } grep { | ||||||||||||||||||||
| 146 | 2 | !$chado_db_names{$_}; | |||||||||||||||||||
| 147 | } $ontology_data->get_db_names(); | ||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||
| 149 | 2 | ▶ | dbxref => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 150 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 151 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | map { | ||||||||||||||||||||
| 154 | 2 | my $db_name = $_; | |||||||||||||||||||
| 155 | 12 | my $db_id = $chado_data->get_db_by_name($db_name)->{db_id}; | |||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 12 | my %chado_termids = (); | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | map { | ||||||||||||||||||||
| 160 | 12 | $chado_termids{$_} = 1; | |||||||||||||||||||
| 161 | } $chado_data->get_all_termids(); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | my @ont_db_termids = grep { | ||||||||||||||||||||
| 164 | 12 | !$chado_termids{"$db_name:$_"}; | |||||||||||||||||||
| 165 | } $ontology_data->accessions_by_db_name($db_name); | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | map { | ||||||||||||||||||||
| 168 | 12 | my $accession = $_; | |||||||||||||||||||
| 169 | 19 | ▶ | if (!defined $accession) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 170 | 0 | die "accession is null for accession in db: $db_name\n"; | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | 19 | [$db_id, $accession]; | |||||||||||||||||||
| 173 | } @ont_db_termids; | ||||||||||||||||||||
| 174 | } $ontology_data->get_db_names(); | ||||||||||||||||||||
| 175 | }, | ||||||||||||||||||||
| 176 | 2 | ▶ | cv => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 177 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 178 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 2 | my %chado_cv_names = (); | |||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | map { | ||||||||||||||||||||
| 183 | 2 | $chado_cv_names{$_} = 1; | |||||||||||||||||||
| 184 | } $chado_data->get_cv_names(); | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | return map { | ||||||||||||||||||||
| 187 | 3 | [$_]; | |||||||||||||||||||
| 188 | } grep { | ||||||||||||||||||||
| 189 | 2 | !$chado_cv_names{$_}; | |||||||||||||||||||
| 190 | } $ontology_data->get_cv_names(); | ||||||||||||||||||||
| 191 | }, | ||||||||||||||||||||
| 192 | 2 | ▶ | cvterm => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||
| 193 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 194 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | map { | ||||||||||||||||||||
| 197 | 2 | my $term = $_; | |||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 7 | my $cv = $chado_data->get_cv_by_name($term->{namespace}); | |||||||||||||||||||
| 200 | 7 | my $cv_id = $cv->{cv_id}; | |||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 7 | my $dbxref = $chado_data->get_dbxref_by_termid($term->id()); | |||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 7 | ▶ | if (!$dbxref) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 205 | 0 | die "dbxref not found for:\n", $term->to_string(), "\n"; | |||||||||||||||||||
| 206 | } | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | 7 | my $name = $term->name(); | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 7 | ▶ | if ($term->is_obsolete()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 211 | 1 | $name .= ' (obsolete ' . $term->id() . ')'; | |||||||||||||||||||
| 212 | } | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 7 | my $definition = undef; | |||||||||||||||||||
| 215 | 7 | ▶ | if (defined $term->def()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 216 | 7 | $definition = $term->def()->{definition}; | |||||||||||||||||||
| 217 | } | ||||||||||||||||||||
| 218 | 7 | my $dbxref_id = $dbxref->{dbxref_id}; | |||||||||||||||||||
| 219 | 7 | my $is_relationshiptype = $term->{is_relationshiptype}; | |||||||||||||||||||
| 220 | 7 | ▶ | my $is_obsolete = $term->{is_obsolete} ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | 7 | [$name, $definition, $cv_id, $dbxref_id, $is_relationshiptype, $is_obsolete]; | |||||||||||||||||||
| 223 | } $ontology_data->get_terms(); | ||||||||||||||||||||
| 224 | }, | ||||||||||||||||||||
| 225 | 2 | ▶ | cvtermprop => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||
| 226 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 227 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 2 | my $prop_type_cv = | |||||||||||||||||||
| 230 | $chado_data->get_cv_by_name('cvterm_property_type'); | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | 2 | ▶ | if (!defined $prop_type_cv) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 233 | 0 | die qq|no "cvterm_property_type" CV in database\n|; | |||||||||||||||||||
| 234 | } | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | my %prop_types = | ||||||||||||||||||||
| 237 | 2 | %{$chado_data->get_cvterms_by_cv_id($prop_type_cv->{cv_id})}; | |||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | map { | ||||||||||||||||||||
| 240 | 2 | my $term = $_; | |||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | 7 | my $replaced_by = $term->replaced_by(); | |||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | 7 | my @res = (); | |||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | 7 | ▶ | if (defined $replaced_by) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 247 | 1 | my $cvterm_id = | |||||||||||||||||||
| 248 | $chado_data->get_cvterm_by_termid($term->id())->cvterm_id(); | ||||||||||||||||||||
| 249 | 1 | push @res, [$cvterm_id, $prop_types{replaced_by}->cvterm_id(), $replaced_by]; | |||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | 7 | my $consider = $term->consider(); | |||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | 7 | ▶ | if (defined $consider) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 255 | 1 | my $cvterm_id = | |||||||||||||||||||
| 256 | $chado_data->get_cvterm_by_termid($term->id())->cvterm_id(); | ||||||||||||||||||||
| 257 | 1 | push @res, [$cvterm_id, $prop_types{consider}->cvterm_id(), $consider]; | |||||||||||||||||||
| 258 | } | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | 7 | my @property_values = $term->property_values(); | |||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | 7 | for my $prop_value (@property_values) { | |||||||||||||||||||
| 263 | 1 | my $cvterm_id = | |||||||||||||||||||
| 264 | $chado_data->get_cvterm_by_termid($term->id())->cvterm_id(); | ||||||||||||||||||||
| 265 | 1 | my $prop_value_name = $prop_value->[0]; | |||||||||||||||||||
| 266 | 1 | my $prop_value_value = $prop_value->[1]; | |||||||||||||||||||
| 267 | 1 | ▶ | if (defined $prop_types{$prop_value_name}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 268 | 1 | push @res, [$cvterm_id, $prop_types{$prop_value_name}->cvterm_id(), $prop_value_value]; | |||||||||||||||||||
| 269 | } | ||||||||||||||||||||
| 270 | } | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | 7 | @res; | |||||||||||||||||||
| 273 | } $ontology_data->get_terms(); | ||||||||||||||||||||
| 274 | }, | ||||||||||||||||||||
| 275 | 2 | ▶ | cvtermsynonym => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||
| 276 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 277 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 278 | |||||||||||||||||||||
| 279 | 2 | my $synonym_type_cv = | |||||||||||||||||||
| 280 | $chado_data->get_cv_by_name('synonym_type'); | ||||||||||||||||||||
| 281 | my %synonym_types = | ||||||||||||||||||||
| 282 | 2 | %{$chado_data->get_cvterms_by_cv_id($synonym_type_cv->{cv_id})}; | |||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | map { | ||||||||||||||||||||
| 285 | 2 | my $term = $_; | |||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | map { | ||||||||||||||||||||
| 288 | 7 | my $synonym_type_name = $_->{scope}; | |||||||||||||||||||
| 289 | my $synonym_type_term = | ||||||||||||||||||||
| 290 | $synonym_types{lc $synonym_type_name} // | ||||||||||||||||||||
| 291 | 6 | ▶ | $synonym_types{uc $synonym_type_name}; | ||||||||||||||||||
|
Condition33%1/3
$synonym_types{lc $synonym_type_name} // $synonym_types{uc $synonym_type_name}
MC/DC0%0/2
$synonym_types{lc $synonym_type_name} // $synonym_types{uc $synonym_type_name}
$synonym_types{lc $synonym_type_name}
$synonym_types{uc $synonym_type_name}
Truth table33%1/3
A // B
A= $synonym_types{lc $synonym_type_name}B= $synonym_types{uc $synonym_type_name}
| |||||||||||||||||||||
| 292 | |||||||||||||||||||||
| 293 | 6 | ▶ | if (!defined $synonym_type_term) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 294 | 0 | die "unknown synonym scope: $synonym_type_name"; | |||||||||||||||||||
| 295 | } | ||||||||||||||||||||
| 296 | |||||||||||||||||||||
| 297 | 6 | my $cvterm_id = $chado_data->get_cvterm_by_termid($term->id())->cvterm_id(); | |||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | 6 | [$cvterm_id, $_->{synonym}, $synonym_type_term->{cvterm_id}]; | |||||||||||||||||||
| 300 | } $term->synonyms(); | ||||||||||||||||||||
| 301 | } $ontology_data->get_terms(); | ||||||||||||||||||||
| 302 | }, | ||||||||||||||||||||
| 303 | 2 | ▶ | cvterm_dbxref => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 304 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 305 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | 2 | my %seen_cvterm_dbxrefs = (); | |||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | map { | ||||||||||||||||||||
| 310 | 2 | my $term = $_; | |||||||||||||||||||
| 311 | |||||||||||||||||||||
| 312 | 12 | ▶ | my $helper = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||
| 313 | 12 | my $id = shift; | |||||||||||||||||||
| 314 | |||||||||||||||||||||
| 315 | 12 | my $is_for_definition = shift; | |||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | 12 | my $cvterm_id = $chado_data->get_cvterm_by_termid($term->id())->cvterm_id(); | |||||||||||||||||||
| 318 | 12 | my $dbxref_details = $chado_data->get_dbxref_by_termid($id); | |||||||||||||||||||
| 319 | |||||||||||||||||||||
| 320 | 12 | ▶ | if (!defined $dbxref_details) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 321 | 0 | die "no dbxref details for $id ", $term->name(), "\n"; | |||||||||||||||||||
| 322 | } | ||||||||||||||||||||
| 323 | |||||||||||||||||||||
| 324 | 12 | my $dbxref_id = $dbxref_details->{dbxref_id}; | |||||||||||||||||||
| 325 | |||||||||||||||||||||
| 326 | 12 | my $key = "$cvterm_id - $dbxref_id"; | |||||||||||||||||||
| 327 | 12 | ▶ | if (exists $seen_cvterm_dbxrefs{$key}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 328 | () | ||||||||||||||||||||
| 329 | 0 | } else { | |||||||||||||||||||
| 330 | 12 | $seen_cvterm_dbxrefs{$key} = 1; | |||||||||||||||||||
| 331 | 12 | [$cvterm_id, $dbxref_id, $is_for_definition] | |||||||||||||||||||
| 332 | } | ||||||||||||||||||||
| 333 | 7 | }; | |||||||||||||||||||
| 334 | |||||||||||||||||||||
| 335 | 7 | my @ret = (); | |||||||||||||||||||
| 336 | |||||||||||||||||||||
| 337 | 7 | ▶ | if ($term->def()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 338 | 7 | push @ret, map { $helper->($_, 1) } @{$term->def()->{dbxrefs}} | |||||||||||||||||||
| 339 | } | ||||||||||||||||||||
| 340 | |||||||||||||||||||||
| 341 | 7 | push @ret, map { $helper->($_->{id}, 0) } $term->alt_ids(); | |||||||||||||||||||
| 342 | 7 | push @ret, map { $helper->($_, 0) } $term->xrefs(); | |||||||||||||||||||
| 343 | |||||||||||||||||||||
| 344 | 7 | @ret; | |||||||||||||||||||
| 345 | } $ontology_data->get_terms(); | ||||||||||||||||||||
| 346 | }, | ||||||||||||||||||||
| 347 | 2 | ▶ | cvterm_relationship => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.0
| |||||||||||||||||||||
| 348 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 349 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 350 | |||||||||||||||||||||
| 351 | 2 | my ($terms_by_name, $terms_by_termid) = _get_relationship_terms($chado_data); | |||||||||||||||||||
| 352 | |||||||||||||||||||||
| 353 | map { | ||||||||||||||||||||
| 354 | 2 | my ($subject_termid, $rel_name_or_id, $object_termid) = @$_; | |||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | 2 | my $subject_term = $chado_data->get_cvterm_by_termid($subject_termid); | |||||||||||||||||||
| 357 | 2 | ▶ | if (defined $subject_term) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 358 | 2 | my $subject_id = $subject_term->{cvterm_id}; | |||||||||||||||||||
| 359 | my $rel_term = $terms_by_name->{$rel_name_or_id} || | ||||||||||||||||||||
| 360 | 2 | ▶ | $terms_by_termid->{$rel_name_or_id}; | ||||||||||||||||||
|
Condition33%1/3
$terms_by_name->{$rel_name_or_id} || $terms_by_termid->{$rel_name_or_id}
MC/DC0%0/2
$terms_by_name->{$rel_name_or_id} || $terms_by_termid->{$rel_name_or_id}
$terms_by_name->{$rel_name_or_id}
$terms_by_termid->{$rel_name_or_id}
Truth table33%1/3
A || B
A= $terms_by_name->{$rel_name_or_id}B= $terms_by_termid->{$rel_name_or_id}
| |||||||||||||||||||||
| 361 | 2 | ▶ | if (!defined $rel_term) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 362 | 0 | die "can't find relation term $rel_name_or_id for relation:\n" . | |||||||||||||||||||
| 363 | " $subject_termid <-$rel_name_or_id-> $object_termid\n"; | ||||||||||||||||||||
| 364 | } | ||||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | 2 | my $rel_id = $rel_term->cvterm_id(); | |||||||||||||||||||
| 367 | |||||||||||||||||||||
| 368 | 2 | my $object_term = $chado_data->get_cvterm_by_termid($object_termid); | |||||||||||||||||||
| 369 | 2 | ▶ | if (defined $object_term) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 370 | 2 | my $object_id = $object_term->{cvterm_id}; | |||||||||||||||||||
| 371 | |||||||||||||||||||||
| 372 | 2 | [$subject_id, $rel_id, $object_id] | |||||||||||||||||||
| 373 | } else { | ||||||||||||||||||||
| 374 | 0 | warn "no Chado cvterm for $object_termid - ignoring relation:\n" . | |||||||||||||||||||
| 375 | " $subject_termid <-$rel_name_or_id-> $object_termid\n"; | ||||||||||||||||||||
| 376 | 0 | (); | |||||||||||||||||||
| 377 | } | ||||||||||||||||||||
| 378 | } else { | ||||||||||||||||||||
| 379 | 0 | warn "no Chado cvterm for $subject_termid - ignoring relation:\n" . | |||||||||||||||||||
| 380 | " $subject_termid <-$rel_name_or_id-> $object_termid\n"; | ||||||||||||||||||||
| 381 | 0 | (); | |||||||||||||||||||
| 382 | } | ||||||||||||||||||||
| 383 | } $ontology_data->relationships(); | ||||||||||||||||||||
| 384 | }, | ||||||||||||||||||||
| 385 | 2 | ▶ | cvprop => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||
| 386 | 2 | my $ontology_data = shift; | |||||||||||||||||||
| 387 | 2 | my $chado_data = shift; | |||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | 2 | my @namespaces = $ontology_data->get_namespaces(); | |||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | 2 | my $cv_version_term = $chado_data->get_cvterm_by_name('cv_property_type', 'cv_version'); | |||||||||||||||||||
| 392 | |||||||||||||||||||||
| 393 | map { | ||||||||||||||||||||
| 394 | 2 | my $namespace = $_; | |||||||||||||||||||
| 395 | |||||||||||||||||||||
| 396 | 3 | my $metadata = $ontology_data->get_metadata_by_namespace($namespace); | |||||||||||||||||||
| 397 | 3 | ▶ | my $cv_version = $metadata->{'data-version'} || $metadata->{'date'};; | ||||||||||||||||||
|
Condition33%1/3
$metadata->{'data-version'} || $metadata->{'date'}
MC/DC0%0/2
$metadata->{'data-version'} || $metadata->{'date'}
$metadata->{'data-version'}
$metadata->{'date'}
Truth table33%1/3
A || B
A= $metadata->{'data-version'}B= $metadata->{'date'}
| |||||||||||||||||||||
| 398 | |||||||||||||||||||||
| 399 | 3 | ▶ | if ($cv_version) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 400 | 3 | my $cv = $chado_data->get_cv_by_name($namespace); | |||||||||||||||||||
| 401 | 3 | my $cv_id = $cv->{cv_id}; | |||||||||||||||||||
| 402 | |||||||||||||||||||||
| 403 | 3 | [$cv_id, $cv_version_term->{cvterm_id}, $cv_version]; | |||||||||||||||||||
| 404 | } else { | ||||||||||||||||||||
| 405 | 0 | (); | |||||||||||||||||||
| 406 | } | ||||||||||||||||||||
| 407 | } @namespaces | ||||||||||||||||||||
| 408 | }, | ||||||||||||||||||||
| 409 | |||||||||||||||||||||
| 410 | 1 | ); | |||||||||||||||||||
| 411 | |||||||||||||||||||||
| 412 | 1 | my %table_column_names = ( | |||||||||||||||||||
| 413 | db => [qw(name)], | ||||||||||||||||||||
| 414 | dbxref => [qw(db_id accession)], | ||||||||||||||||||||
| 415 | cv => [qw(name)], | ||||||||||||||||||||
| 416 | cvterm => [qw(name definition cv_id dbxref_id is_relationshiptype is_obsolete)], | ||||||||||||||||||||
| 417 | cvtermprop => [qw(cvterm_id type_id value)], | ||||||||||||||||||||
| 418 | cvtermsynonym => [qw(cvterm_id synonym type_id)], | ||||||||||||||||||||
| 419 | cvterm_dbxref => [qw(cvterm_id dbxref_id is_for_definition)], | ||||||||||||||||||||
| 420 | cvterm_relationship => [qw(subject_id type_id object_id)], | ||||||||||||||||||||
| 421 | cvprop => [qw(cv_id type_id value)], | ||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||
| 423 | |||||||||||||||||||||
| 424 | sub chado_store | ||||||||||||||||||||
| 425 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
chado_store: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 426 | 2 | my $self = shift; | |||||||||||||||||||
| 427 | |||||||||||||||||||||
| 428 | 2 | $self->ontology_data()->finish(); | |||||||||||||||||||
| 429 | |||||||||||||||||||||
| 430 | 2 | my @cvterm_column_names = | |||||||||||||||||||
| 431 | @PomBase::Chobo::ChadoData::cvterm_column_names; | ||||||||||||||||||||
| 432 | |||||||||||||||||||||
| 433 | 2 | my @tables_to_store = qw(db dbxref cv cvterm cvtermprop cvtermsynonym cvterm_dbxref cvterm_relationship cvprop); | |||||||||||||||||||
| 434 | |||||||||||||||||||||
| 435 | 2 | for my $table_to_store (@tables_to_store) { | |||||||||||||||||||
| 436 | 18 | my $chado_data = PomBase::Chobo::ChadoData->new(dbh => $self->dbh()); | |||||||||||||||||||
| 437 | |||||||||||||||||||||
| 438 | 18 | my @rows = $row_makers{$table_to_store}->($self->ontology_data(), | |||||||||||||||||||
| 439 | $chado_data); | ||||||||||||||||||||
| 440 | |||||||||||||||||||||
| 441 | 18 | $self->_copy_to_table($table_to_store, $table_column_names{$table_to_store}, | |||||||||||||||||||
| 442 | \@rows); | ||||||||||||||||||||
| 443 | } | ||||||||||||||||||||
| 444 | |||||||||||||||||||||
| 445 | } | ||||||||||||||||||||
| 446 | |||||||||||||||||||||
| 447 | 1 | 1; | |||||||||||||||||||