HELLO. I AM TRYING TO COUNT G'S AND C'S IN A LIST OF STRINGS AND HAVE THE LOOP PUT OUT THE GC COUNT AND THEN CALCULATE A GC PERCENTAGE. I HAVE TRIED VARIOUS CONFIGURATIONS OF A NESTED LOOP AS WELL AS TRYING TO FIGURE OUT HOW TO SOLVE IT USING A FUNCTION, AND AM JUST STUCK. ANY HELP WOULD BE GREATLY APPRECIATED. I AM STUCK ON PART 2/3.
print("\n########## PART 3 ##########\n") #PART 3 - Iterate through a list of strings, calculate value, write to file #(1) Iterate through the list of sequences #(2) Count G's and C's for each sequence number in a list. #(3) Calculate the GC Percentage for the sequence nmer. #(4) Write the sequence and its GC percentage (separated by a "Tab") # to a file named: # gc_output.txt #For example if given the following sequence list #seq_list=["AAUG","AGCG","GCUA"] #The loop would write the following to the file gc_output.txt #AAUG 25.0 #AGCG 75.0 #GCUA 50.0 #== PART 3 == #seq_list=["AAUG","AGCG","GCUA"] #seq_list=["AAUGGAGACU","AGCGCCCC","GCUAAAAAAU"] #(1) seqs=["AAUG","AGCG","GCUA"] for element in seqs: print(element) #(2) gc_count=0 total=len(seqs) for seq in seqs: for x in seq: if x == "G" or x == "C": gc_count+=1 print(gc_count) #c_count=0 #seq=["AAUG"] #for x in seq: # if x =="G" or x =="C": # gc_count+=1 # print(gc_count) #def gc_count(string) #Doing a for loop for one of the three sequences seq="AGGC" gc_count=0 for b in seq: if b=="G" or b=="C": gc_count+=1 else: gc_count+=0 print(gc_count) gc_count=0 seq_list=["AAUG", "AGCG", "GCUA"] def gc_calc(seq_list): for b in seq_list: if re.search(g,c): gc_count+=1 else: pass return gc_count #Lab 04 Part 3 Work #(3) #gc_count=0 #seqs=["AAUG","AGCG","GCUA"] #total=len(seqs) #for seq in seqs: # for x in seq: # if x == "G" or x == "C": # gc_count+=1 # gc_percentage = gc_count/float(total) # print("gc_percentage", gc_percentage) #gc_percentage = gc_count/float(total) #print("gc_percentage", gc_percentage) #g=0 #c=0 #t=0 #a=0 #gc_count=0 #a_count=0 #t_count=0 #seq_list=["AAUG","AGCG","GCUA"] #total=len(seq_list) #print("total = ", total) #this refers to how many strings are in the list #for seq in seq_list: # if i == "G" or i == "C": # gc_count+=1 # print("gc=", gc_count) # elif i == "A": # a_count+=1 # print(a_count) # elif i == "T": # t_count+=1 # print(t_count) #gc_count=0 #seq=["AAUG"] #for char in seq: # if i == "G" or i =="C": # gc_count+=1 # print(gc_count) #for x in seq_list: # if "C" in x: # c+=1 # elif "G" in x: # g+=1 # elif "A" in x: # a+=1 # elif "T" in x: # t+=1 #print ("C=%total, G=%total, A=%total, T=%total" %(c,g,a,t)) #gc_content=(g+c)*100/(a+t+g+c) #print ("gc_content= %f" %(gc_content))