import argparse
import os
import sys
from pathlib import Path
DATASET_DIR = os.path.join(os.getcwd(), 'datasets')
WEEK2_DIR = str(Path(__file__).resolve().parents[1]) + "/week2"
sys.path.insert(1, WEEK2_DIR)


def profileMostProbableKmer(dna, k, profile) :
    # Get all the kmers inside the dna
    kmer_scores = {}
    for i in range(len(dna)-k+1) :
        curr_kmer = dna[i:i+k]
        if curr_kmer not in kmer_scores :
            kmer_scores[curr_kmer] = 1

    for kmer, score in kmer_scores.items() :
        for i in range(len(kmer)) :
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    
    probable_kmer = max(kmer_scores, key=kmer_scores.get)

    return probable_kmer

def parseArgs() :
    parser = argparse.ArgumentParser(
                prog="{}".format(__file__),
                formatter_class=argparse.RawDescriptionHelpFormatter,
                description='''\
                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                '''
            )
    
    parser.add_argument('-f', '--file', required=False, help="Input file path.")

    return parser.parse_args()

def main() :
    args = parseArgs()
    dataset_path = "{}/{}_dataset.txt".format(DATASET_DIR, os.path.splitext(sys.argv[0])[0])
    nucleotides = ["A", "C", "G", "T"]

    # Default to the dataset folder, if not provided
    if not args.file :
        args.file = dataset_path
    
    with open(args.file, 'r') as f :
        text = f.readline().strip()
        k = f.readline().strip()

        profile_matrix = {}
        for i, row in enumerate(f.readlines()) : 
            profile_matrix[nucleotides[i]] = [float(_) for _ in row.strip().split(" ")]

    kmer = profileMostProbableKmer(text, int(k), profile_matrix)

    print(kmer)

if __name__ == "__main__":
    main()
95656a5afc175d6620d3d890533706600937b30b
<mask token>


def profileMostProbableKmer(dna, k, profile):
    kmer_scores = {}
    for i in range(len(dna) - k + 1):
        curr_kmer = dna[i:i + k]
        if curr_kmer not in kmer_scores:
            kmer_scores[curr_kmer] = 1
    for kmer, score in kmer_scores.items():
        for i in range(len(kmer)):
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    probable_kmer = max(kmer_scores, key=kmer_scores.get)
    return probable_kmer


def parseArgs():
    parser = argparse.ArgumentParser(prog='{}'.format(__file__),
        formatter_class=argparse.RawDescriptionHelpFormatter, description=
        """                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                """
        )
    parser.add_argument('-f', '--file', required=False, help='Input file path.'
        )
    return parser.parse_args()


<mask token>

<mask token>


def profileMostProbableKmer(dna, k, profile):
    kmer_scores = {}
    for i in range(len(dna) - k + 1):
        curr_kmer = dna[i:i + k]
        if curr_kmer not in kmer_scores:
            kmer_scores[curr_kmer] = 1
    for kmer, score in kmer_scores.items():
        for i in range(len(kmer)):
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    probable_kmer = max(kmer_scores, key=kmer_scores.get)
    return probable_kmer


def parseArgs():
    parser = argparse.ArgumentParser(prog='{}'.format(__file__),
        formatter_class=argparse.RawDescriptionHelpFormatter, description=
        """                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                """
        )
    parser.add_argument('-f', '--file', required=False, help='Input file path.'
        )
    return parser.parse_args()


def main():
    args = parseArgs()
    dataset_path = '{}/{}_dataset.txt'.format(DATASET_DIR, os.path.splitext
        (sys.argv[0])[0])
    nucleotides = ['A', 'C', 'G', 'T']
    if not args.file:
        args.file = dataset_path
    with open(args.file, 'r') as f:
        text = f.readline().strip()
        k = f.readline().strip()
        profile_matrix = {}
        for i, row in enumerate(f.readlines()):
            profile_matrix[nucleotides[i]] = [float(_) for _ in row.strip()
                .split(' ')]
    kmer = profileMostProbableKmer(text, int(k), profile_matrix)
    print(kmer)


<mask token>

<mask token>
DATASET_DIR = os.path.join(os.getcwd(), 'datasets')
WEEK2_DIR = str(Path(__file__).resolve().parents[1]) + '/week2'
sys.path.insert(1, WEEK2_DIR)


def profileMostProbableKmer(dna, k, profile):
    kmer_scores = {}
    for i in range(len(dna) - k + 1):
        curr_kmer = dna[i:i + k]
        if curr_kmer not in kmer_scores:
            kmer_scores[curr_kmer] = 1
    for kmer, score in kmer_scores.items():
        for i in range(len(kmer)):
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    probable_kmer = max(kmer_scores, key=kmer_scores.get)
    return probable_kmer


def parseArgs():
    parser = argparse.ArgumentParser(prog='{}'.format(__file__),
        formatter_class=argparse.RawDescriptionHelpFormatter, description=
        """                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                """
        )
    parser.add_argument('-f', '--file', required=False, help='Input file path.'
        )
    return parser.parse_args()


