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 alignments from a multiple genome alignment.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 use Maasha::Biopieces;
36 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
39 my ( $options, $in, $out, $record, $tmp_dir, $maf_track, $align, $align_num, $beg, $end, $len, $entry );
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 => 'strand', short => 's', type => 'string', mandatory => 'no', default => '+', allowed => '+,-', disallowed => undef },
52 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
53 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
55 $tmp_dir = Maasha::Biopieces::get_tmpdir();
59 $maf_track = maf_track( $options->{ "genome" } );
61 if ( $options->{ "chr" } and $options->{ "beg" } and ( $options->{ "end" } or $options->{ "len" } ) )
63 $beg = $options->{ "beg" } - 1;
65 if ( $options->{ "end" } ) {
66 $end = $options->{ "end" };
67 } elsif ( $options->{ "len" } ) {
68 $end = $beg + $options->{ "len" };
71 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $options->{ "chr" }, $beg, $end, $options->{ "strand" } );
73 foreach $entry ( @{ $align } )
75 $entry->{ "CHR" } = $record->{ "CHR" };
76 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
77 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
78 $entry->{ "STRAND" } = $record->{ "STRAND" } || '+';
79 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
80 $entry->{ "SCORE" } = $record->{ "SCORE" };
82 Maasha::Biopieces::put_record( $entry, $out );
86 while ( $record = Maasha::Biopieces::get_record( $in ) )
88 if ( $record->{ "REC_TYPE" } eq "BED" )
90 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $record->{ "STRAND" } );
92 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" )
94 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" } + 1, $record->{ "STRAND" } );
96 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
98 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
100 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
102 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
105 foreach $entry ( @{ $align } )
107 $entry->{ "CHR" } = $record->{ "CHR" };
108 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
109 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
110 $entry->{ "STRAND" } = $record->{ "STRAND" };
111 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
112 $entry->{ "SCORE" } = $record->{ "SCORE" };
114 Maasha::Biopieces::put_record( $entry, $out );
120 Maasha::Biopieces::close_stream( $in );
121 Maasha::Biopieces::close_stream( $out );
124 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
129 # Martin A. Hansen, April 2008.
131 # Given a genome returns the corresponding mafTrack database table name.
133 my ( $genome, # genome to lookup.
140 # The below has should be in a config file - fix later.
143 danRer4 => 'multiz7way',
144 dm2 => 'multiz15way',
145 dm3 => 'multiz15way',
147 galGal3 => 'multiz7way',
148 gasAcu1 => 'multiz7way',
149 hg18 => 'multiz17way',
150 mm8 => 'multiz17way',
151 mm9 => 'multiz17way',
152 oryLat1 => 'multiz7way',
153 panTro2 => 'multiz17way',
154 tetNig1 => 'multiz7way',
157 Maasha::Common::error( qw(multiz track not found) ) if not exists $hash{ $genome };
159 return $hash{ $genome };
163 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
168 Maasha::Biopieces::status_set();
174 Maasha::Biopieces::status_log();
178 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<