]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/read_soft
added use strict to all biopieces
[biopieces.git] / bp_bin / read_soft
1 #!/usr/bin/env perl
2
3 # Copyright (C) 2007-2009 Martin A. Hansen.
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24 # Read SOFT entries from one or more files.
25 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
26
27 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
28
29
30 use warnings;
31 use strict;
32 use Maasha::Biopieces;
33 use Maasha::Filesys;
34 use Maasha::NCBI;
35
36
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38
39
40 my ( $options, $in, $out, $record, $data_in, $num, $entry, $records, $soft_index,
41      $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip, $file );
42
43 $options = Maasha::Biopieces::parse_options(
44     [
45         { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
46         { long => 'samples', short => 's', type => 'list',   mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
47         { long => 'num',     short => 'n', type => 'uint',   mandatory => 'no', default => undef, allowed => undef, disallowed => '0' },
48     ]   
49 );
50
51 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
52 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
53
54 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
55     Maasha::Biopieces::put_record( $record, $out );
56 }
57
58 $num = 1;
59
60 foreach $file ( @{ $options->{ "data_in" } } )
61 {
62     print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
63
64     $soft_index = Maasha::NCBI::soft_index_file( $file );
65
66     $fh         = Maasha::Filesys::file_read_open( $file );
67
68     @platforms  = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
69
70     print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
71
72     $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
73
74     @samples    = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
75
76     $old_end    = $platforms[ -1 ]->{ "LINE_END" };
77
78     foreach $sample ( @samples )
79     {
80         $skip = 0;
81         $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
82
83         print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
84
85         $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
86
87         foreach $record ( @{ $records } )
88         {
89             Maasha::Biopieces::put_record( $record, $out );
90
91             goto NUM if $options->{ "num" } and $num == $options->{ "num" };
92
93             $num++;
94         }
95
96         $old_end = $sample->{ "LINE_END" };
97     }
98
99     close $fh;
100 }
101
102 NUM:
103
104 close $data_in if $data_in;
105 close $fh if $fh;
106
107 Maasha::Biopieces::close_stream( $in );
108 Maasha::Biopieces::close_stream( $out );
109
110
111 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
112
113
114 BEGIN
115 {
116     Maasha::Biopieces::status_set();
117 }
118
119
120 END
121 {
122     Maasha::Biopieces::status_log();
123 }
124
125
126 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
127
128
129 __END__