-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_interaction_xml.cgi
executable file
·164 lines (126 loc) · 3.67 KB
/
get_interaction_xml.cgi
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl
BEGIN{
unshift @INC, "./modules/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi";
}
print "Content-Type: text/xml\n\n";
use strict;
use warnings;
use CGI;
use DBI;
use Data::Dumper;
use Template;
my $query = new CGI;
my $locus = $query->param('locus');
my $type = $query->param('type');
#$locus = "AT1G01040";
#####
## Here's all the MySQL initialization
#####
# MySQL database information
my $dbName = 'gsignal';
my $host = "bioinfolab.unl.edu";
my $user = "gprotein";
my $password = "gpa";
# Connection info, connect
my $connectionInfo = "dbi:mysql:$dbName:$host";
my $dbh = DBI->connect($connectionInfo, $user, $password)
or die "Could not connect to $dbName: " . DBI->errstr;
####
# Here's just a test SQL
####
my ($hash_ref, $nodes) = get_data();
print_xml($hash_ref);
##################################################
# get_data
#
# DESCRIPTION: get all of the data needed for the interaction
# using the locus
#
# IN
# $locus : locus of the protein to be found
# @loci : an array of multiple locus
#
# OUT
# $hashref : a reference to a hash that will be
# used by XML::Simple
##################################################
sub get_data{
#######
###TODO
#######
### Redo this query so we can also get correlation coefficients
my $sql = "
SELECT
Bait_locus,
Prey_locus,
BP_ID
FROM
bait,
interact
WHERE
bait.Bait_ID = interact.Bait_ID AND
(bait.Bait_locus = '$locus') OR ( interact.Prey_locus = '$locus')
";
# If this is a bait, group by preys
if($type eq "bait"){
$sql .= "
GROUP BY
Prey_locus;";
}
# If this is a prey, group by baits
elsif($type eq "prey"){
$sql .= "
GROUP BY
bait.Bait_ID;";
}
# Prepare and execute SQL statement
my $sth = $dbh->prepare($sql) or die "Could not prepare statement: " . DBI->errstr;
$sth->execute()
or die "Couldn't execute statement: " . $sth->errstr;
# create variables and bind to columns
my ($bp_id, $bait_locus, $prey_locus);
$sth->bind_columns(\$bait_locus, \$prey_locus, \$bp_id);
# Make all of the hashes, including the node hash
my %protein_hash;
my %node_hash;
my @edges;
while($sth->fetch()){
my %temp_hash;
$temp_hash{node_from} = $bait_locus;
$temp_hash{node_to} = $prey_locus;
$protein_hash{$bp_id} = \%temp_hash;
push @edges, \%temp_hash;
$node_hash{$bait_locus} = 1;
$node_hash{$prey_locus} = 1;
}
my @nodes;
# For each of the nodes in the hash add it to the array
foreach my $node(keys %node_hash){
push @nodes, $node;
}
return \%protein_hash, \@nodes, \@edges;
}
##################################################
# print_xml
#
# DESCRIPTION: print the xml using the hash ref that was given
#
# IN
# $interactions : all of the interactions for this locus
#
# OUT
# Nothing will be returned, all will be printed - John 3:42
#
##################################################
sub print_xml{
my ($interactions, $nodes, $edges) = get_data();
#Define all of the Template stuff
my $interaction_xml = 'templates/interaction.xml';
my $template = Template->new();
my $data = {
'interactions' => $interactions,
'nodes' => $nodes,
'edges' => $edges
};
$template->process($interaction_xml, $data);
}