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