p3 Python Project
p3 Python Project
p3 Python Project
##### ADD YOUR NAME, Student ID, and Section number #######
# NAME: DANIELLA VARGAS FIGUEROA
# STUDENT ID:802228453
# SECTION:096
###########################################################
# The function load_data, it take as an argument, it input the DNA sequences, save
in the list and return the list
# a: is a number of sequences to be input
#Auxiliar functions
def valid_seq(seq):
isvalid = False
for s in list(seq):
if (s == 'A') or (s == 'C') or (s == 'T') or (s == 'G'):
isvalid = True
else:
isvalid = False
break
return isvalid
#the max_nuc() takes four inputs: the nucleotide frequencey in a colum, and returns
a list of two elements containing the nucleotide
#and its frequency in a column
def max_nuc(freq_a, freq_g, freq_c, freq_t):
if freq_a > freq_g and freq_a > freq_c and freq_a > freq_t:
return ["A", freq_a]
elif freq_g > freq_a and freq_g > freq_c and freq_g > freq_t:
return ["G", freq_g]
elif freq_c > freq_a and freq_c > freq_g and freq_c > freq_t:
return ["C", freq_c]
elif freq_t > freq_a and freq_t > freq_c and freq_t > freq_g:
return ["T", freq_t]
#########################
#the load_data() takes two inputs: the file name and returns one tuple (firts one
list of elements, and option (consesus or transcription)
def load_data(filename, option):
#assign variable and open file
lst = []
infile = open(filename, "r")
#read file
valid_length = None
for line in infile:
seq = line.rstrip("\n")
#Check if the sequence is valid and is the same length as the first one to
continue with program.
if valid_seq(seq) == True and (valid_length == len(seq)
or valid_length == None):
lst.append(seq)
if len(lst) == 1:
valid_length = len(lst[0])
result = (lst, option)
#Return result.
return result
consensusString = consensusString + x
#Write the Consensus inside the file.
f.write(consensusString)
# The function main, your program to start and function calls and write new file
with consensus or transcription
def main():
filename = input("Write the name of the file: ")
print('Select option:')
print('1. Consensus Sequences')
print('2. Transcriptions Sequences')
option = int(input(""))
#Create while loop to only accept option one or two.
while option != 1 and option != 2:
print("Incorrect input. Only enter 1 or 2.")
option = int(input(""))
data = load_data(filename, option)
#Create the function calls according to the option the user inputs.
if data[1] == 1:
freq = count_nucl_freq(data[0])
cons = find_consensus(freq)
elif data[1] == 2:
# conv=convert_seq(data[0])
transcript = transcript_seq(data[0])
if __name__ == "__main__":
main()