def foun(file: str): """The Founder Effect and Genetic Drift""" l1, l2 = Parser(file).lines() n, m = [int(x) for x in l1.split()] a = [int(x) for x in l2.split()] for x in pr.foun(n, m, a): print(*[round(f, 8) for f in x])
def rstr(file: str): """Matching Random Motifs""" l1, seq = Parser(file).lines() n, x = map(float, l1.split(" ")) gc = sum([seq.count(x) for x in "GC"]) lam = ((1 - x) / 2) ** (len(seq) - gc) * (x / 2) ** gc * n print(1 - math.exp(-lam))
def conv(file: str): """Comparing Spectra with the Spectral Convolution""" l1, l2 = Parser(file).lines() s1 = list(map(float, l1.split())) s2 = list(map(float, l2.split())) res = mass.conv(s1, s2) print(res[1], res[0], sep="\n")
def lexf(file: str): """Enumerating k-mers Lexicographically""" l1, l2 = Parser(file).lines() set = l1.split(" ") n = int(l2) perm = ["".join(x) for x in product(set, repeat=n)] print(*sorted(perm), sep="\n")
def lgis(file: str): """Longest Increasing Subsequence""" data = Parser(file).lines()[1] data = [int(x) for x in data.split(" ")] s1 = ros.lgis(data) print(*s1) s2 = ros.lgis([-x for x in data]) s2 = [-x for x in s2] print(*s2)
def cons(file: str): """Consensus and Profile""" x = Parser(file).seqs() mat = ros.profile_matrix(x) print(ros.consensus_sequence(mat)) for i in range(0, 4): print("ACGT"[i] + ":", *mat[i])
def perm(file: str): """Enumerating Gene Orders""" n = Parser(file).ints()[0] perm = list(permutations(range(1, n + 1))) print(len(perm)) for i in perm: print(*i)
def sign(file: str): """Enumerating Oriented Gene Orderings""" n = Parser(file).ints()[0] res = com.sign(n) print(len(res)) for i in res: print(*i)
def gaff(file: str): """Global Alignment with Scoring Matrix and Affine Gap Penalty""" seqs = Parser(file).seqs() res = aln.gaff(seqs[0], seqs[1], -11, -1) print(res["dist"]) print(res["a1"]) print(res["a2"])
def seto(file: str): """Introduction to Set Operations""" n, s1, s2 = Parser(file).lines() n = int(n) s1 = builtins.eval(s1) s2 = builtins.eval(s2) s3 = set(range(1, n + 1)) print(*[s1 | s2, s1 & s2, s1 - s2, s2 - s1, s3 - s1, s3 - s2], sep="\n")
def mprt(file: str): """Finding a Protein Motif""" for id in Parser(file).lines(): seq = ros.get_uniprot(id) matches = ros.find_protein_motif(str(seq.seq)) if len(matches): print(id) print(*matches)
def splc(file: str): """RNA Splicing""" def trim(gene, intron): s = gene.find(intron) return gene[:s] + gene[s + len(intron) :] seqs = Parser(file).seqs() print(ros.Dna(reduce(trim, seqs)).translate())
def sseq(file: str): """Finding a Spliced Motif""" def matches(s1, s2): i, j = 0, 0 while j < len(s2): if s2[j] == s1[i]: yield i + 1 j += 1 i += 1 s1, s2 = [x.seq for x in Parser(file).fastas()] print(*list(matches(s1, s2)))
def kmer(file: str): """k-Mer Composition""" seq = Parser(file).fastas()[0].seq # initialise hash with all possible 4-mers permutations d = {k: 0 for k in ros.kmer_perm(4)} # Run through 4-mer slices of sequence and increment dictionary keys for i in range(len(seq) - 3): d[seq[i : (i + 4)]] += 1 print(*d.values())
def iprb(file: str): """Mendel's First Law""" print(pr.iprb(*Parser(file).ints()))
def lexv(file: str): """Ordering Strings of Varying Length Lexicographically""" l1, l2 = Parser(file).lines() print(*ros.lexv(l1.split(), int(l2)), sep="\n")
def pmch(file: str): """Perfect Matchings and RNA Secondary Structures""" print(com.pmch(Parser(file).seqs()[0]))
def motz(file: str): """Motzkin Numbers and RNA Secondary Structures""" print(com.motz(Parser(file).seqs()[0]))
def lcsq(file: str): """Locating Motifs Despite Introns""" print(aln.lcsq(*Parser(file).seqs()))
def wfmd(file: str): """The Wright-Fisher Model of Genetic Drift""" print(pr.wfmd(*Parser(file).ints()))
def sexl(file: str): """Sex-Linked Inheritance""" arr = Parser(file).floats() print(*[round(2 * v * (1 - v), 3) for v in arr])
def grph(file: str): """Overlap Graphs""" fa = Parser(file).fastas() for i in graph.overlap_graph(fa): print(*i)
def prot(file: str): """Translating RNA into Protein""" print(Parser(file).rna().translate())
def gcon(file: str): """Global Alignment with Constant Gap Penalty""" seqs = Parser(file).seqs() print(aln.gcon(seqs[0], seqs[1]))
def subs(file: str): """Finding a Motif in DNA""" s1, s2 = Parser(file).lines() print(*list(ros.find_motif(s1, s2)))
def eval(file: str): """Expected Number of Restriction Sites""" n, s, a = Parser(file).lines() n = int(n) a = map(float, a.split()) print(*[round(pr.eval(n, s, x), 3) for x in a])
def fibd(file: str): """Mortal Fibonacci Rabbits""" print(com.fibd(*Parser(file).ints()))
def indc(file: str): """Independent Segregation of Chromosomes""" print(*pr.indc(*Parser(file).ints()))
def iev(file: str): """Calculating Expected Offspring""" print(pr.iev(Parser(file).ints()))
def hamm(file: str): """Counting Point Mutations""" print(aln.hamm(*Parser(file).lines()))