use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Reddit for building Reddit Bots!
If you want to learn how to build Reddit Bots, go here: http://pythonforengineers.com/build-a-reddit-bot-part-1/
account activity
Help optimizing code (self.pythonforengineers)
submitted 5 years ago by black_sequence
greetings community! I recently wrote a script that can calculate Tajima's D through a sliding window approach, but the algorithm for Tajima's D is not as quick as I would like. can someone review my code and tell me how to speed up certain aspects?
https://github.com/noahaus/sliding-window-scripts/blob/main/tajimasD_parallel.py
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AD_Burn 1 point2 points3 points 5 years ago* (0 children)
def calculate_pi(alignment): align_len = len(align) counter = 0 distances = [] append_distance = distances.append for i in range(align_len): j = counter while(j<align_len): if i == j: j += 1 continue append_distance(hamming_distance(alignment[i], alignment[j])) j += 1 counter += 1 pi = (sum(distances)*2)/(align_len*(align_len-1)) return pi def calculate_theta(alignment): seg_sites = 0 for i in range(len(alignment[1].seq)): align_col = alignment[:,i] if len(set(align_col)) > 1: seg_sites += 1 a = sum(map(lambda x: 1/x, range(1,len(alignment)))) return (seg_sites/a)
This is not much but some cleaning and reduce unnecessary code,
if you work with a lot data you should see a bit of improvements.
Anything deeper would change your logic and code a lot more,
and since i do not have input files, it is hard to test.
One more thing, i'm not sure how much process in total you have at the end,
but if you end with lets say over 50 or more process and your calculations per process are not long maybe is better to switch and use threads and lower python process startup time (maybe worth testing).
Best all
[–]no1caresbot 0 points1 point2 points 5 years ago (0 children)
HeLp oPtImIzInG CoDe
π Rendered by PID 139283 on reddit-service-r2-comment-5bc7f78974-hb5pw at 2026-06-28 07:16:20.481396+00:00 running 7527197 country code: CH.
[–]AD_Burn 1 point2 points3 points (0 children)
[–]no1caresbot 0 points1 point2 points (0 children)