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 # Plot chromosome distribution histogram.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 use Maasha::Biopieces;
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
40 my ( $run_time_beg, $run_time_end, $options, $in, $out, $default, $terminals, $phastcons_file, $phastcons_index,
41 $index, $fh_phastcons, $record, $scores, $AoA, $plot, $fh, $tmp_dir );
43 $default = "PhastCons Profiles";
44 $terminals = "dumb,x11,aqua,post,svg";
46 $options = Maasha::Biopieces::parse_options(
48 { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
49 { long => 'data_out', short => 'o', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
50 { long => 'genome', short => 'g', type => 'genome', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
51 { long => 'mean', short => 'm', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
52 { long => 'median', short => 'M', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
53 { long => 'flank', short => 'f', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
54 { long => 'terminal', short => 't', type => 'string', mandatory => 'no', default => 'dumb', allowed => $terminals, disallowed => undef },
55 { long => 'title', short => 'T', type => 'string', mandatory => 'no', default => $default, allowed => undef, disallowed => undef },
56 { long => 'xlabel', short => 'X', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
57 { long => 'ylabel', short => 'Y', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
61 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
62 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
64 $phastcons_file = Maasha::Config::genome_phastcons( $options->{ "genome" } );
65 $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
67 $index = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
68 $fh_phastcons = Maasha::Filesys::file_read_open( $phastcons_file );
70 while ( $record = Maasha::Biopieces::get_record( $in ) )
72 if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
74 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" },
75 $record->{ "CHR_BEG" },
76 $record->{ "CHR_END" },
77 $options->{ "flank" } );
79 push @{ $AoA }, [ @{ $scores } ];
82 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
85 Maasha::UCSC::phastcons_normalize( $AoA );
87 $AoA = [ [ Maasha::UCSC::phastcons_mean( $AoA ) ] ] if $options->{ "mean" };
88 $AoA = [ [ Maasha::UCSC::phastcons_median( $AoA ) ] ] if $options->{ "median" };
90 $AoA = Maasha::Matrix::matrix_flip( $AoA );
92 $tmp_dir = Maasha::Biopieces::get_tmpdir();
94 $plot = Maasha::Plot::lineplot_simple( $AoA, $options, $tmp_dir );
96 $fh = Maasha::Biopieces::write_stream( $options->{ "data_out" } );
98 print $fh "$_\n" foreach @{ $plot };
102 Maasha::Filesys::dir_remove( $tmp_dir );
105 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
110 $run_time_beg = Maasha::Biopieces::run_time();
112 Maasha::Biopieces::log_biopiece();
118 Maasha::Biopieces::close_stream( $in );
119 Maasha::Biopieces::close_stream( $out );
121 $run_time_end = Maasha::Biopieces::run_time();
123 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
127 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<