File Coverage

blib/lib/Microarray/GEO/SOFT/GSM.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Microarray::GEO::SOFT::GSM;
2            
3             # parse SOFT file
4             # get the GSM part, only the first record of GSM from the current position to read
5            
6 1     1   2475 use List::Vectorize qw(!table);
  1         1327691  
  1         670  
7 1     1   10 use Carp;
  1         1  
  1         65  
8 1     1   6 use strict;
  1         2  
  1         40  
9            
10 1     1   5 use base "Microarray::GEO::SOFT";
  1         2  
  1         745  
11            
12             1;
13            
14            
15             sub new {
16            
17             my $invocant = shift;
18             my $class = ref($invocant) || $invocant;
19             my $self = { "file" => "",
20             "verbose" => 1,
21             "sample_value_column" => "VALUE",
22             @_ };
23             bless($self, $class);
24            
25             return $self;
26            
27             }
28            
29             sub parse {
30            
31             my $self = shift;
32            
33             my $fh;
34             if(! List::Vectorize::is_glob_ref($self->{file})) {
35            
36             open F, $self->{file} or croak "cannot open $self->{file}.\n";
37             $fh = \*F;
38             }
39             else {
40             $fh = $self->{file};
41             }
42            
43             $self->_parse_sample($fh);
44            
45             return 1;
46             }
47            
48             sub _parse_sample {
49            
50             my $self = shift;
51            
52             my $fh = shift;
53            
54             Microarray::GEO::SOFT::_set_fh($self->{verbose});
55            
56             my $accession;
57             my $title;
58             my $platform;
59             my $table_colnames = [];
60             my $table_rownames = [];
61             my $table_matrix = [];
62            
63             while(my $line = <$fh>) {
64            
65             chomp $line;
66             if($line =~/^!Sample_geo_accession = (GSM\d+)$/) {
67             $accession = $1;
68             }
69            
70             elsif($line =~/^!Sample_title = (.*?)$/) {
71             $title = $1;
72             }
73            
74             elsif($line =~/^!Sample_platform_id = (GPL\d+)$/) {
75             $platform = $1;
76             }
77            
78             elsif($line =~/^!sample_table_begin$/) {
79            
80             $line = <$fh>;
81             chomp $line;
82            
83             @$table_colnames = split "\t", $line, -1;
84             shift(@$table_colnames);
85            
86             my $value_index = -1;
87             for(my $i = 0; $i < len($table_colnames); $i ++) {
88             if($table_colnames->[$i] eq $self->{sample_value_column}) {
89             $value_index = $i;
90             last;
91             }
92             }
93            
94             if($value_index == -1) {
95             croak "ERROR: Cannot find sample value column ($self->{sample_value_column}).";
96             }
97            
98             while($line = <$fh>) {
99            
100             if($line =~/^!sample_table_end$/) {
101             last;
102             }
103            
104             chomp $line;
105             my @tmp = split "\t", $line, -1;
106            
107             my $uid = shift(@tmp);
108            
109             push(@$table_rownames, $uid);
110             # one column matrix
111             push(@$table_matrix, [$tmp[$value_index]]);
112             }
113            
114            
115             }
116            
117             if($line =~/^!sample_table_end$/) {
118             last;
119             }
120            
121             }
122            
123             my $n_row = len($table_rownames);
124             my $n_col = len($table_colnames);
125            
126             print "Sample info:\n";
127             print " Accession: $accession\n";
128             print " Platform: $platform\n";
129             print " Title: $title\n";
130             print " Rows: $n_row\n";
131             print " Columns: $n_col\n";
132             print "\n";
133            
134             #my $table_rownames_sorted = sort_array($table_rownames, sub {$_[0] cmp $_[1]});
135             #my $table_rownames_sorted_index = order($table_rownames, sub {$_[0] cmp $_[1]});
136             #my $table_matrix_sorted = subset($table_matrix, $table_rownames_sorted_index);
137            
138             $self->set_meta( accession => $accession,
139             title => $title,
140             platform => $platform );
141             $self->set_table( rownames => $table_rownames,
142             colnames => $table_colnames,
143             matrix => $table_matrix );
144            
145             Microarray::GEO::SOFT::_set_to_std_fh();
146            
147             return $self;
148            
149             }
150            
151            
152             __END__