Exemple #1
0
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])
Exemple #2
0
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))
Exemple #3
0
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")
Exemple #4
0
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")
Exemple #5
0
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)
Exemple #6
0
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])
Exemple #7
0
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)
Exemple #8
0
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)
Exemple #9
0
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"])
Exemple #10
0
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")
Exemple #11
0
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)
Exemple #12
0
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())
Exemple #13
0
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)))
Exemple #14
0
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())
Exemple #15
0
def iprb(file: str):
    """Mendel's First Law"""
    print(pr.iprb(*Parser(file).ints()))
Exemple #16
0
def lexv(file: str):
    """Ordering Strings of Varying Length Lexicographically"""
    l1, l2 = Parser(file).lines()
    print(*ros.lexv(l1.split(), int(l2)), sep="\n")
Exemple #17
0
def pmch(file: str):
    """Perfect Matchings and RNA Secondary Structures"""
    print(com.pmch(Parser(file).seqs()[0]))
Exemple #18
0
def motz(file: str):
    """Motzkin Numbers and RNA Secondary Structures"""
    print(com.motz(Parser(file).seqs()[0]))
Exemple #19
0
def lcsq(file: str):
    """Locating Motifs Despite Introns"""
    print(aln.lcsq(*Parser(file).seqs()))
Exemple #20
0
def wfmd(file: str):
    """The Wright-Fisher Model of Genetic Drift"""
    print(pr.wfmd(*Parser(file).ints()))
Exemple #21
0
def sexl(file: str):
    """Sex-Linked Inheritance"""
    arr = Parser(file).floats()
    print(*[round(2 * v * (1 - v), 3) for v in arr])
Exemple #22
0
def grph(file: str):
    """Overlap Graphs"""
    fa = Parser(file).fastas()
    for i in graph.overlap_graph(fa):
        print(*i)
Exemple #23
0
def prot(file: str):
    """Translating RNA into Protein"""
    print(Parser(file).rna().translate())
Exemple #24
0
def gcon(file: str):
    """Global Alignment with Constant Gap Penalty"""
    seqs = Parser(file).seqs()
    print(aln.gcon(seqs[0], seqs[1]))
Exemple #25
0
def subs(file: str):
    """Finding a Motif in DNA"""
    s1, s2 = Parser(file).lines()
    print(*list(ros.find_motif(s1, s2)))
Exemple #26
0
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])
Exemple #27
0
def fibd(file: str):
    """Mortal Fibonacci Rabbits"""
    print(com.fibd(*Parser(file).ints()))
Exemple #28
0
def indc(file: str):
    """Independent Segregation of Chromosomes"""
    print(*pr.indc(*Parser(file).ints()))
Exemple #29
0
def iev(file: str):
    """Calculating Expected Offspring"""
    print(pr.iev(Parser(file).ints()))
Exemple #30
0
def hamm(file: str):
    """Counting Point Mutations"""
    print(aln.hamm(*Parser(file).lines()))