Insulin Protein Sequence | |
---|---|
Human | MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN |
Dog | MALWMRLLPLLALLALWAPAPTRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREVEDLQVRDVELAGAPGEGGLQPLALEGALQKRGIVEQCCTSICSLYQLENYCN |
Cat | MAPWTRLLPLLALLSLWIPAPTRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAEDLQGKDAELGEAPGAGGLQPSALEAPLQKRGIVEQCCASVCSLYQLEHYCN |
Pig | MALWTRLLPLLALLALWAPAPAQAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAENPQAGAVELGGGLGGLQALALEGPPQKRGIVEQCCTSICSLYQLENYCN |
2
Human : MALWMRLLPLLALLALWGPdPAaAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQ_____________GSLQPLALEGs_LQKRGIVEQCCTSICSLYQLENYCN |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||| Dog : MALWMRLLPLLALLALWAPAPtRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREvEDLQvrDVELaG_APGeGGLQPLALEGA_LQKRGIVEQCCTSICSLYQLENYCN |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||| | ||| ||||||||| | ||||||||||||||||||||||||| Cat : MApWtRLLPLLALLsLWiPAPtRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAEDLQgkDaEL_GeAPGaGGLQPsALE_APLQKRGIVEQCCaSvCSLYQLEHYCN |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||| | || |||||||||||| |||||||||||||||||||||||| Pig : MALWtRLLPLLALLAlWAPAPAqAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAEnpQagaVEL_Gggl__GGLQaLALEGpP_QKRGIVEQCCTSICSLYQLENYCN AFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAE QKRGIVEQCC SICSLYQLENYCN
3
Let's Simplify the problem a bit by considering only 2 sequences, and make the problem statement more precise by estabishing rules as if it were a game.
Rules:
Objective: Get the most points
%%javascript
var Insulin = {
"Human" : "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN",
"Dog" : "MALWMRLLPLLALLALWAPAPTRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREVEDLQVRDVELAGAPGEGGLQPLALEGALQKRGIVEQCCTSICSLYQLENYCN",
"Cat" : "MAPWTRLLPLLALLSLWIPAPTRAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAEDLQGKDAELGEAPGAGGLQPSALEAPLQKRGIVEQCCASVCSLYQLEHYCN",
"Pig" : "MALWTRLLPLLALLALWAPAPAQAFVNQHLCGSHLVEALYLVCGERGFFYTPKARREAENPQAGAVELGGGLGGLQALALEGPPQKRGIVEQCCTSICSLYQLENYCN"
};
var score = 0;
var topIndex = 0;
var botIndex = 0;
function Match() {
var top = Insulin[document.getElementById("top").value];
var bot = Insulin[document.getElementById("bot").value];
score += (top[topIndex] == bot[botIndex]) ? 1 : 0;
topIndex += 1;
botIndex += 1;
document.getElementById("topseq").innerHTML = top.substring(topIndex,topIndex+24);
document.getElementById("botseq").innerHTML = bot.substring(botIndex,botIndex+24);
document.getElementById("scoreboard").innerHTML = score;
}
function Delete() {
var top = Insulin[document.getElementById("top").value];
score -= 1;
topIndex += 1;
document.getElementById("topseq").innerHTML = top.substring(topIndex,topIndex+24);
document.getElementById("scoreboard").innerHTML = score;
}
function Insert() {
var bot = Insulin[document.getElementById("bot").value];
score -= 1;
botIndex += 1;
document.getElementById("botseq").innerHTML = bot.substring(botIndex,botIndex+24);
document.getElementById("scoreboard").innerHTML = score;
}
function onStart() {
var row, cell, button;
var board = document.getElementById("board");
var table = document.createElement("table");
var tbody = document.createElement("tbody");
topIndex = 0;
botIndex = 0;
var topseq = document.createElement("pre");
topseq.id = "topseq";
topseq.style = "color: blue; font-size: 50px; line-height: 100%;"
topseq.innerHTML = Insulin[document.getElementById("top").value].substring(topIndex,topIndex+24);
var botseq = document.createElement("pre");
botseq.id = "botseq";
botseq.style = "color: blue; font-size: 50px; line-height: 100%;"
botseq.innerHTML = Insulin[document.getElementById("bot").value].substring(topIndex,topIndex+24);
row = document.createElement("tr");
cell = document.createElement("td");
cell.style = "padding: 5px;";
cell.rowSpan = 2;
button = document.createElement("input");
button.style = "height: 90px;";
button.type = "button";
button.value = "Match";
button.addEventListener("click", Match, false);
cell.appendChild(button);
row.appendChild(cell);
cell = document.createElement("td");
button = document.createElement("input");
button.style = "height: 40px;";
button.type = "button";
button.value = "DEL";
button.addEventListener("click", Delete, false);
cell.appendChild(button);
row.appendChild(cell);
cell = document.createElement("td");
cell.style = "padding-left: 20px;"
cell.appendChild(topseq);
row.appendChild(cell);
tbody.appendChild(row);
row = document.createElement("tr");
cell = document.createElement("td");
button = document.createElement("input");
button.style = "height: 40px;";
button.type = "button";
button.value = "INS";
button.addEventListener("click", Insert, false);
cell.appendChild(button);
row.appendChild(cell);
cell = document.createElement("td");
cell.appendChild(botseq);
cell.style = "padding-left: 20px;"
row.appendChild(cell);
tbody.appendChild(row);
table.appendChild(tbody);
board.innerHTML = "";
board.appendChild(table);
score = 0;
document.getElementById("scoreboard").innerHTML = score;
}
function selection(name, check) {
var element = document.createElement("select");
element.id = name;
for (var key in Insulin) {
var option = document.createElement("option");
option.value = key;
option.appendChild(document.createTextNode(key));
option.selected = (key == check);
element.appendChild(option);
}
return element;
}
element.append(selection("top", "Human"));
element.append(" ");
element.append(selection("bot", "Dog"));
element.append(" ");
var start = document.createElement("input");
start.type = "button";
start.value = "Start";
start.addEventListener("click", onStart, false);
element.append(start);
element.append(" <b>Score:</b> ");
var scoreboard = document.createElement("span");
scoreboard.id = "scoreboard";
scoreboard.innerHTML = score;
element.append(scoreboard);
var board = document.createElement("div");
board.id = "board";
board.style = "margin: 20px; height: 160px;"
element.append(board);
// Hidden-Cell
4
The solution my not be unique
How many presses?
How many possible moves?
How big are these for our problem instance?
What algorithm is solves this problem
5
It relies on a rather suprising idea
But before we solve this problem, let's look at another related related problem
Finding a best city tour on a Manhattan grid
6
Imagine seeking a path from a given source to given destination in a Manhattan-like city grid that maximizes the number of attractions (\*) passed. With the following caveat– at every step you must make progress towards the goal. We treat the city map as a graph, with a vertices at each intersection, and weighted edges along each block. The weights are the number of attractions along each block.
7
Goal: Find the maximum weighted path in a grid.
Input: A weighted grid G with two distinct vertices, one labeled source and the other labeled destination
Output: A shortest path in G from source to destination with the greatest weight
8
There are limited number of ways to reach any destination
$$Score(n,m) = Max(Score(n-1,m)+Edge(n-1,m), Score(n,m-1)+Edge(n,m-1))$$
This rule applies recursively with the base case
$$Score(0,0) = 0$$
10
Dynamic Programming is a technique for computing recurrence relations efficiently by storing partial or intermediate results
Three keys to constructing a dynamic programming solution:
11
The solution may not be unique, but it will have the best possible score
12
Instead of solving the Manhattan Tourist problem directly, (i.e. the path from (0,0) to (n,m)) we will solve a more general problem: find the longest path from (0,0) to any arbitrary vertex (i,j).
If the longest path from (0,0) to (n,m) passes through some vertex (i,j), then the path from (0,0) to (i,j) must be the longest. Otherwise, you could increase the weight along your path by changing it.
13
14
19
Computing the score for a point (i,j) by the recurrence relation:
The running time is n x m for a n by m grid
(n = # of rows, m = # of columns)
20
21
22
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$("div.input:contains('Hidden-Cell')").hide();
} else {
$("div.input:contains('Hidden-Cell')").show();
}
code_show = !code_show;
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Toggle Hidden Cells"></form>''')