How I can store some value in loop?

I

it_says_BALLS_on_your forehead

Rita said:
No you all are giving me code for store data in 1 string or whatever
but my question is not for that, You guys are considering that i
already have value of start and end but I am getting that value from
loop and i want to store in different variable .

see my first posts.
as you all know that in my all programm i have 2 sequences
like
$seq1="AACTGACGACTTTATATACACTAAACTACAATTAAATGGAAGACAGATAATTTAAGAGAAAAAGATTCTTCATATGCATTCTAATTTAGGCAATTTAACATCTAGATCTCGACATAGAGATTGAC";
and
$seq2="CGAGCTGGCAGAGTTCACATGGACAAACAAGGATGCCTGGTTTCTTCATATGCATTCTTGCTGCCCTATACTGTTCAATCCATTCTGCTCAAACCACTATCGTCGACATAGAGATTGACT";

I write both sequences in temperary file called temp1 and temp 2 then
I aligned both sequence using Blast program then i use this code
my $in = Bio::SearchIO ->new(-format => 'blast',
-file => 'temp.blast');
#Print Starting and Ending Point of 1 Hsps-

my $result=$in->next_result;
my $hit =$result->next_hit;

my $hsp1 =$hit->next_hsp;
my$start1=$hsp1->query->start;
my $end1=$hsp1->query->end;

print "start First Hsp ",$start1,"\n";
print "End First Hsp ",$end1,"\n\n";

instead, you would do this:
print "start First Hsp ",$start[0],"\n";
print "End First Hsp ",$end[0],"\n\n";

#Print Starting and Ending Point of 2 Hsps-

my $hsp2 =$hit->next_hsp;
my$start2=$hsp2->query->start;
my $end2=$hsp2->query->end;

print "start Second Hsp ",$start2,"\n";
print "End Second Hsp ",$end2,"\n\n";
print "start Second Hsp ",$start[1],"\n";
print "End Second Hsp ",$end[1],"\n\n";

....or you could start from a 1-indexed array if you so chose. i'm sure
you can figure out how to do that.
 
R

Rita

#Print Starting and Ending Point of 1 Hsps-

my $result=$in->next_result;
my $hit =$result->next_hit;

my $hsp1 =$hit->next_hsp;
my$start1=$hsp1->query->start;
my $end1=$hsp1->query->end;

print "start First Hsp ",$start1,"\n";
print "End First Hsp ",$end1,"\n\n";

instead, you would do this:
print "start First Hsp ",$start[0],"\n";
print "End First Hsp ",$end[0],"\n\n";

#Print Starting and Ending Point of 2 Hsps-

my $hsp2 =$hit->next_hsp;
my$start2=$hsp2->query->start;
my $end2=$hsp2->query->end;

print "start Second Hsp ",$start2,"\n";
print "End Second Hsp ",$end2,"\n\n";
print "start Second Hsp ",$start[1],"\n";
print "End Second Hsp ",$end[1],"\n\n";

...or you could start from a 1-indexed array if you so chose. i'm sure
you can figure out how to do that.

