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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33 use Maasha::Biopieces;
38 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41 my ( $options, $in, $out, $record, $data_in, $num, $entry, $records, $soft_index,
42 $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip, $file );
44 $options = Maasha::Biopieces::parse_options(
46 { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
47 { long => 'samples', short => 's', type => 'list', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
48 { long => 'num', short => 'n', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => '0' },
52 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
53 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
55 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
56 Maasha::Biopieces::put_record( $record, $out );
61 foreach $file ( @{ $options->{ "data_in" } } )
63 print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
65 $soft_index = Maasha::NCBI::soft_index_file( $file );
67 # print STDERR Dumper( $soft_index ) if $options->{ "verbose" };
69 $fh = Maasha::Filesys::file_read_open( $file );
71 @platforms = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
73 print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
75 $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
77 @samples = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
79 $old_end = $platforms[ -1 ]->{ "LINE_END" };
81 foreach $sample ( @samples )
84 $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
86 print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
88 $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
90 foreach $record ( @{ $records } )
92 Maasha::Biopieces::put_record( $record, $out );
94 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
99 $old_end = $sample->{ "LINE_END" };
107 close $data_in if $data_in;
110 Maasha::Biopieces::close_stream( $in );
111 Maasha::Biopieces::close_stream( $out );
114 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
119 Maasha::Biopieces::status_set();
125 Maasha::Biopieces::status_log();
129 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<