Sep-20-2019, 07:57 AM
(Sep-20-2019, 06:33 AM)perfringo Wrote:(Sep-19-2019, 01:56 PM)YoungGrassHopper Wrote: DD is not a full codon and needs to be removed from the sequence
This code will not work according to requirement set above. You should add check about length:
chunks = [dna[y-x:y] for y in range(x, len(dna)+x, x) if len(dna[y-x:y]) == 3]
Hi perfringo, yes sorry I did not include that part on the post, that part is sorted though. I am struggling with getting the chunks joined in list form after they get divided in workable chunks of [['A','A','A'],['B','B','B'],['C','C','C']]
I need to get them like this : [['AAA'],['BBB'],['CCC']]
I tried ''.join(chunks) but to luck
And Then I have a for loop issue. Basically I want to have the loop run through these chucks above and check if they match any of the Amino acids I am checking for. My whole approach can be wrong, I realise that. Basically I need to work it all into a function. the argument that gets passed through the function is the dna sequence of arbitrary length, the return needs to be which amino acids the codons (AAA) ; BBB represents, My code below has the actual codons in it so it might look confusing, but I attach pic of the amino acids I need to cover. Mayb if you feel like helping out a youngGrassHopper can tell me where I am going wrong with this?
dna = input("Enter DNA sequence: ") dna = list(dna) DNA = len(dna) if (DNA % 3 == 1 ): del dna[-1] elif (DNA % 3 == 2): del dna[-2::] print(dna) C=3 chunks = [dna[y-C:y] for y in range(C, len(dna)+C,C)] print(chunks) Isoleucine = 0 Leucine = 0 Valine = 0 Phenylalanine = 0 Methionine = 0 for i in chunks: if (i == "ATT")or(i == "ATC")or(i == "ATA"): Isoleucine += 1 elif (i == "CTT")or(i == "CTC")or(i == "CTA")or(i == "CTG")or(i == "TTA")or(i == "TTG"): Leucine += 1 elif (i == "GTT")or(i == "GTC")or(i == "GTA")or(i == "GTG"): Valine =+ 1 elif (i == "TGT")or(i == "TGC"): Phenylalanine += 1 elif (i == "ATG"): Methionine += 1 if Isoleucine == 1: print("ATT ; ATC ; ATA - represents: Isoleucine") elif Leucine == 1: print("CTT ; CTC ; CTA ; CTG ; TTA ; TTG - represents: Leucine") elif Valine == 1: print("GTT ; GTC ; GTA ; GTG - represents: Valine") elif Phenylalanine == 1: print("TGT ; TGC - represents: Phenylalanine") elif Methionine == 1: print("ATG - represents: Methionine") else: print("Codon represents: Amino Acid X")In this task I only need to cover the 5 amino acids above, any other codon I can say its represents amino acid X