diff --git a/Schrick-Noah_CS-6643_Lab-9.R b/Schrick-Noah_CS-6643_Lab-9.R index 6ed1de2..b611ca7 100644 --- a/Schrick-Noah_CS-6643_Lab-9.R +++ b/Schrick-Noah_CS-6643_Lab-9.R @@ -49,3 +49,41 @@ Fmat[1,]<- seq(from=0,len=y.len+1,by=-abs(gap_penalty)) Tmat[,1]<- rep(2,x.len+1) # 2 means align with a gap in the upper seq Tmat[1,]<- rep(3,y.len+1) # 3 means align with a gap in the side seq + +#### Part C: Building Fmat and Tmat +## Building Fmat and Tmat +for (i in 2:nrow(Fmat)){ + for (j in 2:ncol(Fmat)){ # use F recursive rules + test_three_cases <- c(Fmat[i-1, j-1] + S[rownames(Fmat)[i], colnames(Fmat)[j]], # 1 mis/match + Fmat[i-1, j] + gap_penalty, # 2 up-gap + Fmat[i, j-1] + gap_penalty) # 3 left-gap + Fmat[i,j]=max(test_three_cases) + Tmat[i,j]=which.max(test_three_cases) + } +} +final_score <- Fmat[nrow(Fmat),ncol(Fmat)] + +## Aligning from Tmat +n <- nrow(Tmat) +m <- ncol(Tmat) +seq_align <- character() +while( (n+m)!=2 ){ + if (Tmat[n,m]==1){ + curr_align_col <- rbind(x[n-1],y[m-1]) + seq_align <- cbind(curr_align_col,seq_align) + n <- n-1 + m <- m-1 + }else if(Tmat[n,m]==2){ + curr_align_col <- rbind(x[n-1],"-") + seq_align <- cbind(curr_align_col,seq_align) + n <- n-1 + }else{ + curr_align_col <- rbind("-",y[m-1]) + seq_align <- cbind(curr_align_col,seq_align) + m <- m-1 + } +} # end while + +seq_align + + diff --git a/Schrick-Noah_CS-6643_Lab-9.docx b/Schrick-Noah_CS-6643_Lab-9.docx index cb449ea..f4ef9b9 100644 Binary files a/Schrick-Noah_CS-6643_Lab-9.docx and b/Schrick-Noah_CS-6643_Lab-9.docx differ