problam in subroutine?

Discussion in 'Perl Misc' started by Rita, Dec 5, 2005.

  1. Rita

    Rita Guest

    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.
     
    Rita, Dec 5, 2005
    #1
    1. Advertising

  2. Rita

    Matt Garrish Guest

    "Rita" <> wrote in message
    news:...
    > 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
     
    Matt Garrish, Dec 5, 2005
    #2
    1. Advertising

  3. Rita

    Rita Guest

    Matt Garrish wrote:
    > "Rita" <> wrote in message
    > news:...
    > > 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.

    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
     
    Rita, Dec 6, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey
    Replies:
    3
    Views:
    866
    Casey
    Jan 30, 2004
  2. Hon Seng Phuah
    Replies:
    1
    Views:
    483
    J├╝rgen Exner
    Mar 5, 2004
  3. Rita

    problam in nesting loop

    Rita, Nov 18, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    108
  4. Rita

    Problam in extract data

    Rita, Dec 14, 2005, in forum: Perl Misc
    Replies:
    18
    Views:
    175
    Tad McClellan
    Dec 16, 2005
  5. king
    Replies:
    5
    Views:
    204
Loading...

Share This Page