Basic genes codon count in R with seqinr
Hello everyone, im new to the r and i have some problems. I need to use just seqinr, so my question is ;
I need to read my genes in FASTA into the list genes so it should be like ;
library(seqinr)
genes <- read.fasta('geness.txt')
length(genes)
## [1] 4120
and i can see my number of genes with the length.
but I need to apply codon_count() to each gene and store the results in the list gene_codon_count.
codon_count <- function(gene) {
answer <- rep(0, 64)
names(answer) <- c("aaa", "aac", "aag", "aat", "aca", "acc", "acg", "act",
"aga", "agc", "agg", "agt", "ata", "atc", "atg", "att", "caa", "cac",
"cag", "cat", "cca", "ccc", "ccg", "cct", "cga", "cgc", "cgg", "cgt",
"cta", "ctc", "ctg", "ctt", "gaa", "gac", "gag", "gat", "gca", "gcc",
"gcg", "gct", "gga", "ggc", "ggg", "ggt", "gta", "gtc", "gtg", "gtt",
"taa", "tac", "tag", "tat", "tca", "tcc", "tcg", "tct", "tga", "tgc",
"tgg", "tgt", "tta", "ttc", "ttg", "ttt")
for(i in seq(from=1, to=length(gene), by=3)) {
codon <- tolower(paste0(gene[i], gene[i+1], gene[i+2]))
answer[codon] <- answer[codon] + 1
}
return(answer)
}
and the answer should be
length(genes_codon_count)
## [1] 4120
length(genes_codon_count[[1]])
## [1] 64
But i cant get any results so im missing or doing something wrong.
• 174 views
•
link
0 answers
No answers yet.
Log in to answer this question.
From your code, it seems to me that you are trying to count the codons and extract codon usage in sequences from a file. There is easy way to do this:
Example fasta file with dummy sequences:
Load this in to R: