line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Maxd; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
1
|
|
|
1
|
|
635
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
149
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
71022
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1938
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
14
|
|
|
|
|
|
|
) ] ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT = qw( |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
24
|
0
|
|
0
|
|
|
|
my $class=ref($self) || $self; |
25
|
0
|
|
|
|
|
|
my(%data,$tag); |
26
|
0
|
0
|
|
|
|
|
while (@_) {$tag = shift; if ($tag =~ /^-/) {$tag =~ s/^-//;$data{lc($tag)} = shift;}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
$data{'dbase'} = "maxd" if (!$data{'dbase'}); |
28
|
0
|
0
|
|
|
|
|
if (!$data{'host'}) { |
29
|
1
|
|
|
1
|
|
1056
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1471
|
|
|
1
|
|
|
|
|
1505
|
|
30
|
0
|
|
|
|
|
|
my $hostname = hostname(); |
31
|
0
|
|
0
|
|
|
|
$data{'host'} = $data{'host'} || $ENV{'MAXD_HOSTDB'} || $hostname || "localhost"; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
0
|
0
|
|
|
|
if (!$data{'user'} || !$data{'pass'}) { |
34
|
0
|
|
|
|
|
|
($data{'user'},$data{'pass'}) = split(/\//,$ENV{'MAXD_USERID'}); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
$data{'dbh'} = _dbconnect ($data{'host'},$data{'dbase'},$data{'user'},$data{'pass'}); |
37
|
|
|
|
|
|
|
# verify special tables |
38
|
0
|
|
|
|
|
|
my($ok,$tname); |
39
|
0
|
|
|
|
|
|
my $st = "show tables"; |
40
|
0
|
|
|
|
|
|
my $sh = $data{'dbh'}->prepare($st); |
41
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
42
|
0
|
|
|
|
|
|
while($tname= $sh->fetchrow_array) { |
43
|
0
|
0
|
|
|
|
|
if ($tname =~ /^Image_Seq$/i) { $ok = 1; last; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
|
|
|
|
if (!$ok) { |
46
|
0
|
|
|
|
|
|
print STDERR "WARNING: Run 'extendMaxD' to configure database\n"; |
47
|
0
|
|
|
|
|
|
$data{'dbh'} = undef; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
$self = bless {} => $class; |
50
|
0
|
|
|
|
|
|
foreach $tag (keys %data) { $self->{$tag} = $data{$tag}; } |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub export { |
55
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
56
|
0
|
|
|
|
|
|
my(%data,$tag); |
57
|
0
|
|
|
|
|
|
foreach $tag (keys %{$self}) { $data{$tag} = $self->{$tag};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
while (@_) {$tag = shift; if ($tag =~ /^-/) {$tag =~ s/^-//;$data{lc($tag)} = shift;}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
return 0 if (ref($data{'dbh'}) ne "DBI::db"); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# valid submitter ? |
62
|
0
|
|
|
|
|
|
($data{'submitter_id'},$data{'submitter_name'}) = |
63
|
|
|
|
|
|
|
_submitterFromSubmitterData($data{'dbh'},$data{'submitter'}); |
64
|
0
|
0
|
|
|
|
|
return (_error(501,$data{'submitter'})) if ($data{'submitter_id'}< 0); |
65
|
0
|
0
|
|
|
|
|
print "Submitter:\tname:$data{'submitter_name'}\tID:$data{'submitter_id'}\n" |
66
|
|
|
|
|
|
|
if ($data{'verbose'}); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# valid repository URL ? |
69
|
0
|
0
|
|
|
|
|
$data{'repository_url'} = "." if (!-d $data{'repository_url'}); |
70
|
0
|
|
|
|
|
|
$data{'repository_url'} .= "/" . $data{'submitter_name'}; |
71
|
0
|
|
|
|
|
|
$data{'repository_url'} =~ s/ +/_/g; |
72
|
0
|
|
|
|
|
|
mkdir($data{'repository_url'},0755); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# valid experiment ? |
75
|
0
|
0
|
|
|
|
|
return 0 if (!$data{'experiment'}); |
76
|
0
|
|
|
|
|
|
($data{'experiment_id'},$data{'experiment_name'}) |
77
|
|
|
|
|
|
|
= _experimentIDfromExperiment($data{'dbh'},$data{'experiment'}, |
78
|
|
|
|
|
|
|
$data{'submitter_id'}); |
79
|
0
|
0
|
|
|
|
|
return (_error(502,"experiment $data{'experiment'} unknown")) |
80
|
|
|
|
|
|
|
if ($data{'experiment_id'} < 0); |
81
|
0
|
0
|
|
|
|
|
print "Experiment:\tname:$data{'experiment_name'}\tID:$data{'experiment_id'}\n" |
82
|
|
|
|
|
|
|
if ($data{'verbose'}); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# valid array type ? |
85
|
0
|
0
|
|
|
|
|
return 0 if (not defined $data{'array_type'}); |
86
|
0
|
0
|
|
|
|
|
$data{'array_name'} = $data{'array_type'} if (!$data{'array_name'}); |
87
|
0
|
0
|
|
|
|
|
$data{'array_id'} = $data{'array_type'} if ($data{'array_type'} =~ /^\d+/); |
88
|
0
|
0
|
|
|
|
|
$data{'array_id'} = _arrayIDfromArrayType($data{'dbh'},$data{'array_type'}) |
89
|
|
|
|
|
|
|
if (!$data{'array_id'}); |
90
|
0
|
0
|
|
|
|
|
return (_error(502,"array $data{'array_type'} unknown")) if ($data{'array_id'} < 0); |
91
|
0
|
0
|
|
|
|
|
print "Array Type:\tname:$data{'array_type'}\tID:$data{'array_id'}\n" |
92
|
|
|
|
|
|
|
if ($data{'verbose'}); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#valid export format ? |
95
|
0
|
|
|
|
|
|
$data{'format'} = lc($data{'format'}); |
96
|
0
|
0
|
|
|
|
|
$data{'format'} = "genespring" if (!$data{'format'}); |
97
|
0
|
0
|
|
|
|
|
return (_error(501,"unknown export format $data{'format'}")) |
98
|
|
|
|
|
|
|
if ($data{'format'} !~ /\bgenespring\b/); |
99
|
0
|
|
0
|
|
|
|
my $templateDir = $ENV{'MAXD_TEMPLATES'} || "."; |
100
|
0
|
0
|
|
|
|
|
return (_error(501,"unable to find template for $data{'format'}")) |
101
|
|
|
|
|
|
|
if (!-f "$templateDir/$data{'format'}\.tmpl"); |
102
|
0
|
0
|
|
|
|
|
print "Export format:\t$data{'format'}\n" if ($data{'verbose'}); |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
print "collecting hybridisation\n" if ($data{'verbose'}); |
105
|
0
|
|
|
|
|
|
my %hybD = _hybridisationByExperimentIDArrayID($data{'dbh'}, |
106
|
|
|
|
|
|
|
$data{'experiment_id'},$data{'array_id'}); |
107
|
0
|
0
|
|
|
|
|
print "collecting tissue\n" if ($data{'verbose'}); |
108
|
0
|
|
|
|
|
|
my(%TisSrc) = _sourceNameTissueByExperiment($data{'dbh'},\%hybD); |
109
|
0
|
|
|
|
|
|
my $numOfExp = scalar(keys %hybD); |
110
|
0
|
|
|
|
|
|
my($imgname,$img,$mesname,$mes,$hybname,$hyb,$k,$v,%tmp,%spotD); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $numOfHyb = scalar(keys %hybD); my $hybCounter = 1; |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
foreach $hybname (sort {$hybD{$a} <=> $hybD{$b}} keys %hybD) { |
|
0
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
print "collecting measurement for $hybname ($hybCounter/$numOfHyb)\n" |
115
|
|
|
|
|
|
|
if ($data{'verbose'}); |
116
|
0
|
|
|
|
|
|
$hybCounter++; |
117
|
0
|
|
|
|
|
|
$hyb = sprintf("%04d",$hybD{$hybname}); |
118
|
0
|
|
|
|
|
|
($imgname,$img) = _imageFromHybridisationID($data{'dbh'},$hyb); |
119
|
0
|
|
|
|
|
|
($mesname,$mes) = _measurementFromImageID($data{'dbh'},$img); |
120
|
0
|
|
|
|
|
|
%tmp = _spotMeasurementByMeasurementID($data{'dbh'},$mes); |
121
|
0
|
|
|
|
|
|
while (($k,$v)=each %tmp) {$spotD{$hyb}{$k} = $v;} |
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
0
|
|
|
|
|
|
my %spotName = _spotNameBySpotID($data{'dbh'},\%tmp); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# export data in txt format |
126
|
0
|
0
|
|
|
|
|
print "exporting data in txt format\n" if ($data{'verbose'}); |
127
|
0
|
|
|
|
|
|
my $dataFileName; |
128
|
0
|
|
|
|
|
|
($dataFileName = "$data{'repository_url'}/$data{'array_name'}") =~ s/\s+/_/g; |
129
|
0
|
|
|
|
|
|
open(OUT,">$dataFileName\.txt"); |
130
|
0
|
|
|
|
|
|
foreach $mes (sort {$a<=>$b} keys %spotName) { |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
print OUT "$spotName{$mes}\t"; |
132
|
0
|
|
|
|
|
|
foreach $hyb (sort keys %spotD) { |
133
|
0
|
|
|
|
|
|
print OUT $spotD{$hyb}{$mes},"\t"; |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
|
print OUT "$spotName{$mes}"; |
136
|
0
|
|
|
|
|
|
print OUT "\n"; |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
close(OUT); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# export master in html format |
141
|
0
|
0
|
|
|
|
|
print "exporting master in htmlformat\n" if ($data{'verbose'}); |
142
|
0
|
|
|
|
|
|
my $date = `date`; |
143
|
1
|
|
|
1
|
|
1831
|
use HTML::Template; |
|
1
|
|
|
|
|
17862
|
|
|
1
|
|
|
|
|
5485
|
|
144
|
0
|
|
|
|
|
|
my $template = HTML::Template->new(filename => "$templateDir/GeneSpring.tmpl"); |
145
|
0
|
|
|
|
|
|
$template->param(SUBMITTER_NAME => $data{'submitter_name'}); |
146
|
0
|
|
|
|
|
|
$template->param(EXPERIMENT_NAME => $data{'experiment_name'}); |
147
|
0
|
|
|
|
|
|
$template->param(ORGANIZ_NAME => $data{'organization_name'}); |
148
|
0
|
|
|
|
|
|
$template->param(DATE => $date); |
149
|
0
|
|
|
|
|
|
$template->param(ARRAY_NAME => $data{'array_name'}); |
150
|
0
|
|
|
|
|
|
$template->param(NUM_OF_EXP => $numOfExp); |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $expCount = 0; |
153
|
0
|
|
|
|
|
|
my @expLoop; |
154
|
0
|
|
|
|
|
|
foreach my $hybname (sort {$hybD{$a} <=> $hybD{$b}} keys %hybD) { |
|
0
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$expCount++; |
156
|
0
|
|
|
|
|
|
my %row = (EXPCOUNT => $expCount, |
157
|
|
|
|
|
|
|
EXPTISSUE => $TisSrc{'tissue'}{$hybD{$hybname}}, |
158
|
|
|
|
|
|
|
EXPNAME => $hybD{$hybname}, |
159
|
|
|
|
|
|
|
EXPSOURCE => $TisSrc{'source'}{$hybD{$hybname}} ); |
160
|
0
|
|
|
|
|
|
push(@expLoop, \%row); |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
$template->param(EXPERIMENT_INFO => \@expLoop); |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my($i,$eLine,$xLine,$sLine,$I); |
165
|
0
|
|
|
|
|
|
$eLine = "";$sLine=""; |
|
0
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
foreach $i (1 .. $numOfExp) { |
167
|
0
|
|
|
|
|
|
$xLine .= " | Exp. $i | ";
168
|
0
|
|
|
|
|
|
$eLine .= " | | ";
169
|
0
|
0
|
|
|
|
|
if ($i == 1) { |
170
|
0
|
|
|
|
|
|
$sLine .= " | | ";
171
|
|
|
|
|
|
|
} else { |
172
|
0
|
|
|
|
|
|
$I = $i + 1; |
173
|
0
|
|
|
|
|
|
$sLine .= " | $I | ";
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $f = basename($dataFileName) . ".txt"; |
178
|
0
|
|
|
|
|
|
$template->param(EXPLINE => $xLine); |
179
|
0
|
|
|
|
|
|
$template->param(SLINE => $sLine); |
180
|
0
|
|
|
|
|
|
$template->param(ELINE => $eLine); |
181
|
0
|
|
|
|
|
|
$template->param(DFILENAME => $f); |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
open(OUT,">$dataFileName\.html"); |
184
|
0
|
|
|
|
|
|
print OUT $template->output; |
185
|
0
|
|
|
|
|
|
close(OUT); |
186
|
0
|
|
|
|
|
|
return 1; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub load_file { |
190
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
191
|
0
|
|
|
|
|
|
my(%data,$tag); |
192
|
0
|
|
|
|
|
|
foreach $tag (keys %{$self}) { $data{$tag} = $self->{$tag};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
while (@_) {$tag = shift; if ($tag =~ /^-/) {$tag =~ s/^-//;$data{lc($tag)} = shift;}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
|
return 0 if (ref($data{'dbh'}) ne "DBI::db"); |
195
|
0
|
0
|
|
|
|
|
return 0 if (!-f $data{'matrix_file'}); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# valid data format ? |
198
|
0
|
|
0
|
|
|
|
$data{'format'} = $data{'format'} || _theFileFormat($data{'matrix_file'}); |
199
|
0
|
0
|
|
|
|
|
return (_error(500,$data{'matrix_file'})) if ($data{'format'} !~ /AFF|TOR/); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# valid image_analysis_protocol ? |
202
|
0
|
0
|
|
|
|
|
return(_error(123,"missing image_analysis_protocol")) |
203
|
|
|
|
|
|
|
if (not defined $data{'image_analysis_protocol'}); |
204
|
0
|
|
|
|
|
|
($data{'image_analysis_protocol_id'},$data{'image_analysis_protocol_name'}) = |
205
|
|
|
|
|
|
|
_imageAnalysisProtocolID($data{'dbh'},$data{'image_analysis_protocol'}); |
206
|
0
|
0
|
|
|
|
|
return (_error(501,"Image Analysis Protocol $data{'image_analysis_protocol'} unknown")) |
207
|
|
|
|
|
|
|
if ($data{'image_analysis_protocol_id'}< 0); |
208
|
0
|
0
|
|
|
|
|
print "Image Protocol:\tname:$data{'image_analysis_protocol_name'}\t", |
209
|
|
|
|
|
|
|
"ID:$data{'image_analysis_protocol_id'}\n" if ($data{'verbose'}); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# valid scanning_protocol ? |
212
|
0
|
0
|
|
|
|
|
return(_error(123,"missing scanning_protocol")) |
213
|
|
|
|
|
|
|
if (not defined $data{'scanning_protocol'}); |
214
|
0
|
|
|
|
|
|
($data{'scanning_protocol_id'},$data{'scanning_protocol_name'}) = |
215
|
|
|
|
|
|
|
_imageAnalysisProtocolID($data{'dbh'},$data{'scanning_protocol'}); |
216
|
0
|
0
|
|
|
|
|
return (_error(501,"Scanning Protocol $data{'scanning_protocol'} unknown")) |
217
|
|
|
|
|
|
|
if ($data{'scanning_protocol_id'}< 0); |
218
|
0
|
0
|
|
|
|
|
print "Scanning Protocol:\tname:$data{'scanning_protocol_name'}\t", |
219
|
|
|
|
|
|
|
"ID:$data{'scanning_protocol_id'}\n" if ($data{'verbose'}); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# valid hybridisation_protocol ? |
222
|
0
|
0
|
|
|
|
|
return(_error(123,"missing hybridisation_protocol")) |
223
|
|
|
|
|
|
|
if (not defined $data{'hybridisation_protocol'}); |
224
|
0
|
|
|
|
|
|
($data{'hybridisation_protocol_id'},$data{'hybridisation_protocol_name'}) = |
225
|
|
|
|
|
|
|
_imageAnalysisProtocolID($data{'dbh'},$data{'hybridisation_protocol'}); |
226
|
0
|
0
|
|
|
|
|
return (_error(501,"Hybridisation Protocol $data{'hybridisation_protocol'} unknown")) |
227
|
|
|
|
|
|
|
if ($data{'hybridisation_protocol_id'}< 0); |
228
|
0
|
0
|
|
|
|
|
print "Hybridisation Protocol:\tname:$data{'hybridisation_protocol_name'}\t", |
229
|
|
|
|
|
|
|
"ID:$data{'hybridisation_protocol_id'}\n" if ($data{'verbose'}); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# valid submitter ? |
232
|
0
|
|
|
|
|
|
($data{'submitter_id'},$data{'submitter_name'}) = |
233
|
|
|
|
|
|
|
_submitterFromSubmitterData($data{'dbh'},$data{'submitter'}); |
234
|
0
|
0
|
|
|
|
|
return (_error(501,"submitter $data{'submitter'} unknown")) |
235
|
|
|
|
|
|
|
if ($data{'submitter_id'}< 0); |
236
|
0
|
0
|
|
|
|
|
print "Submitter:\tname:$data{'submitter_name'}\tID:$data{'submitter_id'}\n" |
237
|
|
|
|
|
|
|
if ($data{'verbose'}); |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# valid array type ? |
240
|
0
|
0
|
|
|
|
|
return 0 if (not defined $data{'array_type'}); |
241
|
0
|
0
|
|
|
|
|
$data{'array_id'} = $data{'array_type'} if ($data{'array_type'} =~ /^\d+/); |
242
|
0
|
0
|
|
|
|
|
$data{'array_id'} = _arrayIDfromArrayType($data{'dbh'},$data{'array_type'}) |
243
|
|
|
|
|
|
|
if (!$data{'array_id'}); |
244
|
0
|
0
|
|
|
|
|
return (_error(502,"array $data{'array_type'} unknown")) if ($data{'array_id'} < 0); |
245
|
0
|
0
|
|
|
|
|
print "Array Type:\tname:$data{'array_type'}\tID:$data{'array_id'}\n" |
246
|
|
|
|
|
|
|
if ($data{'verbose'}); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# valid experiment ? |
249
|
0
|
0
|
|
|
|
|
return 0 if (!$data{'experiment'}); |
250
|
0
|
|
|
|
|
|
($data{'experiment_id'},$data{'experiment_name'}) |
251
|
|
|
|
|
|
|
= _experimentIDfromExperiment($data{'dbh'},$data{'experiment'}, |
252
|
|
|
|
|
|
|
$data{'submitter_id'}); |
253
|
0
|
0
|
|
|
|
|
return (_error(502,"experiment $data{'experiment'} unknown")) |
254
|
|
|
|
|
|
|
if ($data{'experiment_id'} < 0); |
255
|
0
|
0
|
|
|
|
|
print "Experiment:\tname:$data{'experiment_name'}\tID:$data{'experiment_id'}\n" |
256
|
|
|
|
|
|
|
if ($data{'verbose'}); |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# valid extract ? |
259
|
0
|
0
|
|
|
|
|
return (_error(600,"extract")) if (!$data{'extract'}); |
260
|
0
|
|
|
|
|
|
($data{'extract_id'},$data{'extract_name'}) = |
261
|
|
|
|
|
|
|
_extractfromExtractData($data{'dbh'},$data{'extract'}); |
262
|
0
|
0
|
|
|
|
|
return (_error(502,"extract $data{'extract'} unknown")) if ($data{'extract_id'} < 0); |
263
|
0
|
0
|
|
|
|
|
print "Extract:\tname:$data{'extract_name'}\tID:$data{'extract_id'}\n" |
264
|
|
|
|
|
|
|
if ($data{'verbose'}); |
265
|
|
|
|
|
|
|
|
266
|
0
|
0
|
0
|
|
|
|
if (($data{'public'} =~ /true/i) or ($data{'public'} eq "1")) { |
|
0
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
$data{'public'} = "true"; } else {$data{'public'} = "false";} |
268
|
0
|
0
|
|
|
|
|
print "Public:\t$data{'public'}\n" if ($data{'verbose'}); |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
|
$data{'repository_url'} =~ s/[\\\/]$//; |
271
|
0
|
0
|
|
|
|
|
print "Repository URL:\t$data{'repository_url'}\n" if ($data{'verbose'}); |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
$data{'description_id'} = "NULL"; # TEMPORARY |
275
|
0
|
|
|
|
|
|
$data{'image_attribute_description_id'} = "NULL"; # TEMPORARY RawQ |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
$data{'dbh'}->begin_work; |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
my $Hybridisation_ID = -1; |
280
|
0
|
0
|
|
|
|
|
if ($data{'hybridisation'}) { |
281
|
0
|
|
|
|
|
|
$Hybridisation_ID = _hybridisationIDfromHybridisationData( |
282
|
|
|
|
|
|
|
$data{'dbh'},$data{'hybridisation'}); |
283
|
0
|
0
|
|
|
|
|
return (_error(501,$data{'hybridisation'})) if ($Hybridisation_ID < 0); |
284
|
|
|
|
|
|
|
} |
285
|
0
|
0
|
|
|
|
|
if ($Hybridisation_ID < 0) { |
286
|
|
|
|
|
|
|
# create Hybridisation entry |
287
|
0
|
|
|
|
|
|
$Hybridisation_ID = _getNextIDForTable($data{'dbh'},"Hybridisation"); |
288
|
0
|
|
|
|
|
|
$data{'dbh'}->do(qq{insert into Hybridisation |
289
|
|
|
|
|
|
|
(Name,ID,Description_ID,Experiment_ID,Hybridisation_Protocol_ID,Extract_ID,Array_ID) |
290
|
|
|
|
|
|
|
VALUES ("$data{'extract_name'}",$Hybridisation_ID,$data{'description_id'}, |
291
|
|
|
|
|
|
|
$data{'experiment_id'},$data{'hybridisation_protocol_id'}, |
292
|
|
|
|
|
|
|
$data{'extract_id'},$data{'array_id'})}); |
293
|
|
|
|
|
|
|
} |
294
|
0
|
0
|
|
|
|
|
print "Hybridisation ID:\t$Hybridisation_ID\n" if ($data{'verbose'}); |
295
|
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
my $Image_ID = -1; |
297
|
0
|
0
|
|
|
|
|
if ($data{'image'}) { |
298
|
0
|
|
|
|
|
|
$Image_ID = _imageIDfromImageData ($data{'dbh'},$data{'image'}); |
299
|
0
|
0
|
|
|
|
|
return (_error(501,$data{'image'})) if ($Image_ID < 0); |
300
|
|
|
|
|
|
|
} |
301
|
0
|
0
|
|
|
|
|
if ($Image_ID < 0) { |
302
|
|
|
|
|
|
|
# create Image entry |
303
|
0
|
|
|
|
|
|
$Image_ID = _getNextIDForTable($data{'dbh'},"Image"); |
304
|
0
|
|
|
|
|
|
my $imageURL = |
305
|
|
|
|
|
|
|
"$data{'repository_url'}/$data{'submitter_name'}/$data{'extract_name'}\.dat"; |
306
|
0
|
|
|
|
|
|
$imageURL =~ s/ +/_/g; |
307
|
0
|
|
|
|
|
|
$data{'dbh'}->do(qq{insert into Image |
308
|
|
|
|
|
|
|
(Name,ID,Digitised_Image_URL,Hybridisation_ID,Scanning_Protocol_ID) VALUES |
309
|
|
|
|
|
|
|
("$data{'extract_name'}",$Image_ID,"$imageURL", |
310
|
|
|
|
|
|
|
$Hybridisation_ID,$data{'scanning_protocol_id'})}); |
311
|
|
|
|
|
|
|
} |
312
|
0
|
0
|
|
|
|
|
print "Image ID:\t$Image_ID\n" if ($data{'verbose'}); |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# create Measurement entry |
315
|
0
|
|
|
|
|
|
my $Measurement_ID = _getNextIDForTable($data{'dbh'},"Measurement"); |
316
|
0
|
|
|
|
|
|
$data{'dbh'}->do(qq{insert into Measurement |
317
|
|
|
|
|
|
|
(Name,ID,Image_ID,Image_Analysis_Protocol_ID,Image_Attribute_Description_ID,Public) |
318
|
|
|
|
|
|
|
VALUES ("$data{'extract_name'}",$Measurement_ID,$Image_ID, |
319
|
|
|
|
|
|
|
$data{'image_analysis_protocol_id'},$data{'image_attribute_description_id'}, |
320
|
|
|
|
|
|
|
"$data{'public'}")}); |
321
|
0
|
0
|
|
|
|
|
print "Measurement ID:\t$Measurement_ID\n" if ($data{'verbose'}); |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
# insert SpotMeasurement data |
324
|
0
|
0
|
|
|
|
|
print "Loading Spot data\n" if ($data{'verbose'}); |
325
|
0
|
|
|
|
|
|
my %spots = _loadSpotID($data{'dbh'},$data{'array_id'}); |
326
|
0
|
0
|
|
|
|
|
print "Loading Experiment data\n" if ($data{'verbose'}); |
327
|
0
|
|
|
|
|
|
my @expression_level = _loadFromFile($data{'format'},$data{'matrix_file'},"Avg Diff"); |
328
|
0
|
|
|
|
|
|
my @significance = _loadFromFile($data{'format'},$data{'matrix_file'},"Pos Fraction"); |
329
|
0
|
|
|
|
|
|
my @spot_name = _loadFromFile($data{'format'},$data{'matrix_file'},"Probe Set Name"); |
330
|
0
|
0
|
|
|
|
|
print "Inserting experiment data\n" if ($data{'verbose'}); |
331
|
0
|
|
|
|
|
|
my $st = "insert into SpotMeasurement |
332
|
|
|
|
|
|
|
(Expression_Level,Significance,Output_Description_ID,Spot_ID,Measurement_ID) |
333
|
|
|
|
|
|
|
VALUES (?,?,?,?,$Measurement_ID)"; |
334
|
0
|
|
|
|
|
|
my $sh = $data{'dbh'}->prepare($st); |
335
|
0
|
|
|
|
|
|
my($rv,$level,$signif,$desc,$spotNam,$spotID); |
336
|
0
|
|
|
|
|
|
foreach $spotNam (@spot_name) { |
337
|
0
|
|
|
|
|
|
$level = shift(@expression_level); |
338
|
0
|
|
|
|
|
|
$signif= shift(@significance); |
339
|
0
|
|
|
|
|
|
$desc = "NULL"; |
340
|
0
|
|
|
|
|
|
$spotID = $spots{$spotNam}; |
341
|
0
|
0
|
|
|
|
|
return(_error(600,"unknown Spot name $spotNam\n")) if (!$spotID); |
342
|
0
|
|
|
|
|
|
$rv = $sh->execute($level,$signif,$desc,$spotID); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
$data{'dbh'}->commit; |
346
|
0
|
|
|
|
|
|
return 1; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub version { |
350
|
0
|
|
|
0
|
0
|
|
return $VERSION; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
sub disconnect { |
354
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
355
|
0
|
|
|
|
|
|
$self->{'dbh'}->disconnect; |
356
|
0
|
|
|
|
|
|
delete $self->{'dbh'}; |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
### internal routines and methods |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub _dbconnect { |
362
|
0
|
|
|
0
|
|
|
my($host,$dbase,$user,$pass) = @_; |
363
|
0
|
|
|
|
|
|
my $MAXD = "DBI:mysql:$dbase:$host"; |
364
|
0
|
|
0
|
|
|
|
my $db = DBI->connect($MAXD,$user,$pass) || $DBI::errstr; |
365
|
0
|
|
|
|
|
|
return $db; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
sub _measurementFromImageID { |
369
|
0
|
|
|
0
|
|
|
my($dbh,$id) = @_; |
370
|
0
|
|
|
|
|
|
my $st = qq{select Name,ID from Measurement where Image_ID = $id}; |
371
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
372
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
373
|
0
|
|
|
|
|
|
my $name; |
374
|
0
|
|
|
|
|
|
($name,$id) =$sh->fetchrow_array; |
375
|
0
|
|
|
|
|
|
return ($name,$id); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub _spotMeasurementByMeasurementID { |
379
|
0
|
|
|
0
|
|
|
my($dbh,$id)=@_; |
380
|
0
|
|
|
|
|
|
my(%data,$Expression_Level,$Spot_ID); |
381
|
0
|
|
|
|
|
|
my $st = qq{select Expression_Level,Spot_ID |
382
|
|
|
|
|
|
|
from SpotMeasurement where Measurement_ID = $id}; |
383
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
384
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
385
|
0
|
|
|
|
|
|
while (($Expression_Level,$Spot_ID) = $sh->fetchrow_array) { |
386
|
0
|
|
|
|
|
|
$data{$Spot_ID} = $Expression_Level; |
387
|
|
|
|
|
|
|
} |
388
|
0
|
|
|
|
|
|
return %data; |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
sub _imageFromHybridisationID { |
392
|
0
|
|
|
0
|
|
|
my($dbh,$id) = @_; |
393
|
0
|
|
|
|
|
|
my $st = qq{select Name,ID from Image where Hybridisation_ID = $id}; |
394
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
395
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
396
|
0
|
|
|
|
|
|
my $name; |
397
|
0
|
|
|
|
|
|
($name,$id) =$sh->fetchrow_array; |
398
|
0
|
|
|
|
|
|
return ($name,$id); |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub _spotNameBySpotID { |
402
|
0
|
|
|
0
|
|
|
my($dbh,$spot) =@_; |
403
|
0
|
|
|
|
|
|
my($id,%data,$name); |
404
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare("select Name from Spot where ID = ?"); |
405
|
0
|
|
|
|
|
|
foreach $id (keys %{$spot}) { |
|
0
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
|
my $rv = $sh->execute($id); |
407
|
0
|
|
|
|
|
|
($name) = $sh->fetchrow_array; |
408
|
0
|
|
|
|
|
|
$data{$id} = $name; |
409
|
|
|
|
|
|
|
} |
410
|
0
|
|
|
|
|
|
return %data; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
sub _sourceNameTissueByExperiment { |
414
|
0
|
|
|
0
|
|
|
my ($dbh,$exp) = @_; |
415
|
0
|
|
|
|
|
|
my $st = qq{select Source.Name,Source.Tissue |
416
|
|
|
|
|
|
|
from Source,Sample,Extract,Hybridisation |
417
|
|
|
|
|
|
|
where Source.ID = Sample.Source_ID |
418
|
|
|
|
|
|
|
and Sample.ID = Extract.Sample_ID |
419
|
|
|
|
|
|
|
and Extract.ID = Hybridisation.Extract_ID |
420
|
|
|
|
|
|
|
and Hybridisation.ID = ?}; |
421
|
0
|
|
|
|
|
|
my(%data); |
422
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
423
|
0
|
|
|
|
|
|
foreach my $expname (keys %{$exp}) { |
|
0
|
|
|
|
|
|
|
424
|
0
|
|
|
|
|
|
my $expid = $$exp{$expname}; |
425
|
0
|
|
|
|
|
|
my $rv = $sh->execute($expid); |
426
|
0
|
|
|
|
|
|
my ($name,$tissue) = $sh->fetchrow_array; |
427
|
0
|
|
|
|
|
|
$data{'tissue'}{$expid} = $tissue; |
428
|
0
|
|
|
|
|
|
$data{'source'}{$expid} = $name; |
429
|
|
|
|
|
|
|
} |
430
|
0
|
|
|
|
|
|
return(%data); |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
sub _hybridisationByExperimentIDArrayID { |
434
|
0
|
|
|
0
|
|
|
my($dbh,$id,$array)=@_; |
435
|
0
|
|
|
|
|
|
my(%data,$ID,$Array_ID,$name); |
436
|
0
|
|
|
|
|
|
my $st = qq{select Name,ID,Array_ID from Hybridisation |
437
|
|
|
|
|
|
|
where Experiment_ID = $id and Array_ID = $array}; |
438
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
439
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
440
|
0
|
|
|
|
|
|
while (($name,$ID,$Array_ID) = $sh->fetchrow_array) { |
441
|
0
|
|
|
|
|
|
$data{$name} = $ID; |
442
|
|
|
|
|
|
|
} |
443
|
0
|
|
|
|
|
|
return %data; |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
sub _loadSpotID { |
447
|
0
|
|
|
0
|
|
|
my($dbh,$array_id) = @_; |
448
|
0
|
|
|
|
|
|
my(%spot,$name,$id); |
449
|
0
|
|
|
|
|
|
my $st = "select name,id from spot where Array_Type_ID = $array_id"; |
450
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
451
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
452
|
0
|
|
|
|
|
|
while (($name,$id)= $sh->fetchrow_array) { |
453
|
0
|
|
|
|
|
|
$spot{$name} = $id; |
454
|
|
|
|
|
|
|
} |
455
|
0
|
|
|
|
|
|
return %spot; |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub _getNextIDForTable { |
459
|
0
|
|
|
0
|
|
|
my($dbh,$table)=@_; |
460
|
0
|
|
|
|
|
|
$table .= "_Seq"; |
461
|
0
|
|
|
|
|
|
$dbh->do("UPDATE $table SET id=LAST_INSERT_ID(id+1)"); |
462
|
0
|
|
|
|
|
|
my $st = "select ID from $table"; |
463
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
464
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
465
|
0
|
|
|
|
|
|
my ($id)= $sh->fetchrow_array; |
466
|
0
|
|
|
|
|
|
return $id; |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub _imageAnalysisProtocolID { |
470
|
0
|
|
|
0
|
|
|
my($dbh,$name) = @_; |
471
|
0
|
|
|
|
|
|
my($id); |
472
|
0
|
|
|
|
|
|
my $st = "select Name,ID from imageanalysisprotocol where "; |
473
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
475
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
476
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
477
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
478
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
479
|
0
|
|
|
|
|
|
return ($id,$name); |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub _extractfromExtractData { |
483
|
0
|
|
|
0
|
|
|
my($dbh,$name) = @_; |
484
|
0
|
|
|
|
|
|
my($id); |
485
|
0
|
|
|
|
|
|
my $st = "select Name,ID from Extract where "; |
486
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
487
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
488
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
489
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
490
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
491
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
492
|
0
|
|
|
|
|
|
return ($id,$name); |
493
|
|
|
|
|
|
|
} |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
sub _submitterFromSubmitterData { |
496
|
0
|
|
|
0
|
|
|
my($dbh,$name) = @_; |
497
|
0
|
|
|
|
|
|
my($id); |
498
|
0
|
|
|
|
|
|
my $st = "select Name,ID from Submitter where "; |
499
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
500
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
501
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
502
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
503
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
504
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
505
|
0
|
|
|
|
|
|
return ($id,$name); |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
sub _hybridisationIDfromHybridisationData { |
509
|
0
|
|
|
0
|
|
|
my($dbh,$name) = @_; |
510
|
0
|
|
|
|
|
|
my($id); |
511
|
0
|
|
|
|
|
|
my $st = "select Name,ID from Hybridisation where "; |
512
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
513
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
514
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
515
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
516
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
517
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
518
|
0
|
|
|
|
|
|
return ($id,$name); |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
sub _imageIDfromImageData { |
522
|
0
|
|
|
0
|
|
|
my($dbh,$name) = @_; |
523
|
0
|
|
|
|
|
|
my($id); |
524
|
0
|
|
|
|
|
|
my $st = "select Name,ID from Image where "; |
525
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
526
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
527
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
528
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
529
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
530
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
531
|
0
|
|
|
|
|
|
return ($id,$name); |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
sub _columns_in_file { |
535
|
0
|
|
|
0
|
|
|
my($f) = @_; |
536
|
0
|
|
|
|
|
|
my($fileType,$l,$name,@col); |
537
|
0
|
|
|
|
|
|
$fileType = _theFileFormat($f); |
538
|
0
|
|
|
|
|
|
open(IN,$f); |
539
|
0
|
0
|
|
|
|
|
if ($fileType eq "AFF") { |
|
|
0
|
|
|
|
|
|
540
|
0
|
|
|
|
|
|
$l = ""; while ($l !~ /Analysis Name/) {$l = ;} chomp($l); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
541
|
0
|
|
|
|
|
|
foreach $name (split(/\t/,$l)) { |
542
|
0
|
|
|
|
|
|
push(@col,$name); |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
} elsif ($fileType eq "TOR") { |
545
|
0
|
0
|
|
|
|
|
while ($l = ) { last if ($l =~ /Begin Measurements/); } |
|
0
|
|
|
|
|
|
|
546
|
0
|
|
|
|
|
|
$l = ; chomp($l); |
|
0
|
|
|
|
|
|
|
547
|
0
|
|
|
|
|
|
foreach $name (split(/\t/,$l)) { |
548
|
0
|
|
|
|
|
|
push(@col,$name); |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
} |
551
|
0
|
|
|
|
|
|
close(IN); |
552
|
0
|
|
|
|
|
|
return @col; |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
sub _loadFromAffimetrixFile { |
556
|
0
|
|
|
0
|
|
|
my ($f,$column)=@_; |
557
|
0
|
|
|
|
|
|
my(@data,$value,$l); |
558
|
0
|
|
|
|
|
|
open(IN,$f); |
559
|
0
|
|
|
|
|
|
while ($l = ) { |
560
|
0
|
0
|
|
|
|
|
next if ($l !~ /^\d/); |
561
|
0
|
|
|
|
|
|
chomp($l); |
562
|
0
|
|
|
|
|
|
$value = (split(/\t/,$l))[$column]; |
563
|
0
|
|
|
|
|
|
push(@data,$value); |
564
|
|
|
|
|
|
|
} |
565
|
0
|
|
|
|
|
|
close(IN); |
566
|
0
|
|
|
|
|
|
return @data; |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub _loadFromOtherFile{ |
570
|
0
|
|
|
0
|
|
|
my ($f,$column)=@_; |
571
|
0
|
|
|
|
|
|
my($l,@data,$value); |
572
|
0
|
|
|
|
|
|
open(IN,$f); |
573
|
0
|
0
|
|
|
|
|
while ($l = ) { last if ($l =~ /Begin Measurements/); } |
|
0
|
|
|
|
|
|
|
574
|
0
|
|
|
|
|
|
while ($l = ) { |
575
|
0
|
0
|
|
|
|
|
last if ($l =~ /^End/); |
576
|
0
|
0
|
|
|
|
|
next if ($l !~ /^\d/); |
577
|
0
|
|
|
|
|
|
chomp($l); |
578
|
0
|
|
|
|
|
|
$value = (split(/\t/,$l))[$column]; |
579
|
0
|
|
|
|
|
|
push(@data,$value); |
580
|
|
|
|
|
|
|
} |
581
|
0
|
|
|
|
|
|
close(IN); |
582
|
0
|
|
|
|
|
|
return @data; |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
sub _loadFromFile { |
586
|
0
|
|
|
0
|
|
|
my($fileType,$f,$column) = @_; |
587
|
0
|
|
|
|
|
|
my @data; |
588
|
0
|
0
|
|
|
|
|
if ($column !~ /^\d+$/) { |
589
|
0
|
|
|
|
|
|
my @col = _columns_in_file($f); |
590
|
0
|
|
|
|
|
|
my $i = 0; my $a; |
|
0
|
|
|
|
|
|
|
591
|
0
|
|
|
|
|
|
foreach $a (@col) { |
592
|
0
|
0
|
|
|
|
|
if ($a eq $column) { |
593
|
0
|
|
|
|
|
|
$column = $i; |
594
|
0
|
|
|
|
|
|
last; |
595
|
|
|
|
|
|
|
} |
596
|
0
|
|
|
|
|
|
$i++; |
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
} |
599
|
0
|
0
|
|
|
|
|
if ($fileType eq "AFF") { |
|
|
0
|
|
|
|
|
|
600
|
0
|
|
|
|
|
|
@data = _loadFromAffimetrixFile($f,$column); |
601
|
|
|
|
|
|
|
} elsif ($fileType eq "TOR") { |
602
|
0
|
|
|
|
|
|
@data = _loadFromOtherFile($f,$column); |
603
|
|
|
|
|
|
|
} else { |
604
|
0
|
|
|
|
|
|
print "Unknown file type\n"; |
605
|
|
|
|
|
|
|
} |
606
|
0
|
|
|
|
|
|
return @data; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
sub _experimentIDfromExperiment { |
610
|
0
|
|
|
0
|
|
|
my($dbh,$name,$subid) = @_; |
611
|
0
|
|
|
|
|
|
my($id); |
612
|
0
|
|
|
|
|
|
my $st = "select Name,ID from Experiment where submitter_id = $subid and "; |
613
|
0
|
0
|
|
|
|
|
if ($name =~ /^\d+$/) {$st .= qq{ID = "$name"};} else {$st .= qq{ Name = "$name"};} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
614
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
615
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
616
|
0
|
|
|
|
|
|
($name,$id)= $sh->fetchrow_array; |
617
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
618
|
0
|
0
|
|
|
|
|
$name = "" unless defined $name; |
619
|
0
|
|
|
|
|
|
return ($id,$name); |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub _arrayIDfromArrayType { |
623
|
0
|
|
|
0
|
|
|
my($dbh,$arrayType)=@_; |
624
|
0
|
|
|
|
|
|
my $st = qq{select ID from ArrayType where Name = "$arrayType"}; |
625
|
0
|
|
|
|
|
|
my $sh = $dbh->prepare($st); |
626
|
0
|
|
|
|
|
|
my $rv = $sh->execute; |
627
|
0
|
|
|
|
|
|
my $id = $sh->fetchrow_array; |
628
|
0
|
0
|
|
|
|
|
$id = "-1" unless defined $id; |
629
|
0
|
|
|
|
|
|
return $id; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
sub _theFileFormat { |
633
|
0
|
|
|
0
|
|
|
my($f) = @_; my($l,$fileType); |
|
0
|
|
|
|
|
|
|
634
|
0
|
|
|
|
|
|
open(IN,$f); $l = ; close(IN); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
635
|
0
|
0
|
|
|
|
|
if ($l =~ /Expression Analysis: Metrics Tab/) { |
|
|
0
|
|
|
|
|
|
636
|
0
|
|
|
|
|
|
$fileType = "AFF"; |
637
|
|
|
|
|
|
|
} elsif ($l =~ /^\?\?/) { |
638
|
0
|
|
|
|
|
|
$fileType = "TOR"; |
639
|
|
|
|
|
|
|
} else { |
640
|
0
|
|
|
|
|
|
$fileType = "UNK"; |
641
|
|
|
|
|
|
|
} |
642
|
0
|
|
|
|
|
|
return $fileType; |
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
sub _error { |
646
|
0
|
|
|
0
|
|
|
my($errnum,$errval)=@_; |
647
|
0
|
|
|
|
|
|
print STDERR "Error $errnum: $errval\n"; |
648
|
0
|
|
|
|
|
|
return 0; |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
1; |
652
|
|
|
|
|
|
|
__END__ |