# score_oligo.py # Author: Neha Bhagwat # Last updated: December 31, 2017 # Purpose: Program to score a sequence using the pwm generated by create_pwm.py # Program uses the Python function open() and the Python methods read(), write(), # close() and split() # from __future__ import division # Read a list of sequences of size 9, one per line, from the file Donor_MOG.txt input_file = open("Donor_MOG.txt", "r") input_data = input_file.read() input_file.close() input_list = input_data.split("\r\n") # Take as input Donor_MOG_matrix.txt to read the values of the PWM pwm = open("Donor_MOG_matrix.txt","r") pwm_data = pwm.read() pwm_set = pwm_data.split("\n") a = pwm_set[0].split('\t') a = a[0:9] c = pwm_set[1].split('\t') c = c[0:9] g = pwm_set[2].split('\t') g = g[0:9] t = pwm_set[3].split('\t') t = t[0:9] pwm.close() output_file = open("Donor_MOG_scores.txt", "w") # Compute the score of each sequence read from the file Donor_MOG.txt for ele in input_list: total = 0 for i in range(9): if ele[i] == 'A': total = total + float(a[i]) elif ele[i] == 'C': total = total + float(c[i]) elif ele[i] == 'G': total = total + float(g[i]) elif ele[i] == 'T': total = total + float(t[i]) # Write each input sequence followed by it's score into the file # Donor_MOG_scores.txt output_file.write(ele + "\t" + str(total) + "\n") output_file.close()