line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Microarray::GEO::SOFT::GDS;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1557
|
use List::Vectorize qw(!table);
|
|
1
|
|
|
|
|
23009
|
|
|
1
|
|
|
|
|
565
|
|
4
|
1
|
|
|
1
|
|
10
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
5
|
1
|
|
|
1
|
|
14
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use base "Microarray::GEO::SOFT";
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
571
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
1;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new {
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $invocant = shift;
|
15
|
|
|
|
|
|
|
my $class = ref($invocant) || $invocant;
|
16
|
|
|
|
|
|
|
my $self = { "file" => "",
|
17
|
|
|
|
|
|
|
"verbose" => 1,
|
18
|
|
|
|
|
|
|
"use_identifier" => 0,
|
19
|
|
|
|
|
|
|
@_ };
|
20
|
|
|
|
|
|
|
bless($self, $class);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self;
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse {
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $self = shift;
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $fh;
|
31
|
|
|
|
|
|
|
if(! List::Vectorize::is_glob_ref($self->{file})) {
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
open F, $self->{file} or croak "cannot open $self->{file}.\n";
|
34
|
|
|
|
|
|
|
$fh = \*F;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
else {
|
37
|
|
|
|
|
|
|
$fh = $self->{file};
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->_parse_dataset($fh);
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return 1;
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _parse_dataset {
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $self = shift;
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $fh = shift;
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Microarray::GEO::SOFT::_set_fh($self->{verbose});
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $accession;
|
54
|
|
|
|
|
|
|
my $title;
|
55
|
|
|
|
|
|
|
my $platform;
|
56
|
|
|
|
|
|
|
my $field_explain;
|
57
|
|
|
|
|
|
|
my $table_colnames = [];
|
58
|
|
|
|
|
|
|
my $table_rownames = [];
|
59
|
|
|
|
|
|
|
my $table_colnames_explain_hash = {};
|
60
|
|
|
|
|
|
|
my $table_matrix = [];
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
while(my $line = <$fh>) {
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
chomp $line;
|
65
|
|
|
|
|
|
|
if($line =~/^\^DATASET = (GDS\d+)$/) {
|
66
|
|
|
|
|
|
|
$accession = $1;
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if($line =~/^!dataset_title = (.*?)$/) {
|
70
|
|
|
|
|
|
|
$title = $1;
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if($line =~/^!dataset_platform = (GPL\d+)$/) {
|
74
|
|
|
|
|
|
|
$platform = $1;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if($line =~/^#(GSM\d+) = (Value for GSM\d+: )?(.*?)$/) {
|
78
|
|
|
|
|
|
|
$table_colnames_explain_hash->{$1} = $3;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if($line =~/^!dataset_table_begin$/) {
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$line = <$fh>;
|
84
|
|
|
|
|
|
|
chomp $line;
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
@$table_colnames = split "\t", $line, -1;
|
87
|
|
|
|
|
|
|
shift(@$table_colnames);
|
88
|
|
|
|
|
|
|
shift(@$table_colnames);
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
while($line = <$fh>) {
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if($line =~/^!dataset_table_end$/) {
|
93
|
|
|
|
|
|
|
last;
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
chomp $line;
|
97
|
|
|
|
|
|
|
my @tmp = split "\t", $line, -1;
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $uid = shift(@tmp);
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# the second column in the matrix is identifier
|
102
|
|
|
|
|
|
|
my $identifier = shift(@tmp);
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# do not recommond to use identifier
|
105
|
|
|
|
|
|
|
# it is better to convert IDs using id_convert subroutine
|
106
|
|
|
|
|
|
|
if($self->{use_identifier}) {
|
107
|
|
|
|
|
|
|
push(@$table_rownames, $identifier);
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
else {
|
110
|
|
|
|
|
|
|
push(@$table_rownames, $uid);
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
push(@$table_matrix, [@tmp]);
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
if($line =~/^!dataset_table_end$/) {
|
119
|
|
|
|
|
|
|
last;
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $n_row = len($table_rownames);
|
125
|
|
|
|
|
|
|
my $n_col = len($table_colnames);
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $table_colnames_explain = [];
|
128
|
|
|
|
|
|
|
for (@$table_colnames) {
|
129
|
|
|
|
|
|
|
push(@$table_colnames_explain, $table_colnames_explain_hash->{$_});
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
print "Dataset info:\n";
|
133
|
|
|
|
|
|
|
print " Accession: $accession\n";
|
134
|
|
|
|
|
|
|
print " Title: $title\n";
|
135
|
|
|
|
|
|
|
print " Rows: $n_row\n";
|
136
|
|
|
|
|
|
|
print " Columns: $n_col\n";
|
137
|
|
|
|
|
|
|
print "\n";
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
#my $table_rownames_sorted = sort_array($table_rownames, sub {$_[0] cmp $_[1]});
|
140
|
|
|
|
|
|
|
#my $table_rownames_sorted_index = order($table_rownames, sub {$_[0] cmp $_[1]});
|
141
|
|
|
|
|
|
|
#my $table_matrix_sorted = subset($table_matrix, $table_rownames_sorted_index);
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$self->set_meta( accession => $accession,
|
144
|
|
|
|
|
|
|
title => $title,
|
145
|
|
|
|
|
|
|
platform => $platform );
|
146
|
|
|
|
|
|
|
$self->set_table( rownames => $table_rownames,
|
147
|
|
|
|
|
|
|
colnames => $table_colnames,
|
148
|
|
|
|
|
|
|
colnames_explain => $table_colnames_explain,
|
149
|
|
|
|
|
|
|
matrix => $table_matrix );
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Microarray::GEO::SOFT::_set_to_std_fh();
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
return $self;
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
}
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub get_subset {
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $self = shift;
|
160
|
|
|
|
|
|
|
my $arg = {"byrow" => rep(1, len($self->rownames)),
|
161
|
|
|
|
|
|
|
"bycol" => rep(1, len($self->colnames)),
|
162
|
|
|
|
|
|
|
@_};
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$arg->{byrow} = sapply($arg->{byrow}, sub{($_[0] != 0)+0});
|
165
|
|
|
|
|
|
|
$arg->{bycol} = sapply($arg->{bycol}, sub{($_[0] != 0)+0});
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
if(len($arg->{byrow}) != len($self->rownames)
|
168
|
|
|
|
|
|
|
or len($arg->{bycol}) != len($self->colnames)) {
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
croak "ERROR: Do not fit the dimension of the matrix";
|
171
|
|
|
|
|
|
|
}
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
if(sum($arg->{bycol}) == len($self->colnames)) {
|
174
|
|
|
|
|
|
|
$self->set_table( rownames => subset($self->rownames, which($arg->{byrow})),
|
175
|
|
|
|
|
|
|
matrix => subset($self->matrix, which($arg->{byrow})) );
|
176
|
|
|
|
|
|
|
}
|
177
|
|
|
|
|
|
|
else {
|
178
|
|
|
|
|
|
|
my $new_matrix = sapply($self->matrix, sub { subset($_[0], which($arg->{bycol})) });
|
179
|
|
|
|
|
|
|
$new_matrix = subset($new_matrix, which($arg->{byrow}));
|
180
|
|
|
|
|
|
|
$self->set_table( rownames => subset($self->rownames, which($arg->{byrow})),
|
181
|
|
|
|
|
|
|
colnames => subset($self->colnames, which($arg->{bycol})),
|
182
|
|
|
|
|
|
|
colnames_explain => subset($self->colnames_explain, which($arg->{bycol})),
|
183
|
|
|
|
|
|
|
matrix => $new_matrix );
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
}
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
return $self->soft2exprset;
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub id_convert {
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
my $self = shift;
|
194
|
|
|
|
|
|
|
my $gpl = shift;
|
195
|
|
|
|
|
|
|
my $to_id = shift;
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
if($self->{use_identifier}) {
|
198
|
|
|
|
|
|
|
croak "ERROR: You are not suitable to use 'id_convert' since you have set use_identifier to TURE. You can only use 'soft2expr' for further analysis.";
|
199
|
|
|
|
|
|
|
}
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $platform_id = $gpl->accession;
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
if(ref($to_id) eq "Regexp") {
|
204
|
|
|
|
|
|
|
my @match = grep {/$to_id/} @{$gpl->colnames};
|
205
|
|
|
|
|
|
|
if(!scalar(@match)) {
|
206
|
|
|
|
|
|
|
croak "ERROR: Cannot find ID ($to_id) in $platform_id\n";
|
207
|
|
|
|
|
|
|
}
|
208
|
|
|
|
|
|
|
elsif(scalar(@match) > 1) {
|
209
|
|
|
|
|
|
|
carp "WARNING: Find more than one matched ID types (".(join ", ", @match).") under $to_id, only take the first one ($match[0])";
|
210
|
|
|
|
|
|
|
$to_id = $match[0];
|
211
|
|
|
|
|
|
|
}
|
212
|
|
|
|
|
|
|
else {
|
213
|
|
|
|
|
|
|
$to_id = $match[0];
|
214
|
|
|
|
|
|
|
}
|
215
|
|
|
|
|
|
|
}
|
216
|
|
|
|
|
|
|
else {
|
217
|
|
|
|
|
|
|
if(! is_element($to_id, $gpl->colnames)) {
|
218
|
|
|
|
|
|
|
croak "ERROR: Cannot find ID ($to_id) in $platform_id\n";
|
219
|
|
|
|
|
|
|
}
|
220
|
|
|
|
|
|
|
}
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $new_rownames = $gpl->_mapping($to_id, $self->rownames);
|
223
|
|
|
|
|
|
|
my $eset = Microarray::ExprSet->new;
|
224
|
|
|
|
|
|
|
$eset->set_feature($new_rownames);
|
225
|
|
|
|
|
|
|
$eset->set_phenotype($self->colnames_explain);
|
226
|
|
|
|
|
|
|
$eset->set_matrix($self->matrix);
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
return $eset;
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
}
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# change SOFT to ExprSet
|
233
|
|
|
|
|
|
|
# in fact, it is only for GDS
|
234
|
|
|
|
|
|
|
sub soft2exprset {
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
my $self = shift;
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $eset = Microarray::ExprSet->new;
|
239
|
|
|
|
|
|
|
$eset->set_feature($self->rownames);
|
240
|
|
|
|
|
|
|
$eset->set_phenotype($self->colnames_explain);
|
241
|
|
|
|
|
|
|
$eset->set_matrix($self->matrix);
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
return $eset;
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
}
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
__END__
|