Question: Write a function printBRH ( geneName , allScoresD ) This function takes a gene name, and a dictionary of memoAlignScore scores as input. It finds
Write a function printBRHgeneNameallScoresD
This function takes a gene name, and a dictionary of memoAlignScore scores as input. It finds and prints the best reciprocal hit for geneName. If there is no best reciprocal hit it returns without printing anything.
def memoAlignScoreS S gap, substitutionMatrix, memo:
computes the alignment score using a a memoized version of alignScore,
memoAlignScoreS S gap, substitutionMatrix,memo where memo is a
dictionary.
# Check if result is already in memo
if S S in memo:
return memoS S
# Base cases
if S: return gap lenS
elif S: return gap lenS
# Recursive cases
option substitutionMatrixS S memoAlignScoreS: S: gap, substitutionMatrix, memo
option gap memoAlignScoreS: S gap, substitutionMatrix, memo
option gap memoAlignScoreS S: gap, substitutionMatrix, memo
# Compute max score
bestscore maxoption option option
# Store result in memo
memoS S bestscore
return bestscore
A simple way to find the best reciprocal hit for geneName is to call closestMatch to get its best matching gene in the other species. Then call closestMatch on this best match from the other species. If the output after the round trip matches geneName, then we've found a best reciprocal hit.
def closestMatchgeneName allScoresD:
Given a gene name and a dictionary of alignment scores, closestMatch
returns the protein from the other species which is most similar
has the highest alignment score
# Initialize variables to keep track of the highest score and best matching protein
maxscore floatinf # Use negative infinity to ensure any score will be higher
bestmatch None
# Loop through each keyvalue pair in the dictionary
for geneA geneB score in allScoresD.items:
# Check if geneName is in the current tuple geneA geneB
if geneName in geneA geneB:
# Determine the other gene in the pair
othergene geneB if geneA geneName else geneA
# Update maxscore and bestmatch if this score is higher
if score maxscore:
maxscore score
bestmatch othergene
return bestmatch
For each best reciprocal hit we will print chromosome, start position, and gene name for the gene in the first species, and then for the gene in the second species. For example:
allScoresDallScoressampleHumanGeneListsampleChickenGeneList
printBRHcallScoresD
chr c chr h
printBRHhallScoresD
printBRHhallScoresD
chr h chr c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
