import os import sys import argparse def studentInfo(): pythonVersion = 'Version' student1FirstName = "Cristian" student1LastName = "Ibarra" student1SectionNumber = "2" student1NetId = "cibar007" student2FirstName = "Kevin" student2LastName = "Le" student2SectionNumber = "2" student2NetId = "kle016" info = 'Python version: ' + pythonVersion + '\n' + '\n' info = info + 'FirstName: ' + student1FirstName + '\n' info = info + 'LastName: ' + student1LastName + '\n' info = info + 'Section: ' + student1SectionNumber + '\n' info = info + 'NetId: ' + student1NetId + '\n' + '\n' info = info + 'FirstName: ' + student2FirstName + '\n' info = info + 'LastName: ' + student2LastName + '\n' info = info + 'Section: ' + student2SectionNumber + '\n' info = info + 'NetId: ' + student2NetId + '\n' + '\n' return info #will follow the recurrence #matching a '-' with a character will result in -.2 + previous #matching a character with the same character will result in 1+diagonal #matching different characters will result in -.1 + previous except for A & T or C & G, #which produces -.15 + previous def diff(i,j,Table, DNASeq2, DNASeq1): value3 = -0.2 + Table[i-1][j] value2 = -0.2 + Table[i][j-1] if DNASeq2[i-1] == DNASeq1[j-1]: value1 = 1 + Table[i-1][j-1] else: if (DNASeq2[i-1] == 'A' and DNASeq1[j-1] == 'T') or (DNASeq2[i-1] == 'T' and DNASeq1[j-1] == 'A') or (DNASeq2[i-1] == 'C' and DNASeq1[j-1] == 'G') or (DNASeq2[i-1] == 'G' and DNASeq1[j-1] == 'C'): value1 = -0.15 + Table[i-1][j-1] else: value1 = -0.1 + Table[i-1][j-1] return max(value1, value2, value3) def DNASeqAlignment(DNASeq1,DNASeq2): similarityScore = -1 sequenceAlignment1 = '' sequenceAlignment2 = '' Table = [[0 for x in range(len(DNASeq1) + 1)] for x in range(len(DNASeq2) + 1)] for x in range(0, len(DNASeq1) + 1): Table[0][x] = -0.2*x for x in range(0, len(DNASeq2) + 1): Table[x][0] = -0.2*x for i in range(1, len(DNASeq2) + 1): for j in range(1, len(DNASeq1) + 1): Table[i][j] = Table[i][j] + diff(i,j,Table, DNASeq2, DNASeq1) similarityScore = Table[len(DNASeq2)][len(DNASeq1)] i=len(DNASeq2) j=len(DNASeq1) while (i > 0) or (j > 0): if Table[i][j]-1 == Table[i-1][j-1]: sequenceAlignment1 = DNASeq1[j-1] + sequenceAlignment1 sequenceAlignment2 = DNASeq2[i-1] + sequenceAlignment2 i = i - 1 j = j - 1 elif Table[i][j] - 0.2 == Table[i][j-1] and j != 0: sequenceAlignment1 = DNASeq1[j-1] + sequenceAlignment1 sequenceAlignment2 = '-' + sequenceAlignment2 j = j - 1 elif Table[i][j] - 0.2 == Table[i-1][j] and i != 0: sequenceAlignment1 = '-' + sequenceAlignment1 sequenceAlignment2 = DNASeq2[i-1] + sequenceAlignment2 i = i - 1 ######################################################################################### # Compute new values for similarityScore and sequenceAlignment1 and sequenceAlignment2 # # ######################################################################################### ################################# Output Section ###################################### result = "Similarity score: " + str(similarityScore) + '\n' result = result + "Sequence alignment1: " + sequenceAlignment1 + '\n' result = result + "Sequence alignment2: " + sequenceAlignment2 + '\n' print(result) if __name__ == "__main__": DNASeq1 = 'ATCG' DNASeq2 = 'T' DNASeqAlignment(DNASeq1,DNASeq2)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question