Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Script to compute Sum in Sliding Windows

Status
Not open for further replies.

gussifinknottle

Programmer
Jan 16, 2001
19
US
I have a table that has 3 columns

Scaffold Position Pileup
-------- -------- ------
1 1 20
1 2 30
1 3 40
1 …
1 n 40
2 1 11
2 2 14
2 3 16
2 …
2 m 4
3 1 2
3 2 56
3 3 4
3 …
3 p 91

For every scaffold, I would like to be able to get a sum of the Pileup for a sliding window. The sliding window is taken as an input, can be anything between 1000 and 10000.

So for a sliding window of 1000, and for scaffold 1, pileups are to be summed for positions 1-1000, 1001-2000, ...., (n-999)-n. Similarly for scaffold 2, sums for positions 1-1000, 1001-2000, ...., (m-999)-m. Apriori I know what is the total number of positions for each scaffold and this can also be taken as an input if necessary.

Thanks for your help!

Anamika
 
What have you tried?
Where are you stuck?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
A sliding window would mean that you sum up positions 1 to 1000, 2 to 1001, 3 to 1002 and so on. Please clarify your requirements. If you maintain what you said, then confirm that the last group will have less that 1000 elements, in fact any number of elements between 1 and 1000. Also state what should happen when there are less than 1000 elements in the list or exactly 1000 (1000 being of course only taken as an example).
Please also post any piece of code you already wrote, connected with the requested function.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Yes there is a possibility that the last window will not have 1000 (or the window size) elements. In this case, I normalize it for the number of elements in the window. So, if there are 784 elements and the sum S = 9000, then I get the data for the last window as (S/9000)*1000.

Anamika
 
Also, by sliding windows, I mean getting data in non-overlapping contiguous windows. This would mean, data for 1-1000, 1001-2000, 2001-3000 and so on.

Thanks,
Anamika
 
I have to assume at this point you have not written any code, and don't even know where to begin. So I will end my participation in this thread.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Can we simplify this problem, and make it 1-4 instead of 1-1000.
So is this what you want: total = (1+2+3+4) + (2+3+4) + (3+4) + 4?
 
gussifinknottle has a habit of posting questions and never appearing to return to the thread to read replies.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
KevinADC

I have posted about 10 times in the last decade. What basis are you using to make your comments? I do have a life outside of the cyber world and make a trip to the forums on a need only basis.

And when I get a reply for my queries, I have thanked the contributor for the same.

Gussifinknottle
 
Yep, you don't post often, but here ya go:

No replies by you:


This one you replied once but seemed to have abandoned the thread after more replies were posted offering more help:


Does that help clear up any confusion? Most of the threads are pretty old, hopefully you start a new habit of replying to the people that help you. This is my own personal opinion and has nothing to do with tek-tips.

Regards,
Kevin

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top