diff options
author | Zachary Sloan | 2013-04-17 21:59:16 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-04-17 21:59:16 +0000 |
commit | 296d7dec13a57519e64e99ab7c3a4673447c026f (patch) | |
tree | 508e8bb43dc87de611553e0ff8c8adeb71ebb727 | |
parent | ed45b048b42a282f7ba7197af07e34db6c78022f (diff) | |
download | genenetwork2-296d7dec13a57519e64e99ab7c3a4673447c026f.tar.gz |
Added a benchmark for running the chunks code on the list of snps
-rw-r--r-- | wqflask/wqflask/my_pylmm/pyLMM/chunks.py | 12 | ||||
-rw-r--r-- | wqflask/wqflask/my_pylmm/pyLMM/lmm.py | 30 |
2 files changed, 10 insertions, 32 deletions
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/chunks.py b/wqflask/wqflask/my_pylmm/pyLMM/chunks.py index 4c34080c..abeffee7 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/chunks.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/chunks.py @@ -32,7 +32,7 @@ def divide_into_chunks(the_list, number_chunks): return chunks -def confirm_chunk(original, result): +def _confirm_chunk(original, result): all_chunked = [] for chunk in result: all_chunked.extend(chunk) @@ -40,7 +40,7 @@ def confirm_chunk(original, result): assert original == all_chunked, "You didn't chunk right" -def chunk_test(divide_func): +def _chunk_test(divide_func): import random random.seed(7) @@ -58,7 +58,7 @@ def chunk_test(divide_func): len(the_list), number_chunks, len(result))) print("result:", result) - confirm_chunk(the_list, result) + _confirm_chunk(the_list, result) amount_off = abs(number_chunks - len(result)) if amount_off == 0: @@ -75,13 +75,13 @@ def chunk_test(divide_func): return number_exact, total_amount_off -def main(): +def _main(): info = dict() #funcs = (("sam", sam_divide_into_chunks), ("zach", zach_divide_into_chunks)) funcs = (("only one", divide_into_chunks),) for name, func in funcs: start = time.time() - number_exact, total_amount_off = chunk_test(func) + number_exact, total_amount_off = _chunk_test(func) took = time.time() - start info[name] = dict(number_exact=number_exact, total_amount_off=total_amount_off, @@ -90,7 +90,7 @@ def main(): print("info is:", info) if __name__ == '__main__': - main() + _main() print("\nConfirming doctests...") import doctest doctest.testmod()
\ No newline at end of file diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py index 99040d38..24565af8 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py @@ -29,6 +29,8 @@ from pprint import pformat as pf from utility.benchmark import Bench +from wqflask.my_pylmm.pyLMM import chunks + #np.seterr('raise') def run_human(pheno_vector, @@ -70,15 +72,14 @@ def run_human(pheno_vector, with Bench("Create list of inputs"): - inputs = list(plink_input) with Bench("Divide into chunks"): - divide_into_chunks(inputs, 63) + results = chunks.divide_into_chunks(inputs, 63) for snp, this_id in plink_input: with Bench("part before association"): - if count > 10000: + if count > 500: break count += 1 @@ -103,25 +104,6 @@ def run_human(pheno_vector, return p_values, t_stats -def divide_into_chunks(the_list, number_chunks): - """Divides a list into approximately number_chunks smaller lists""" - length = len(the_list) - - if length == 0: - return [[]] - - if length <= number_chunks: - number_chunks = length - - chunksize = int(math.ceil(length / number_chunks)) - - chunks = [] - for counter in range(0, length, chunksize): - chunks.append(the_list[counter:counter+chunksize]) - - return chunks - - def human_association(snp, n, keep, @@ -624,7 +606,3 @@ class LMM: pl.xlabel("Heritability") pl.ylabel("Probability of data") pl.title(title) - - -if __name__ == '__main__': - chunk_test()
\ No newline at end of file |