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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 use Maasha::Biopieces;
35 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38 my ( $options, $in, $out, $record, $tmp_dir, $maf_track, $align, $align_num, $beg, $end, $len, $entry );
40 $options = Maasha::Biopieces::parse_options(
42 { long => 'genome', short => 'g', type => 'genome', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
43 { long => 'chr', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
44 { long => 'beg', short => 'b', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
45 { long => 'end', short => 'e', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
46 { long => 'len', short => 'l', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => 0 },
47 { long => 'strand', short => 's', type => 'string', mandatory => 'no', default => '+', allowed => '+,-', disallowed => undef },
51 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
52 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
54 $tmp_dir = Maasha::Biopieces::get_tmpdir();
58 $maf_track = maf_track( $options->{ "genome" } );
60 if ( $options->{ "chr" } and $options->{ "beg" } and ( $options->{ "end" } or $options->{ "len" } ) )
62 $beg = $options->{ "beg" } - 1;
64 if ( $options->{ "end" } ) {
65 $end = $options->{ "end" };
66 } elsif ( $options->{ "len" } ) {
67 $end = $beg + $options->{ "len" };
70 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $options->{ "chr" }, $beg, $end, $options->{ "strand" } );
72 foreach $entry ( @{ $align } )
74 $entry->{ "CHR" } = $record->{ "CHR" };
75 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
76 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
77 $entry->{ "STRAND" } = $record->{ "STRAND" } || '+';
78 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
79 $entry->{ "SCORE" } = $record->{ "SCORE" };
81 Maasha::Biopieces::put_record( $entry, $out );
85 while ( $record = Maasha::Biopieces::get_record( $in ) )
87 if ( $record->{ "REC_TYPE" } eq "BED" )
89 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $record->{ "STRAND" } );
91 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" )
93 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" } + 1, $record->{ "STRAND" } );
95 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
97 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
99 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
101 $align = Maasha::UCSC::maf_extract( $tmp_dir, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
104 foreach $entry ( @{ $align } )
106 $entry->{ "CHR" } = $record->{ "CHR" };
107 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
108 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
109 $entry->{ "STRAND" } = $record->{ "STRAND" };
110 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
111 $entry->{ "SCORE" } = $record->{ "SCORE" };
113 Maasha::Biopieces::put_record( $entry, $out );
119 Maasha::Biopieces::close_stream( $in );
120 Maasha::Biopieces::close_stream( $out );
123 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
128 # Martin A. Hansen, April 2008.
130 # Given a genome returns the corresponding mafTrack database table name.
132 my ( $genome, # genome to lookup.
139 # The below has should be in a config file - fix later.
142 danRer4 => 'multiz7way',
143 dm2 => 'multiz15way',
144 dm3 => 'multiz15way',
146 galGal3 => 'multiz7way',
147 gasAcu1 => 'multiz7way',
148 hg18 => 'multiz17way',
149 mm8 => 'multiz17way',
150 mm9 => 'multiz17way',
151 oryLat1 => 'multiz7way',
152 panTro2 => 'multiz17way',
153 tetNig1 => 'multiz7way',
156 Maasha::Common::error( qw(multiz track not found) ) if not exists $hash{ $genome };
158 return $hash{ $genome };
162 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
167 Maasha::Biopieces::status_set();
173 Maasha::Biopieces::status_log();
177 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<