def main():
    args = parseArgs()
    dataset_path = '{}/{}_dataset.txt'.format(DATASET_DIR, os.path.splitext
        (sys.argv[0])[0])
    nucleotides = ['A', 'C', 'G', 'T']
    if not args.file:
        args.file = dataset_path
    with open(args.file, 'r') as f:
        text = f.readline().strip()
        k = f.readline().strip()
        profile_matrix = {}
        for i, row in enumerate(f.readlines()):
            profile_matrix[nucleotides[i]] = [float(_) for _ in row.strip()
                .split(' ')]
    kmer = profileMostProbableKmer(text, int(k), profile_matrix)
    print(kmer)


if __name__ == '__main__':
    main()

import argparse
import os
import sys
from pathlib import Path
DATASET_DIR = os.path.join(os.getcwd(), 'datasets')
WEEK2_DIR = str(Path(__file__).resolve().parents[1]) + '/week2'
sys.path.insert(1, WEEK2_DIR)


def profileMostProbableKmer(dna, k, profile):
    kmer_scores = {}
    for i in range(len(dna) - k + 1):
        curr_kmer = dna[i:i + k]
        if curr_kmer not in kmer_scores:
            kmer_scores[curr_kmer] = 1
    for kmer, score in kmer_scores.items():
        for i in range(len(kmer)):
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    probable_kmer = max(kmer_scores, key=kmer_scores.get)
    return probable_kmer


def parseArgs():
    parser = argparse.ArgumentParser(prog='{}'.format(__file__),
        formatter_class=argparse.RawDescriptionHelpFormatter, description=
        """                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                """
        )
    parser.add_argument('-f', '--file', required=False, help='Input file path.'
        )
    return parser.parse_args()


def main():
    args = parseArgs()
    dataset_path = '{}/{}_dataset.txt'.format(DATASET_DIR, os.path.splitext
        (sys.argv[0])[0])
    nucleotides = ['A', 'C', 'G', 'T']
    if not args.file:
        args.file = dataset_path
    with open(args.file, 'r') as f:
        text = f.readline().strip()
        k = f.readline().strip()
        profile_matrix = {}
        for i, row in enumerate(f.readlines()):
            profile_matrix[nucleotides[i]] = [float(_) for _ in row.strip()
                .split(' ')]
    kmer = profileMostProbableKmer(text, int(k), profile_matrix)
    print(kmer)


if __name__ == '__main__':
    main()

import argparse
import os
import sys
from pathlib import Path
DATASET_DIR = os.path.join(os.getcwd(), 'datasets')
WEEK2_DIR = str(Path(__file__).resolve().parents[1]) + "/week2"
sys.path.insert(1, WEEK2_DIR)


def profileMostProbableKmer(dna, k, profile) :
    # Get all the kmers inside the dna
    kmer_scores = {}
    for i in range(len(dna)-k+1) :
        curr_kmer = dna[i:i+k]
        if curr_kmer not in kmer_scores :
            kmer_scores[curr_kmer] = 1

    for kmer, score in kmer_scores.items() :
        for i in range(len(kmer)) :
            prob = profile[kmer[i]][i]
            kmer_scores[kmer] = kmer_scores[kmer] * prob
    
    probable_kmer = max(kmer_scores, key=kmer_scores.get)

    return probable_kmer

def parseArgs() :
    parser = argparse.ArgumentParser(
                prog="{}".format(__file__),
                formatter_class=argparse.RawDescriptionHelpFormatter,
                description='''\
                    Given profile matrix, it will provide the most probable k-mer
                    that is likely to be generated by the profile.

                    Input File format :
                    ---------------------------------------
                    ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
                    5
                    0.2 0.2 0.3 0.2 0.3
                    0.4 0.3 0.1 0.5 0.1
                    0.3 0.3 0.5 0.2 0.4
                    0.1 0.2 0.1 0.1 0.2

                    Expected output :
                    ---------------------------------------
                    CCGAG
                '''
            )
    
    parser.add_argument('-f', '--file', required=False, help="Input file path.")

    return parser.parse_args()

def main() :
    args = parseArgs()
    dataset_path = "{}/{}_dataset.txt".format(DATASET_DIR, os.path.splitext(sys.argv[0])[0])
    nucleotides = ["A", "C", "G", "T"]

    # Default to the dataset folder, if not provided
    if not args.file :
        args.file = dataset_path
    
    with open(args.file, 'r') as f :
        text = f.readline().strip()
        k = f.readline().strip()

        profile_matrix = {}
        for i, row in enumerate(f.readlines()) : 
            profile_matrix[nucleotides[i]] = [float(_) for _ in row.strip().split(" ")]

    kmer = profileMostProbableKmer(text, int(k), profile_matrix)

    print(kmer)

if __name__ == "__main__":
    main()