Page 1 of 1

Write another method for the class called. It should construct and return a new from the consensus characters for each c

Posted: Fri Apr 29, 2022 6:36 am
by answerhappygod
Write Another Method For The Class Called It Should Construct And Return A New From The Consensus Characters For Each C 1
Write Another Method For The Class Called It Should Construct And Return A New From The Consensus Characters For Each C 1 (32.14 KiB) Viewed 20 times
Write another method for the class called. It should construct and return a new from the consensus characters for each column in an alignment. You are recommended to repeatedly call getConsensusForColumn in your implementation. Note that the returned sequence should be composed from the same alphabet as the alignment, except you should allow for gaps to appear in the consensus. Alignment getConsensus Sequence To test your code, use the following sequences and check your consensus sequence using Coder Quiz: seqi Sequence (name="Seql", sequence="AGFDTVTTAISYSL-YLVTNPNVQKKIQ", alphabet=Pr otein_Alphabet, gappy=True) seq2 = Sequence (name="Seq2", sequence="AGFDTITTAISWSL-YLVMNPRIQKKIQ", alphabet=Pr otein_Alphabet, cappy=True) seq3 Sequence (name="Seq3", sequence="AGFDTVT-A-SWSLMYLVMNPRVQRKIQ", alphabet=Pr otein_Alphabet, gappy=True) seq4 Sequence (name="Seq4", sequence="AGFDTVT-A-SWSLMYLVTNPRVQRKIQ“, alphabet=Pr otein_Alphabet, rappy=True) seq5 Sequence (name="Seq5", sequence="AGFDTVT-AISYSLMYLVTNPGVQRKIQ", alphabet=Pr otein_Alphabet, gappy=True) test_aln Alignment([seqi, seq2, seq3, seq4, seq5]) print("My consensus:", test_aln. getConsensus () Question 3a : Submit the consensus sequence that is produced by the getConsensus function for the five sequences above. Question 3b : Submit a file containing the code you developed for your implementation of getConsensus.
def getConsensusForColumn (self, colidx): syment = {} for seq in self. seqs: mysym = seq[colidx] try: #Attempt to execute the code in the below block syment[mysym] += 1 except: #If the above block of code throws any kind of error, #eg. a dictionary key error, execute the below block of code syment [mysym] 1 consensus = None Maxcnt = 0 for mysym in syment: if syment[mysym] > maxcnt: maxcnt = syment (mysyn] consensus = my sym return consensus