Skip to content

Instantly share code, notes, and snippets.

@armanbilge
Created September 14, 2015 10:16
Show Gist options
  • Save armanbilge/15add43eb68ed859f136 to your computer and use it in GitHub Desktop.
Save armanbilge/15add43eb68ed859f136 to your computer and use it in GitHub Desktop.
import sys
import itertools as it
stateCount = 4
transitionCount = stateCount ** 2
taxonCount = 92
f = lambda m, n, i, j: (m + n * (n - 1) // 2) * transitionCount + stateCount * i + j
for l in sys.stdin:
D = eval(l)
constant = sum(sum(D[f(m, n, i, i)] for i in range(stateCount)) for m, n in it.combinations(range(taxonCount), 2))
variable = sum(sum(D[f(m, n, i, j)] + D[f(m, n, j, i)] for i, j in it.combinations(range(stateCount), 2)) for m, n in it.combinations(range(taxonCount), 2))
print(variable/constant)
import sys
class SR:
pass
R = [SR() for _ in range(92)]
for i in range(92):
l = sys.stdin.readline().strip()
sr = R[i]
_, sr.taxon, A, G, T, C, sr.seq = l.split(',')
sr.A, sr.G, sr.T, sr.C = map(int, (A, G, T, C))
i = 0
for l in map(str.strip, sys.stdin):
if l:
sr = R[i]
_, _, A, G, T, C, seq = l.split(',')
sr.seq += seq
A, G, T, C = map(int, (A, G, T, C))
sr.A += A
sr.G += G
sr.T += T
sr.C += C
i += 1
i %= 92
for r in R:
print('{},{},{},{},{},{}'.format(r.taxon, r.A, r.G, r.T, r.C, r.seq))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment