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 # Extract phastcons scores from a specified genome.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
33 use Maasha::UCSC::Wiggle;
36 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 my ( $options, $in, $out, $phastcons_file, $phastcons_index, $index, $fh_phastcons, $scores, $record );
41 $options = Maasha::Biopieces::parse_options(
43 { long => 'genome', short => 'g', type => 'genome', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
44 { long => 'chr', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
45 { long => 'beg', short => 'b', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
46 { long => 'end', short => 'e', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
47 { long => 'len', short => 'l', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
48 { long => 'flank', short => 'f', type => 'uint', mandatory => 'no', default => 0, allowed => undef, disallowed => undef },
52 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
53 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
55 $phastcons_file = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/phastcons/$options->{ 'genome' }.pp";
56 $phastcons_index = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/phastcons/$options->{ 'genome' }.pp.index";
58 $index = Maasha::UCSC::Wiggle::fixedstep_index_retrieve( $phastcons_index );
59 $fh_phastcons = Maasha::Filesys::file_read_open( $phastcons_file );
61 if ( defined $options->{ "chr" } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) )
63 $options->{ "beg" } -= 1; # request is 1-based
64 $options->{ "end" } -= 1; # request is 1-based
66 if ( $options->{ "len" } ) {
67 $options->{ "end" } = $options->{ "beg" } + $options->{ "len" } - 1;
70 $scores = Maasha::UCSC::Wiggle::fixedstep_index_lookup( $index, $fh_phastcons, $options->{ "chr" }, $options->{ "beg" }, $options->{ "end" }, $options->{ "flank" } );
72 $record->{ "CHR" } = $options->{ "chr" };
73 $record->{ "CHR_BEG" } = $options->{ "beg" } - $options->{ "flank" };
74 $record->{ "CHR_END" } = $options->{ "end" } + $options->{ "flank" };
76 $record->{ "PHASTCONS" } = join ",", @{ $scores };
77 $record->{ "PHAST_COUNT" } = scalar @{ $scores }; # DEBUG
79 Maasha::Biopieces::put_record( $record, $out );
82 while ( $record = Maasha::Biopieces::get_record( $in ) )
84 if ( $record->{ "REC_TYPE" } eq "BED" )
86 $scores = Maasha::UCSC::Wiggle::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "flank" } );
88 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
90 $scores = Maasha::UCSC::Wiggle::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
92 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
94 $scores = Maasha::UCSC::Wiggle::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
97 $record->{ "PHASTCONS" } = join ",", @{ $scores } if @{ $scores };
98 # $record->{ "PHAST_COUNT" } = @{ $scores } if @{ $scores }; # DEBUG
100 Maasha::Biopieces::put_record( $record, $out );
103 close $fh_phastcons if $fh_phastcons;
105 Maasha::Biopieces::close_stream( $in );
106 Maasha::Biopieces::close_stream( $out );
109 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
114 Maasha::Biopieces::status_set();
120 Maasha::Biopieces::status_log();
124 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<