ya thats true i can use array there but in generalization i dont know
Sequence has how many gaps it would be 0 or 1 or 2 or 3 ...
and then how many times i have to write that same codeso I use while loop
while( my $hsp = $hit->next_hsp ) {
and this loop always give me value of start[0] and end[0] not start[1]
,start[2]....
so how i can get that?
 
B

Brian McCauley

Rita said:
I use while loop
while( my $hsp = $hit->next_hsp ) {
and this loop always give me value of start[0] and end[0] not start[1]
,start[2]....
so how i can get that?

It is impossible to tell what you are doing wrong because you have not
shown us the code you are using.

Please post a _minimal_ but _complete_ script that illustrates your
point.
 
B

Brian McCauley

Brian said:
It is impossible to tell what you are doing wrong because you have not
shown us the code you are using.

Please post a _minimal_ but _complete_ script that illustrates your
point.

However, without seeing your code, I can take a random shot in the
dark.

I think you are looking for the push() function.

Read about it in

perldoc -f push

You may also want to get some background on arrays in Perl

perldoc perldata
 
I

it_says_BALLS_on_your forehead

Rita said:
#Print Starting and Ending Point of 1 Hsps-

my $result=$in->next_result;
my $hit =$result->next_hit;

my $hsp1 =$hit->next_hsp;
my$start1=$hsp1->query->start;
my $end1=$hsp1->query->end;

print "start First Hsp ",$start1,"\n";
print "End First Hsp ",$end1,"\n\n";

instead, you would do this:
print "start First Hsp ",$start[0],"\n";
print "End First Hsp ",$end[0],"\n\n";

#Print Starting and Ending Point of 2 Hsps-

my $hsp2 =$hit->next_hsp;
my$start2=$hsp2->query->start;
my $end2=$hsp2->query->end;

print "start Second Hsp ",$start2,"\n";
print "End Second Hsp ",$end2,"\n\n";
print "start Second Hsp ",$start[1],"\n";
print "End Second Hsp ",$end[1],"\n\n";

...or you could start from a 1-indexed array if you so chose. i'm sure
you can figure out how to do that.

ya thats true i can use array there but in generalization i dont know
Sequence has how many gaps it would be 0 or 1 or 2 or 3 ...
and then how many times i have to write that same codeso I use while loop
while( my $hsp = $hit->next_hsp ) {
and this loop always give me value of start[0] and end[0] not start[1]
,start[2]....
so how i can get that?

you never posted code with a while loop before, but to answer your
question:
my $counter = 0;
while( my $hsp = $hit->next_hsp ) {
print "start Second Hsp ",$start[$counter],"\n";
print "End Second Hsp ",$end[$counter],"\n\n";
$counter++;
}

i want to help you rita, since people have helped me in this group
(most notably xho, but others as well--a. sinan unur, paul lalli...to
name a few). but i don't want to encourage your flouting of the posting
rules. please PLEASE post minimal but COMPLETE code, and the results
that you are getting, and the results that you want.
 
R

Rita

it_says_BALLS_on_your forehead said:
Rita said:
#Print Starting and Ending Point of 1 Hsps-

my $result=$in->next_result;
my $hit =$result->next_hit;

my $hsp1 =$hit->next_hsp;
my$start1=$hsp1->query->start;
my $end1=$hsp1->query->end;

print "start First Hsp ",$start1,"\n";
print "End First Hsp ",$end1,"\n\n";


instead, you would do this:
print "start First Hsp ",$start[0],"\n";
print "End First Hsp ",$end[0],"\n\n";


#Print Starting and Ending Point of 2 Hsps-

my $hsp2 =$hit->next_hsp;
my$start2=$hsp2->query->start;
my $end2=$hsp2->query->end;

print "start Second Hsp ",$start2,"\n";
print "End Second Hsp ",$end2,"\n\n";

print "start Second Hsp ",$start[1],"\n";
print "End Second Hsp ",$end[1],"\n\n";

...or you could start from a 1-indexed array if you so chose. i'm sure
you can figure out how to do that.

ya thats true i can use array there but in generalization i dont know
Sequence has how many gaps it would be 0 or 1 or 2 or 3 ...
and then how many times i have to write that same code
my $hsp1 =$hit->next_hsp;
my$start1=$hsp1->query->start;
my $end1=$hsp1->query->end;
so I use while loop
while( my $hsp = $hit->next_hsp ) {
and this loop always give me value of start[0] and end[0] not start[1]
,start[2]....
so how i can get that?

you never posted code with a while loop before, but to answer your
question:
my $counter = 0;
while( my $hsp = $hit->next_hsp ) {
print "start Second Hsp ",$start[$counter],"\n";
print "End Second Hsp ",$end[$counter],"\n\n";
$counter++;
}

yes, This is what I want but I am not sure that how I can explain you.
I tried to get this thing in many post but I didn't get it. Thanks alot
to try to understand me.
I am so glad that evem i am bad poster you help me. I really appritiate
it.
Thanks again.
But problam is that this code is also not workin though I want this
code bcoz i am thinking that it will work but it's not
while( my $hsp = $hit->next_hsp ) {

my @start=$hsp->sbjct->start;
my @end=$hsp->sbjct->end;
my $counter = 0;

print "start ",$start[$counter],"\n";
print "End ",$end[$counter],"\n";

print "Start",$start[0],"\n\n";

$counter++;
}
it's giving me output
start 34
End 267
Start 34

start 1068
End 1248
Satrt 1068

start 824
End 917
Start 824

Here the problam is that every time when It is going in loop it's
storing value of Start[0]and giving me.
But I want that if I Print $start[0] then it give me 34
simillarly $start[1]=1068
and start[2]=824
and for End value so..
 
I

it_says_BALLS_on_your forehead

Rita said:
But problam is that this code is also not workin though I want this
code bcoz i am thinking that it will work but it's not
while( my $hsp = $hit->next_hsp ) {

my @start=$hsp->sbjct->start;
my @end=$hsp->sbjct->end;
my $counter = 0;

print "start ",$start[$counter],"\n";
print "End ",$end[$counter],"\n";

print "Start",$start[0],"\n\n";

$counter++;
}


my ( @start, @end );
my $counter = 0; # this needs to be OUTSIDE the while loop
while( my $hsp = $hit->next_hsp ) {
push @start, $hsp->sbjct->start; # push into array, don't create a
new one
push @end, $hsp->sbjct->end; # push into array, don't create a new
one
print "start ",$start[$counter],"\n";
print "End ",$end[$counter],"\n";
print "Start",$start[0],"\n\n";
$counter++;
}

it's giving me output
start 34
End 267
Start 34

start 1068
End 1248
Satrt 1068

start 824
End 917
Start 824

Here the problam is that every time when It is going in loop it's
storing value of Start[0]and giving me.
But I want that if I Print $start[0] then it give me 34
simillarly $start[1]=1068
and start[2]=824
and for End value so..
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top