Advertisement
icarussiano

Untitled

Mar 18th, 2024
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from random import choice
  2. N = 1000000
  3. def occurences(sub, string):
  4.     return sum(1 for i in range(len(string)) if string.startswith(sub, i))
  5. seqs = [''.join(choice(['T', 'C']) for _ in range(100)) for _ in range(N)]
  6. counts = [(seq.count('TC'), occurences('CC',seq)) for seq in seqs]
  7. bob_counts=sorted([x for x,y in counts])
  8. alice_counts=sorted([y for x,y in counts])
  9. import matplotlib.pyplot as plt
  10. import numpy as np
  11. from collections import Counter
  12. bob_mean, bob_median = np.mean(bob_counts), np.median(bob_counts)
  13. alice_mean, alice_median = np.mean(alice_counts), np.median(alice_counts)
  14. bob_counts = Counter(bob_counts)
  15. bob_counts_keys, bob_counts_values = list(bob_counts.keys()), list(bob_counts.values())
  16. alice_counts = Counter(alice_counts)
  17. alice_counts_keys, alice_counts_values = list(alice_counts.keys()), list(alice_counts.values())
  18. label_bob = f'Bob mean: {bob_mean:.2f}, median: {bob_median:.2f}'
  19. label_alice = f'Alice mean: {alice_mean:.2f}, median: {alice_median:.2f}'
  20. plt.plot(bob_counts_keys, bob_counts_values, label=label_bob)
  21. plt.plot(alice_counts_keys, alice_counts_values, label=label_alice)
  22. plt.legend()
  23. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement