| 1 | # | ||||||||||
| 2 | # BioPerl module for Bio::Tools::Blat | ||||||||||
| 3 | # | ||||||||||
| 4 | # Written by Balamurugan Kumarasamy | ||||||||||
| 5 | # | ||||||||||
| 6 | # You may distribute this module under the same terms as perl itself | ||||||||||
| 7 | # | ||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Bio::Tools::Blat - parser for Blat program | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | use Bio::Tools::Blat; | ||||||||||
| 16 | my $blat_parser = Bio::Tools::Blat->new(-fh =>$filehandle ); | ||||||||||
| 17 | while( my $blat_feat = $blat_parser->next_result ) { | ||||||||||
| 18 | push @blat_feat, $blat_feat; | ||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | Parser for Blat program | ||||||||||
| 24 | |||||||||||
| 25 | =head1 FEEDBACK | ||||||||||
| 26 | |||||||||||
| 27 | =head2 Mailing Lists | ||||||||||
| 28 | |||||||||||
| 29 | User feedback is an integral part of the evolution of this and other | ||||||||||
| 30 | Bioperl modules. Send your comments and suggestions preferably to | ||||||||||
| 31 | the Bioperl mailing list. Your participation is much appreciated. | ||||||||||
| 32 | |||||||||||
| 33 | bioperl-l@bioperl.org - General discussion | ||||||||||
| 34 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||
| 35 | |||||||||||
| 36 | =head2 Support | ||||||||||
| 37 | |||||||||||
| 38 | Please direct usage questions or support issues to the mailing list: | ||||||||||
| 39 | |||||||||||
| 40 | I<bioperl-l@bioperl.org> | ||||||||||
| 41 | |||||||||||
| 42 | rather than to the module maintainer directly. Many experienced and | ||||||||||
| 43 | reponsive experts will be able look at the problem and quickly | ||||||||||
| 44 | address it. Please include a thorough description of the problem | ||||||||||
| 45 | with code and data examples if at all possible. | ||||||||||
| 46 | |||||||||||
| 47 | =head2 Reporting Bugs | ||||||||||
| 48 | |||||||||||
| 49 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||
| 50 | of the bugs and their resolution. Bug reports can be submitted the | ||||||||||
| 51 | web: | ||||||||||
| 52 | |||||||||||
| 53 | https://github.com/bioperl/bioperl-live/issues | ||||||||||
| 54 | |||||||||||
| 55 | =head1 AUTHOR - Balamurugan Kumarasamy | ||||||||||
| 56 | |||||||||||
| 57 | Email: bala@tll.org.sg | ||||||||||
| 58 | |||||||||||
| 59 | =head1 APPENDIX | ||||||||||
| 60 | |||||||||||
| 61 | The rest of the documentation details each of the object methods. | ||||||||||
| 62 | Internal methods are usually preceded with a _ | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | package Bio::Tools::Blat; | ||||||||||
| 67 | 1 | $Bio::Tools::Blat::VERSION = '1.7.8'; | |||||||||
| 68 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 1 | ▶ | use Bio::SeqFeature::Generic; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | ▶ | use Bio::SeqFeature::FeaturePair; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 71 | 1 | ▶ | use Bio::SeqFeature::Generic; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 72 | 1 | ▶ | use base qw(Bio::Root::Root Bio::Root::IO); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 73 | |||||||||||
| 74 | =head2 new | ||||||||||
| 75 | |||||||||||
| 76 | Title : new | ||||||||||
| 77 | Usage : my $obj = Bio::Tools::Blat->new(-fh=>$filehandle); | ||||||||||
| 78 | Function: Builds a new Bio::Tools::Blat object | ||||||||||
| 79 | Returns : Bio::Tools::Blat | ||||||||||
| 80 | Args : -filename | ||||||||||
| 81 | -fh (filehandle) | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | my($class,@args) = @_; | |||||||||
| 87 | |||||||||||
| 88 | 0 | my $self = $class->SUPER::new(@args); | |||||||||
| 89 | 0 | $self->_initialize_io(@args); | |||||||||
| 90 | |||||||||||
| 91 | 0 | return $self; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | =head2 next_result | ||||||||||
| 95 | |||||||||||
| 96 | Title : next_result | ||||||||||
| 97 | Usage : my $feat = $blat_parser->next_result | ||||||||||
| 98 | Function: Get the next result set from parser data | ||||||||||
| 99 | Returns : L<Bio::SeqFeature::Generic> | ||||||||||
| 100 | Args : none | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub next_result { | ||||||||
|
Subroutine
next_result: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 105 | 0 | my ($self) = @_; | |||||||||
| 106 | 0 | my $filehandle; | |||||||||
| 107 | my $line; | ||||||||||
| 108 | 0 | my $id; | |||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | while ($_=$self->_readline()){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | # first split on spaces: | ||||||||||
| 112 | 0 | $line = $_; | |||||||||
| 113 | 0 | chomp $line; | |||||||||
| 114 | |||||||||||
| 115 | 0 | my ($matches, $mismatches, $rep_matches, $n_count, $q_num_insert, | |||||||||
| 116 | $q_base_insert, $t_num_insert, $t_base_insert, $strand, $q_name, | ||||||||||
| 117 | $q_length, $q_start, $q_end, $t_name, $t_length, | ||||||||||
| 118 | $t_start, $t_end, $block_count, $block_sizes, $q_starts, | ||||||||||
| 119 | $t_starts | ||||||||||
| 120 | ) = split; | ||||||||||
| 121 | |||||||||||
| 122 | 0 | my $superfeature = Bio::SeqFeature::Generic->new(); | |||||||||
| 123 | |||||||||||
| 124 | # ignore any preceeding text | ||||||||||
| 125 | 0 | ▶ | next unless ( $matches =~/^\d+$/ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | |||||||||||
| 127 | # create as many features as blocks there are in each output line | ||||||||||
| 128 | 0 | my (%feat1, %feat2); | |||||||||
| 129 | 0 | $feat1{name} = $t_name; | |||||||||
| 130 | 0 | $feat2{name} = $q_name; | |||||||||
| 131 | |||||||||||
| 132 | 0 | ▶ | $strand = $1 if ($strand =~/([+-])[+-]/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | |||||||||||
| 134 | 0 | $feat2{strand} = 1; | |||||||||
| 135 | 0 | $feat1{strand} = $strand; | |||||||||
| 136 | |||||||||||
| 137 | 0 | my $percent_id = sprintf "%.2f", | |||||||||
| 138 | (100 * ($matches + $rep_matches)/( $matches + $mismatches + $rep_matches)); | ||||||||||
| 139 | |||||||||||
| 140 | 0 | ▶ | unless ( $q_length ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 0 | $self->warn("length of query is zero, something is wrong!"); | |||||||||
| 142 | 0 | next; | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 0 | my $score = sprintf "%.2f", | |||||||||
| 146 | (100 * ( $matches + $mismatches + $rep_matches ) / $q_length); | ||||||||||
| 147 | |||||||||||
| 148 | # size of each block of alignment (inclusive) | ||||||||||
| 149 | 0 | my @block_sizes = split ",",$block_sizes; | |||||||||
| 150 | |||||||||||
| 151 | # start position of each block (you must add 1 as psl output | ||||||||||
| 152 | # is off by one in the start coordinate) | ||||||||||
| 153 | 0 | my @q_start_positions = split ",",$q_starts; | |||||||||
| 154 | 0 | my @t_start_positions = split ",",$t_starts; | |||||||||
| 155 | |||||||||||
| 156 | 0 | $superfeature->seq_id($q_name); | |||||||||
| 157 | 0 | $superfeature->score( $score ); | |||||||||
| 158 | 0 | $superfeature->add_tag_value('percent_id',$percent_id); | |||||||||
| 159 | |||||||||||
| 160 | # each line of output represents one possible entire aligment | ||||||||||
| 161 | # of the query (feat1) and the target(feat2) | ||||||||||
| 162 | |||||||||||
| 163 | 0 | ▶ | for (my $i=0; $i<$block_count; $i++ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | |||||||||||
| 165 | 0 | my ($query_start,$query_end); | |||||||||
| 166 | |||||||||||
| 167 | 0 | ▶ | if ( $strand eq '+' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 168 | 0 | $query_start = $q_start_positions[$i] + 1; | |||||||||
| 169 | 0 | $query_end = $query_start + $block_sizes[$i] - 1; | |||||||||
| 170 | }else{ | ||||||||||
| 171 | 0 | $query_end = $q_length - $q_start_positions[$i]; | |||||||||
| 172 | 0 | $query_start = $query_end - $block_sizes[$i] + 1; | |||||||||
| 173 | } | ||||||||||
| 174 | |||||||||||
| 175 | #$feat2 {start} = $q_start_positions[$i] + 1; | ||||||||||
| 176 | #$feat2 {end} = $feat2{start} + $block_sizes[$i] - 1; | ||||||||||
| 177 | 0 | $feat2 {start} = $query_start; | |||||||||
| 178 | 0 | $feat2 {end} = $query_end; | |||||||||
| 179 | 0 | ▶ | if ( $query_end < $query_start ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 180 | 0 | $self->warn("dodgy feature coordinates: end = $query_end, start = $query_start. Reversing..."); | |||||||||
| 181 | 0 | $feat2 {end} = $query_start; | |||||||||
| 182 | 0 | $feat2 {start} = $query_end; | |||||||||
| 183 | } | ||||||||||
| 184 | |||||||||||
| 185 | 0 | $feat1 {start} = $t_start_positions[$i] + 1; | |||||||||
| 186 | 0 | $feat1 {end} = $feat1{start} + $block_sizes[$i] - 1; | |||||||||
| 187 | |||||||||||
| 188 | # we put all the features with the same score and percent_id | ||||||||||
| 189 | 0 | $feat2 {score} = $score; | |||||||||
| 190 | 0 | $feat1 {score} = $feat2 {score}; | |||||||||
| 191 | 0 | $feat2 {percent} = $percent_id; | |||||||||
| 192 | 0 | $feat1 {percent} = $feat2 {percent}; | |||||||||
| 193 | |||||||||||
| 194 | # other stuff: | ||||||||||
| 195 | 0 | $feat1 {db} = undef; | |||||||||
| 196 | 0 | $feat1 {db_version} = undef; | |||||||||
| 197 | 0 | $feat1 {program} = 'blat'; | |||||||||
| 198 | 0 | $feat1 {p_version} = '1'; | |||||||||
| 199 | 0 | $feat1 {source} = 'blat'; | |||||||||
| 200 | 0 | $feat1 {primary} = 'similarity'; | |||||||||
| 201 | 0 | $feat2 {source} = 'blat'; | |||||||||
| 202 | 0 | $feat2 {primary} = 'similarity'; | |||||||||
| 203 | |||||||||||
| 204 | 0 | my $feature_pair = $self->create_feature(\%feat1, \%feat2); | |||||||||
| 205 | 0 | $superfeature->add_sub_SeqFeature( $feature_pair,'EXPAND'); | |||||||||
| 206 | } | ||||||||||
| 207 | 0 | return $superfeature; | |||||||||
| 208 | } | ||||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | =head2 create_feature | ||||||||||
| 212 | |||||||||||
| 213 | Title : create_feature | ||||||||||
| 214 | Usage : my $feat=$blat_parser->create_feature($feature,$seqname) | ||||||||||
| 215 | Function: creates a SeqFeature Generic object | ||||||||||
| 216 | Returns : L<Bio::SeqFeature::Generic> | ||||||||||
| 217 | Args : | ||||||||||
| 218 | |||||||||||
| 219 | |||||||||||
| 220 | =cut | ||||||||||
| 221 | |||||||||||
| 222 | 0 | ▶ | sub create_feature { | ||||||||
|
Subroutine
create_feature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 223 | 0 | my ($self, $feat1,$feat2) = @_; | |||||||||
| 224 | my $feature1= Bio::SeqFeature::Generic->new( | ||||||||||
| 225 | -seq_id =>$feat1->{name}, | ||||||||||
| 226 | -start =>$feat1->{start}, | ||||||||||
| 227 | -end =>$feat1->{end}, | ||||||||||
| 228 | -strand =>$feat1->{strand}, | ||||||||||
| 229 | -score =>$feat1->{score}, | ||||||||||
| 230 | -source =>$feat1->{source}, | ||||||||||
| 231 | 0 | -primary =>$feat1->{primary} ); | |||||||||
| 232 | |||||||||||
| 233 | my $feature2= Bio::SeqFeature::Generic->new( | ||||||||||
| 234 | -seq_id =>$feat2->{name}, | ||||||||||
| 235 | -start =>$feat2->{start}, | ||||||||||
| 236 | -end =>$feat2->{end}, | ||||||||||
| 237 | -strand =>$feat2->{strand}, | ||||||||||
| 238 | -score =>$feat2->{score}, | ||||||||||
| 239 | -source =>$feat2->{source}, | ||||||||||
| 240 | 0 | -primary =>$feat2->{primary} ); | |||||||||
| 241 | |||||||||||
| 242 | 0 | my $featurepair = Bio::SeqFeature::FeaturePair->new; | |||||||||
| 243 | 0 | $featurepair->feature1 ($feature1); | |||||||||
| 244 | 0 | $featurepair->feature2 ($feature2); | |||||||||
| 245 | |||||||||||
| 246 | 0 | $featurepair->add_tag_value('evalue',$feat2->{p}); | |||||||||
| 247 | 0 | $featurepair->add_tag_value('percent_id',$feat2->{percent}); | |||||||||
| 248 | 0 | $featurepair->add_tag_value("hid",$feat2->{primary}); | |||||||||
| 249 | 0 | return $featurepair; | |||||||||
| 250 | } | ||||||||||
| 251 | |||||||||||
| 252 | 1 | 1; | |||||||||