line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::ConnectDots::DB::ConnectorSet; |
2
|
2
|
|
|
2
|
|
13
|
use vars qw(@ISA @AUTO_ATTRIBUTES @OTHER_ATTRIBUTES %SYNONYMS); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
150
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
6038
|
use DBI; |
|
2
|
|
|
|
|
102068
|
|
|
2
|
|
|
|
|
221
|
|
5
|
2
|
|
|
2
|
|
4358
|
use Bio::ConnectDots::DB::DotSet; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
274
|
|
6
|
2
|
|
|
2
|
|
21
|
use Bio::ConnectDots::DotSet; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
7
|
2
|
|
|
2
|
|
13
|
use Bio::ConnectDots::ConnectorSet; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3304
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Class::AutoClass::Root); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# store one ConnectorSet, including connected DotSets. |
11
|
|
|
|
|
|
|
# store db_id in object |
12
|
|
|
|
|
|
|
sub put { |
13
|
0
|
|
|
0
|
0
|
|
my ( $class, $connectorset, @newlabels ) = @_; |
14
|
0
|
|
|
|
|
|
my $db = $connectorset->db; |
15
|
0
|
0
|
|
|
|
|
$class->throw("Cannot put data: database is not connected") |
16
|
|
|
|
|
|
|
unless $db->is_connected; |
17
|
0
|
0
|
|
|
|
|
$class->throw("Cannot put data: database does not exist") unless $db->exists; |
18
|
0
|
|
|
|
|
|
my $dbh = $db->dbh; |
19
|
0
|
|
|
|
|
|
my $connectorset_id = $connectorset->db_id; |
20
|
0
|
0
|
|
|
|
|
unless ($connectorset_id) { # insert ConnectorSet if not already in database |
21
|
0
|
|
|
|
|
|
my $name = $connectorset->name; |
22
|
0
|
|
|
|
|
|
my $file_name = $connectorset->file; |
23
|
0
|
|
|
|
|
|
my $version = $connectorset->cs_version; |
24
|
0
|
|
|
|
|
|
my $ftp = $connectorset->ftp; |
25
|
0
|
|
|
|
|
|
my $ftp_files = $connectorset->ftp_files; |
26
|
0
|
|
|
|
|
|
my $source_version = $connectorset->source_version; |
27
|
0
|
|
|
|
|
|
my $source_date = $connectorset->source_date; |
28
|
0
|
|
|
|
|
|
my $download_date = $connectorset->download_date; |
29
|
0
|
|
|
|
|
|
my $comment = $connectorset->comment; |
30
|
0
|
|
|
|
|
|
$connectorset_id = 1 + |
31
|
|
|
|
|
|
|
$dbh->selectrow_array(qq(SELECT MAX(connectorset_id) FROM connectorset)); |
32
|
0
|
|
|
|
|
|
my $sql = |
33
|
|
|
|
|
|
|
qq(INSERT INTO connectorset (connectorset_id,name,file_name,version, |
34
|
|
|
|
|
|
|
ftp,ftp_files,source_date,source_version, |
35
|
|
|
|
|
|
|
download_date,comment) |
36
|
|
|
|
|
|
|
VALUES ('$connectorset_id','$name','$file_name','$version','$ftp','$ftp_files','$source_date', |
37
|
|
|
|
|
|
|
'$source_version','$download_date','$comment')); |
38
|
0
|
|
|
|
|
|
$db->do_sql($sql); |
39
|
0
|
|
|
|
|
|
$connectorset->db_id($connectorset_id); |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
my $label2dotset = $connectorset->label2dotset; |
42
|
0
|
|
|
|
|
|
my $label2labelid = $connectorset->label2labelid; |
43
|
0
|
|
|
|
|
|
my $label_annotations = $connectorset->label_annotations; |
44
|
0
|
|
|
|
|
|
for my $label (@newlabels) |
45
|
|
|
|
|
|
|
{ # insert any new DotSets and update new connections |
46
|
0
|
|
|
|
|
|
my $dotset = $label2dotset->{$label}; |
47
|
0
|
|
|
|
|
|
my $dotset_id = $dotset->db_id; |
48
|
0
|
0
|
|
|
|
|
unless ($dotset_id) { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# see if DotSet already exists from another ConnectorSet |
51
|
0
|
|
|
|
|
|
my $name = $dotset->name; |
52
|
0
|
|
|
|
|
|
my $sql = qq(SELECT dotset_id FROM dotset WHERE name='$name'); |
53
|
0
|
|
|
|
|
|
($dotset_id) = $dbh->selectrow_array($sql); |
54
|
0
|
0
|
|
|
|
|
if ($dotset_id) { |
55
|
0
|
|
|
|
|
|
$dotset->db_id($dotset_id); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
|
Bio::ConnectDots::DB::DotSet->put($dotset); |
59
|
0
|
|
|
|
|
|
$dotset_id = $dotset->db_id; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
my $label_id = $dbh->selectrow_array(qq(SELECT label_id FROM label WHERE label='$label')); |
63
|
0
|
0
|
|
|
|
|
unless ($label_id) { |
64
|
0
|
|
|
|
|
|
my $source_label = $label_annotations->{$label}->{source_label}; |
65
|
0
|
|
|
|
|
|
my $description = $label_annotations->{$label}->{description}; |
66
|
0
|
|
|
|
|
|
my $sql = qq(INSERT INTO label (label,source_label,description) VALUES ('$label','$source_label','$description')); |
67
|
0
|
|
|
|
|
|
$db->do_sql($sql); |
68
|
0
|
|
|
|
|
|
$label_id = $dbh->selectrow_array(qq(SELECT MAX(label_id) FROM label)); |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$label2labelid->{$label} = $label_id; |
71
|
0
|
|
|
|
|
|
my $sql = qq(INSERT INTO connectdotset (connectorset_id,dotset_id,label_id) |
72
|
|
|
|
|
|
|
VALUES ($connectorset_id,$dotset_id,$label_id)); |
73
|
0
|
|
|
|
|
|
$db->do_sql($sql); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
return $connectorset; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# fetch one ConnectorSet, including connected DotSets. return object. |
79
|
|
|
|
|
|
|
sub get { |
80
|
0
|
|
|
0
|
0
|
|
my ( $class, $connectorset ) = @_; |
81
|
0
|
0
|
|
|
|
|
return $connectorset if $connectorset->db_id; # already fetched |
82
|
0
|
|
|
|
|
|
my $db = $connectorset->db; |
83
|
0
|
0
|
|
|
|
|
$class->throw("Cannot get data: database is not connected") |
84
|
|
|
|
|
|
|
unless $db->is_connected; |
85
|
0
|
0
|
|
|
|
|
$class->throw("Cannot get data: database does not exist") unless $db->exists; |
86
|
0
|
|
|
|
|
|
my $name = $connectorset->name; |
87
|
0
|
|
|
|
|
|
my $dbh = $db->dbh; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# determine version |
90
|
0
|
|
|
|
|
|
my $cs_version = $connectorset->cs_version; |
91
|
0
|
0
|
|
|
|
|
unless ($cs_version) { # grab newest version of connectorset |
92
|
0
|
|
|
|
|
|
my $iterator = |
93
|
|
|
|
|
|
|
$dbh->prepare( |
94
|
|
|
|
|
|
|
"SELECT connectorset_id,version FROM connectorset WHERE name='$name'"); |
95
|
0
|
|
|
|
|
|
$iterator->execute(); |
96
|
0
|
|
|
|
|
|
while ( my ( $id, $ver ) = $iterator->fetchrow_array() ) { |
97
|
0
|
0
|
|
|
|
|
$cs_version = $ver if $ver gt $cs_version; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $sql = qq(SELECT connectorset.connectorset_id,connectorset.file_name,connectorset.version,connectorset.ftp,connectorset.ftp_files,dotset.dotset_id,dotset.name,label.label_id,label.label |
102
|
|
|
|
|
|
|
FROM connectorset,dotset,connectdotset,label |
103
|
|
|
|
|
|
|
WHERE connectorset.name='$name' AND connectorset.version='$cs_version' |
104
|
|
|
|
|
|
|
AND connectorset.connectorset_id=connectdotset.connectorset_id |
105
|
|
|
|
|
|
|
AND dotset.dotset_id=connectdotset.dotset_id |
106
|
|
|
|
|
|
|
AND label.label_id=connectdotset.label_id); |
107
|
0
|
0
|
|
|
|
|
my $rows = $dbh->selectall_arrayref($sql) or $class->throw( $dbh->errstr ); |
108
|
0
|
0
|
|
|
|
|
return undef unless @$rows; # no data. assume ConnectorSet doesn't exist |
109
|
0
|
|
|
|
|
|
my ( $db_id, $file_name, $version, $ftp, $ftp_files ) = |
110
|
0
|
|
|
|
|
|
@{ $rows->[0] }; # pull ConnectorSet info from first row |
111
|
0
|
|
|
|
|
|
my ( $id2dotset, $label2dotset, $label2labelid ); |
112
|
0
|
|
|
|
|
|
for my $row (@$rows) { |
113
|
0
|
|
|
|
|
|
my ( $connectorset_id, $file_name, $version, $dotset_id, $dotset_name, |
114
|
|
|
|
|
|
|
$label_id, $label ) |
115
|
|
|
|
|
|
|
= @$row; |
116
|
0
|
|
0
|
|
|
|
my $dotset = $id2dotset->{$dotset_id} |
117
|
|
|
|
|
|
|
|| ( |
118
|
|
|
|
|
|
|
$id2dotset->{$dotset_id} = new Bio::ConnectDots::DotSet( |
119
|
|
|
|
|
|
|
-name => $dotset_name, |
120
|
|
|
|
|
|
|
-db_id => $dotset_id, |
121
|
|
|
|
|
|
|
-db => $db |
122
|
|
|
|
|
|
|
) |
123
|
|
|
|
|
|
|
); |
124
|
0
|
|
|
|
|
|
$label2dotset->{$label} = $dotset; |
125
|
0
|
|
|
|
|
|
$label2labelid->{$label} = $label_id; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return new Bio::ConnectDots::ConnectorSet( |
128
|
|
|
|
|
|
|
-name => $name, |
129
|
|
|
|
|
|
|
-file => $file_name, |
130
|
|
|
|
|
|
|
-cs_version => $version, |
131
|
|
|
|
|
|
|
-ftp => $ftp, |
132
|
|
|
|
|
|
|
-ftp_files => $ftp_files, |
133
|
|
|
|
|
|
|
-db_id => $db_id, |
134
|
|
|
|
|
|
|
-db => $db, |
135
|
|
|
|
|
|
|
-dotsets => $label2dotset, |
136
|
|
|
|
|
|
|
-label2labelid => $label2labelid |
137
|
|
|
|
|
|
|
); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
1; |