3 # Copyright (C) 2007-2009 Martin A. Hansen.
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.
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.
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.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # Read SOFT entries from one or more files.
25 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
27 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
36 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 my ( $options, $in, $out, $record, $data_in, $num, $entry, $records, $soft_index,
40 $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip, $file );
42 $options = Maasha::Biopieces::parse_options(
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' },
50 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
51 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
53 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
54 Maasha::Biopieces::put_record( $record, $out );
59 foreach $file ( @{ $options->{ "data_in" } } )
61 print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
63 $soft_index = Maasha::NCBI::soft_index_file( $file );
65 $fh = Maasha::Filesys::file_read_open( $file );
67 @platforms = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
69 print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
71 $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
73 @samples = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
75 $old_end = $platforms[ -1 ]->{ "LINE_END" };
77 foreach $sample ( @samples )
80 $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
82 print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
84 $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
86 foreach $record ( @{ $records } )
88 Maasha::Biopieces::put_record( $record, $out );
90 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
95 $old_end = $sample->{ "LINE_END" };
103 close $data_in if $data_in;
107 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
112 $run_time_beg = Maasha::Biopieces::run_time();
114 Maasha::Biopieces::log_biopiece();
119 Maasha::Biopieces::close_stream( $in );
120 Maasha::Biopieces::close_stream( $out );
122 $run_time_end = Maasha::Biopieces::run_time();
124 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
128 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<