Skip to content

Instantly share code, notes, and snippets.

@WinstonCampeau
Last active February 7, 2019 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WinstonCampeau/1d71eace809fc9a61c60f110bd3c3a5f to your computer and use it in GitHub Desktop.
Save WinstonCampeau/1d71eace809fc9a61c60f110bd3c3a5f to your computer and use it in GitHub Desktop.
tRNA DAMBE check in R
md <- read.csv(file.choose(), header=T) #This is not working, need to use FILE, IMPORT DATASET, FROM TEXT(BASE), then select csv, DESELECT "Strings as Factors", IMPORT
#removes leading and trailing numbers from sequences
for(i in 1:nrow(md)){
md[i,] <- substr(md[i,], 3, nchar(md[i,])-2)
}
#Check for even length stem
trna_len_list <- c()
for(i in 1:nrow(md)){
checkstem <- nchar(md[i,])-3 ## subtract 3 to account for anticodon
trna_len_list[i] <- checkstem
if(checkstem%%2 != 0){
cat("tRNA", md[i,], "at row id", i, "has asymmetry\n\n")
}
}
#Get anticodon, then complement
anticodons <- c()
to_codon <- c()
codons <- c()
for(i in 1:nrow(md)){
anticodons[i] <- substr(md[i,], (trna_len_list[i]/2)+1, (trna_len_list[i]/2)+3)
to_codon[i] <- strsplit(anticodons[i], "")
for(j in 1:3){
if(to_codon[[i]][j] == "G"){
to_codon[[i]][j] <- sub("G", "C", to_codon[[i]][j])
} else
if(to_codon[[i]][j] == "C"){
to_codon[[i]][j] <- sub("C", "G", to_codon[[i]][j])
} else
if(to_codon[[i]][j] == "A"){
to_codon[[i]][j] <- sub("A", "U", to_codon[[i]][j])
} else
if(to_codon[[i]][j] == "U"){
to_codon[[i]][j] <- sub("U", "A", to_codon[[i]][j])
}
}
codons[i] <- paste(rev(to_codon[[i]]), collapse='')
}
for(i in 1:nrow(test)){
print(codons[i] == test[i,])
}
#Check stem complimentarity
#substr(md[1,], 0, (nchar(md[1,])/2)-1)
#substr(md[1,], (nchar(md[1,])/2)+5, nchar(md[,1]))
right_list <- c()
left_list <- c()
original_left <- c()
check_list <- c()
for(i in 1:nrow(md)){
left <- strsplit(substr(md[i,], 0, (nchar(md[i,])/2)-3), "")
original_left[i] <- substr(md[i,], 0, (nchar(md[i,])/2)-3)
right_list[i] <- substr(md[i,], (nchar(md[i,])/2)+5, nchar(md[i,]))
for(j in 1:length(left[[1]])){
if(left[[1]][j] == "G"){
left[[1]][j] <- sub("G", "C", left[[1]][j])
} else
if(left[[1]][j] == "C"){
left[[1]][j] <- sub("C", "G", left[[1]][j])
} else
if(left[[1]][j] == "A"){
left[[1]][j] <- sub("A", "U", left[[1]][j])
} else
if(left[[1]][j] == "U"){
left[[1]][j] <- sub("U", "A", left[[1]][j])
}
}
left_list[i] <- paste(rev(left[[1]]), collapse="")
check_list[i] <- left_list[i] == right_list[i]
}
output <- data.frame(tRNA=md[,1], ANTICODON=anticodons, LEFT.STEM=original_left, RIGHT.STEM=right_list, LEFT.COMPLEMENT=left_list, LC.RS.EQUIVALENCY=check_list)
output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment