File: cvterm.t

package info (click to toggle)
libdbix-dbstag-perl 0.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,420 kB
  • sloc: perl: 6,152; sql: 588; xml: 221; lisp: 59; makefile: 20
file content (91 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use lib 't';

BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    use Test;    
    use DBStagTest;
    plan tests => 9;
}
use DBIx::DBStag;
use DBI;
use Data::Stag;
use FileHandle;
use strict;

open(F, "t/data/chado-cvterm.sql") || die;
my $ddl = join('',<F>);
close(F);
drop();
my $dbh = connect_to_cleandb();
#DBI->trace(1);

$dbh->do($ddl);

my $chado  = Data::Stag->parse("t/data/test.chadoxml");
$dbh->storenode($_) foreach $chado->subnodes;
ok(1);
my $query =
q[
SELECT * 
FROM cvterm
 INNER JOIN dbxref ON (cvterm.dbxref_id = dbxref.dbxref_id)
 INNER JOIN db ON     (dbxref.db_id = db.db_id)
 INNER JOIN cv ON     (cvterm.cv_id = cv.cv_id)
WHERE
 cvterm.definition LIKE '%snoRNA%'
USE NESTING (set(cvterm(cv)(dbxref(db))))
];

my $termset =
  $dbh->selectall_stag($query);
print $termset->xml;
my @terms = $termset->get_cvterm;
ok(@terms,1);
my $term = shift @terms;
ok($term->sget_cv->sget_name eq 'biological_process');
ok($term->sget_dbxref->sget_db->sget_name eq 'GO');

# find parents of 'snoRNA'
$query =
q[
SELECT * 
FROM cvterm AS baseterm
 INNER JOIN cvterm_relationship AS r ON (r.subject_id=baseterm.cvterm_id)
 INNER JOIN cvterm AS parentterm      ON (r.object_id=parentterm.cvterm_id)
 INNER JOIN cvterm AS rtype          ON (r.type_id=rtype.cvterm_id)
WHERE
 baseterm.definition LIKE '%snoRNA%'
USE NESTING (set(baseterm(r(parentterm)(rtype))))
];

$termset =
  $dbh->selectall_stag(-sql=>$query,
                       -aliaspolicy=>'a');
my @parents = $termset->get('baseterm/r/parentterm');
ok(@parents == 1);

$termset =
  $dbh->selectall_stag(-sql=>$query,
                       -aliaspolicy=>'t');
@parents = $termset->get('cvterm/cvterm_relationship/cvterm');
#both child and parent are cvterm
ok(@parents == 2);

$termset =
  $dbh->selectall_stag(-sql=>$query);
@parents = $termset->get('baseterm/cvterm/r/cvterm_relationship/parentterm/cvterm');
ok(@parents == 1);

# this next test uses the new style of obo2chadoxml conversion
my $chado  = Data::Stag->parse("t/data/test2.chadoxml");
$dbh->storenode($_) foreach $chado->subnodes;
ok(1);

my ($genus) =
  $dbh->selectrow_array("SELECT cvterm.name FROM cvterm_genus INNER JOIN cvterm ON (genus_id=cvterm.cvterm_id)");
ok($genus eq 'a');

$dbh->disconnect;