p2 Python Project
p2 Python Project
##### ADD YOUR NAME, Student ID, and Section number #######
# NAME: Daniella Vargas Figueroa
# STUDENT ID:802228453
# SECTION:096
###########################################################
# Auxiliar functions
# The function valid_seq() will check if the given sequence is valid or not.
# seq: is a string containing the sequence entered by the user
def valid_seq(seq):
isvalid = False
#Checks which of the inputs is valid.
for s in 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,
# calculate which nucleotide is more frequent
# and returns a list with two elements: the nucleotide with maximum frequency and
its frequency.
# a,b,c,d: are the number of frequencies for each nucleotide
def max_nuc(A,G,C,T):
if A>G and A>C and A>T:
return["A",A]
elif G>A and G>C and G>T:
return ["G",G]
elif C>A and C>G and C>T:
return ["C",C]
elif T>A and T>C and T>G:
return ["T",T]
#########################
# 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
def load_data(a):
#Create a counter for the while loop.
counter=a
#Create an empty list named sequences.
sequences=[]
# While loop continues adding entered sequences to list sequences until reached
number of sequences the user input.
while counter > 0:
seq=input("DNA sequence: ")
if valid_seq(seq):
sequences.append(seq)
counter-=1
else:
print("Invalid Input. Try again")
#Created a new list to add all the valid sequences.
validseq=[]
for i in sequences:
if valid_seq(i):
validseq.append(i)
return validseq
# input sequences
# validate sequences
# save list
# return list
#New function to sort the order of the frequencies from greater to least for the
challenge.
def order(l):
#Reverse each element in l, sort l and reverse l again. Then after the list is
sorted reverse l again to get the list from greatest to least.
for element in l:
element.reverse()
l.sort()
l.reverse()
for element in l:
element.reverse()
#return l
return l
if __name__ == "__main__":
main()