# Working with iterations (CrossMatch results)
my $searchIO = Bio::SearchIO->new( -format => 'cross_match',
-file => "$file.screen.out" )
while(my $r = $searchIO->next_result) {
while(my $hit = $r->next_hit) {
while(my $hsp = $hit->next_hsp) {
#Do the processing here.
}
}
}
# See Bio::SearchIO for information about working with Results.
# See
Bio::SearchIO# for details about working with Bio::SearchIO.
sub next_result
{ my ($self) = @_;
my $start = 0;
while( defined ($_ = $self->_readline )) {
return if($self->{'_end_document'});
if(/^cross_match version\s+(.*?)$/) {
$self->{_algorithm_version} = $1;
} elsif(/^Maximal single base matches/) {
$start = 1;
} elsif(/^(\d+) matching entries/) {
$self->{'_end_document'} = 1;
return;
} elsif(($start || $self->{'_result_count'}) && /^\s+(\d+)/xms) {
$self->{'_result_count'}++;
return $self->_parse($_);
} elsif(! $self->{_parameters}) {
if(/.*?\s+(\-.*?)$/) {
my $p = $1;
my @pp = split /\s+/, $p;
for(my $i = 0; $i < @pp; $i ++) {
if($pp[$i] =~ /^\-/) {
if($pp[$i + 1] && $pp[$i + 1] !~ /^\-/) {
$self->{_parameters}->{$pp[$i]} = $pp[$i + 1];
$i ++;
} else {
$self->{_parameters}->{$pp[$i]} = "";
}
}
}
}
} elsif(/^Query file(s):\s+(.*?)$/) {
$self->{_query_name} = $1;
} elsif(/^Subject file(s):\s+(.*?)$/) {
$self->{_subject_name} = $2;
}
}} |
sub _alignment
{ my $self = shift;
my $blank = $self->_readline;
unless($blank =~ /^\s*$/) {
return;
}
my @data;
my @pad;
$count = 0;
while( defined ($_ = $self->_readline )) {
$count = 0 if($count >= 3);
next if(/^$/);
if(/^(C \S+.*?\d+ )(\S+) \d+$|^( \S+.*?\d+ )(\S+) \d+$$|^\s+$/) {
$count ++;
if($1 || $3) {
$pad[$count] = $1 ? $1 : $3;
push @{$data[$count]}, ($2 ? $2 : $4);
} else {
if(/\s{$pad[0],$pad[0]}(.*?)$/) {
push @{$data[$count]}, $1;
} else {
$self->throw("Format error for the homology line [$_].");
}
}
} else {
last;
}
}
return @data; } |
sub _parse
{ my $self = shift;
my $line = shift;
my $is_alignment = 0;
my($hit_seq, $homology_seq, $query_seq);
$line =~ s/^\s+|\s+$//g;
my @r = split /\s+/, $line;
if($r[0] eq "ALIGNMENT") {
$is_alignment = 1;
shift @r;
($hit_seq, $homology_seq, $query_seq) = $self->_alignment();
}
my $subject_seq_id;
my $query_seq_id = $r[4];
my $query_start = $r[5];
my $query_end = $r[6];
my $is_complement = 0;
my $subject_start;
my $subject_end;
if($r[8] eq "C" && $r[9] !~ /^\(\d+\)$/) {
$subject_seq_id = $r[9];
$is_complement = 1;
$subject_start = $r[11];
$subject_end = $r[12];
} else {
$subject_seq_id = $r[8];
$subject_start = $r[9];
$subject_end = $r[10];
}
my $hit = Bio::Search::Hit::GenericHit->new(-name => $subject_seq_id,
-hsps => [Bio::Search::HSP::GenericHSP->new(-query_name => $query_seq_id,
-query_start => $query_start,
-query_end => $query_end,
-hit_name => $subject_seq_id,
-hit_start => $subject_start,
-hit_end => $subject_end,
-query_length => 0,
-hit_length => 0,
-identical => $r[0],
-conserved => $r[0],
-query_seq => $query_seq ? (join "", @$query_seq) : "", -hit_seq => $hit_seq ? (join "", @$hit_seq) : "", -homology_seq=> $homology_seq ? (join "", @$homology_seq) : "", -algorithm => 'SW',)],
);
my $result = Bio::Search::Result::CrossMatchResult->new( -query_name => $self->{_query_name},
-query_accession => '',
-query_description => '',
-query_length => 0,
-database_name => $self->{_subject_name},
-database_letters => 0,
-database_entries => 0,
-parameters => $self->{_parameters},
-statistics => { },
-algorithm => 'cross_match',
-algorithm_version => $self->{_algorithm_version},
);
$result->add_hit($hit);
return $result; } |
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _