]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/read_soft
implementing status solution
[biopieces.git] / bp_bin / read_soft
1 #!/usr/bin/env perl -w
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 strict;
31 use Maasha::Biopieces;
32 use Maasha::Filesys;
33 use Maasha::NCBI;
34
35
36 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
37
38
39 my ( $options, $in, $out, $record, $data_in, $num, $entry, $records, $soft_index,
40      $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip, $file );
41
42 $options = Maasha::Biopieces::parse_options(
43     [
44         { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
45         { long => 'samples', short => 's', type => 'list',   mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
46         { long => 'num',     short => 'n', type => 'uint',   mandatory => 'no', default => undef, allowed => undef, disallowed => '0' },
47     ]   
48 );
49
50 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
51 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
52
53 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
54     Maasha::Biopieces::put_record( $record, $out );
55 }
56
57 $num = 1;
58
59 foreach $file ( @{ $options->{ "data_in" } } )
60 {
61     print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
62
63     $soft_index = Maasha::NCBI::soft_index_file( $file );
64
65     $fh         = Maasha::Filesys::file_read_open( $file );
66
67     @platforms  = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
68
69     print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
70
71     $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
72
73     @samples    = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
74
75     $old_end    = $platforms[ -1 ]->{ "LINE_END" };
76
77     foreach $sample ( @samples )
78     {
79         $skip = 0;
80         $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
81
82         print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
83
84         $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
85
86         foreach $record ( @{ $records } )
87         {
88             Maasha::Biopieces::put_record( $record, $out );
89
90             goto NUM if $options->{ "num" } and $num == $options->{ "num" };
91
92             $num++;
93         }
94
95         $old_end = $sample->{ "LINE_END" };
96     }
97
98     close $fh;
99 }
100
101 NUM:
102
103 close $data_in if $data_in;
104 close $fh if $fh;
105
106 Maasha::Biopieces::close_stream( $in );
107 Maasha::Biopieces::close_stream( $out );
108
109
110 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
111
112
113 BEGIN
114 {
115     Maasha::Biopieces::status_set();
116 }
117
118
119 END
120 {
121     Maasha::Biopieces::status_log();
122 }
123
124
125 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
126
127
128 __END__