Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/local/bin/python3.4
  2.  
  3. def solution(S, P, Q):
  4. # write your code in Python 2.7
  5. ones = []
  6. twos = []
  7. threes = []
  8. fours = []
  9. sum_ones = sum_twos = sum_threes = sum_fours = 0
  10. for nucl in S:
  11. if nucl == 'A':
  12. sum_ones += 1
  13. elif nucl == 'C':
  14. sum_twos += 1
  15. elif nucl == 'G':
  16. sum_threes += 1
  17. elif nucl == 'T':
  18. sum_fours += 1
  19. ones.append(sum_ones)
  20. twos.append(sum_twos)
  21. threes.append(sum_threes)
  22. fours.append(sum_fours)
  23.  
  24. result = []
  25. for i in range(len(P)):
  26. if P[i] == 0:
  27. a = ones[Q[i]]
  28. b = twos[Q[i]]
  29. c = threes[Q[i]]
  30. d = fours[Q[i]]
  31. else:
  32. a = ones[Q[i]] - ones[P[i] - 1]
  33. b = twos[Q[i]] - twos[P[i] - 1]
  34. c = threes[Q[i]] - threes[P[i] - 1]
  35. d = fours[Q[i]] - fours[P[i] - 1]
  36. if a > 0:
  37. result.append(1)
  38. elif b > 0:
  39. result.append(2)
  40. elif c > 0:
  41. result.append(3)
  42. else:
  43. result.append(4)
  44. return result
  45.  
  46. S = 'CAGCCTA'
  47. P = [2, 5, 0]
  48. Q = [4, 5, 6]
  49. print(solution(S, P, Q))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement