problam in subroutine?

R

Rita

Hi All,
I am making 1 subroutine and it is working too but it doesn't giving me
all the values just giving me first value .
my subroutinr is-

sub Sequence {
my ($filename1)=@_;
my $in2 = Bio::SearchIO ->new(-format => 'blast',
-file => $filename1);
while( my $result2 = $in2->next_result){
while(my $hit2 = $result2->next_hit ){
while(my $hsp2 = $hit2->next_hsp){

#Print Sequence 1Name and Start of End Point where it is matching:
my $query2= $result2->query_name;
print "QUERY = $query2\t\t";
my ($query_beg1, $query_end1) = $hsp2->range('query');
print "(Start,End)=($query_beg1,$query_end1)\n";

#Print Sequence2 Name and Start of End Point where it is matching:
my $hit_name2= $hit2->name;
print "Hit =$hit_name2\t\t ";
my ($hit_beg1, $hit_end1) = $hsp2->range('hit2');
print "(Start,End)=($hit_beg1,$hit_end1)\n";

#Print Matching Sequence:
my $str2 = $hsp2->seq_str('match');
return ($str2);
}
}
}

}
and my main program's code is
my $filename1='xyz.blast';
my $str =Sequence($filename1);
print ("Match SEQUENCE-\n $str\n\n");

I tried while loop but that giving me same value all time in loop.
can i doing any mistake somewhere?
Thanks.
 
M

Matt Garrish

Rita said:
Hi All,
I am making 1 subroutine and it is working too but it doesn't giving me
all the values just giving me first value .
my subroutinr is-

sub Sequence {
my ($filename1)=@_;
my $in2 = Bio::SearchIO ->new(-format => 'blast',
-file => $filename1);
while( my $result2 = $in2->next_result){
while(my $hit2 = $result2->next_hit ){
while(my $hsp2 = $hit2->next_hsp){

#Print Sequence 1Name and Start of End Point where it is matching:
my $query2= $result2->query_name;
print "QUERY = $query2\t\t";
my ($query_beg1, $query_end1) = $hsp2->range('query');
print "(Start,End)=($query_beg1,$query_end1)\n";

#Print Sequence2 Name and Start of End Point where it is matching:
my $hit_name2= $hit2->name;
print "Hit =$hit_name2\t\t ";
my ($hit_beg1, $hit_end1) = $hsp2->range('hit2');
print "(Start,End)=($hit_beg1,$hit_end1)\n";

#Print Matching Sequence:
my $str2 = $hsp2->seq_str('match');
return ($str2);

I'm not sure I entirely understand your problem, but would this be the
culprit? You set up the while loops, but as soon as a match is found the
subroutine returns $str2. It's not going to keep returning values, if that's
what you're thinking. Instead of returning $str2, why not push it onto an
array and then return the array once all the while loops have completed? For
example:

my $aref = Sequence($filename);

foreach (@{$aref) {
print ("Match SEQUENCE-\n $_\n\n");
}

sub Sequence {
my @match;
while (...) {
push @matcht, $str2;
}
return \@match;
}


Again, it's difficult to undestand what part of the script you are referring
to, so my apologies if I'm just stating the obvious.

Matt
 
R

Rita

Matt said:
I'm not sure I entirely understand your problem, but would this be the
culprit? You set up the while loops, but as soon as a match is found the
subroutine returns $str2. It's not going to keep returning values, if that's
what you're thinking. Instead of returning $str2, why not push it onto an
array and then return the array once all the while loops have completed? For
example:

my $aref = Sequence($filename);

foreach (@{$aref) {
print ("Match SEQUENCE-\n $_\n\n");
}

sub Sequence {
my @match;
while (...) {
push @matcht, $str2;
}
return \@match;
}


Again, it's difficult to undestand what part of the script you are referring
to, so my apologies if I'm just stating the obvious.
No, I think you are right i have to collect all values.
I am just thiking that there will be some way you can get all values
from subrotine.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

problam in nesting loop 1
loop ? 22
subroutine 8
moving a match into a subroutine 3
Subroutine on Mutation of Codons 7
Translater + module + tkinter 1
cubic root subroutine 20
Python battle game help 2

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top