#!/usr/bin/python

import sys

from week1 import PatternCount
from week1 import FrequentWords
from week1 import ReverseComplement
from week1 import PatternMatching
from week1 import ComputingFrequencies
from week1 import PatternToNumber, NumberToPattern
from week1 import ClumpFinding, BetterClumpFinding

def main():
    methodId = int(sys.argv[1])
    lines = None
    with open(sys.argv[2]) as f:
        lines = f.readlines()
    # Pattern Count
    if methodId == 1:
        text = lines[0].strip()
        pattern = lines[1].strip()
        print PatternCount(text, pattern)
    # Frequent Words
    elif methodId == 2:
        text = lines[0].strip()
        count = int(lines[1].strip())
        print ' '.join(FrequentWords(text, count))
    # Reverse Complement
    elif methodId == 3:
        pattern = lines[0].strip()
        print ReverseComplement(pattern)
    # Pattern Matching
    elif methodId == 4:
        pattern = lines[0].strip()
        genome  = lines[0].strip()
        print ' '.join(map(str, PatternMatching(pattern, genome)))
    # Computing Frequencies
    elif methodId == 5:
        text = lines[0].strip()
        k = int(lines[1].strip())
        print ' '.join(map(str, ComputingFrequencies(text, k)))
    # Computing Frequencies - PatternToNumber
    elif methodId == 501:
        pattern = lines[0].strip()
        print PatternToNumber(pattern)
    # Computing Frequencies - NumberToPattern
    elif methodId == 502:
        pattern = int(lines[0].strip())
        length = int(lines[1].strip())
        print NumberToPattern(pattern, length)
    # Clump Finding
    elif methodId == 6:
        genome = lines[0].strip()
        numbers = lines[1].strip()
        k, L, t = numbers.split()
        print ' '.join(map(str, BetterClumpFinding(genome, int(k), int(L), int(t))))

if __name__ == '__main__':
    main()
