使用Biostrings编写R程序,将核苷酸序列转换为蛋白质序列



我有一个.fasta文件,其中包含许多不同的序列。我的目标是使用Biostrings包将每个单独的序列转换为氨基酸序列。.fasta文件看起来像这样:

>Sequence 1
AAATTTGGGCCC
>Sequence 2
TTTGGGCCCAAA

任何帮助都会很感激。谢谢你。

翻译函数将按照您的要求执行:

library(Biostrings)
`Sequence 1` <- DNAString("AAATTTGGGCCC")
`Sequence 2` <- DNAString("TTTGGGCCCAAA")
seq_1 <- translate(`Sequence 1`, no.init.codon=TRUE)
seq_1
#> 4-letter AAString object
#> seq: KFGP
seq_2 <- translate(`Sequence 2`, no.init.codon=TRUE)
seq_2
#> 4-letter AAString object
#> seq: FGPK

读取整个fasta文件:

seqs <- Biostrings::readDNAStringSet("file.fasta", format = "fasta", use.names = TRUE)
seqs_translated <- translate(seqs, no.init.codon = TRUE)
seqs_translated
#> AAStringSet object of length 2:
#>     width seq                               names               
#> [1]     4 KFGP                              Sequence 1
#> [2]     4 FGPK                              Sequence 2

编辑

翻译fasta文件的问题是序列使用"完整"字母表,而不仅仅是ATCG -您有"无呼叫"("N"),间隙("-")和矛盾/未解决的呼叫,例如"K"(鸟嘌呤或胸腺嘧啶)。我使用sed:

找到了这些
grep -v ">" SEQUENCE_orf1ab.fasta | sed 's/[ATCG]//g' | sed '/^$/d'
# explanation: remove lines beginning with ">"
# then remove all A/T/C/G's and blank lines
# what you have left is causing the "not a base" error

如果你删除这些"non-base"使用例如

的碱基
sed '/^>/! s/[-NYRKW]//g' SEQUENCE_orf1ab.fasta > test.fasta 
#explanation: in lines not beginning with ">", substitute all of the characters "-NYRKW" with nothing (i.e. delete them)

则文件被翻译而没有问题:

seqs <- Biostrings::readDNAStringSet("test.fasta", format = "fasta", use.names = TRUE)
seqs_translated <- translate(seqs, no.init.codon = TRUE)
seqs_translated
#>  AAStringSet object of length 91:
#>       width seq                              names               
#>  [1]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MZ505877.1 |Sever...
#>  [2]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MZ020653.1 |Sever...
#>  [3]  7092 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MW988268.1 |Sever...
#>  [4]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MW928277.1 |Sever...
#>  [5]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MW885875.1 |Sever...
#>  ...   ... ...
#> [87]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MN996529.1 |Sever...
#> [88]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MN996530.1 |Sever...
#> [89]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MN996531.1 |Sever...
#> [90]  7094 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MN988713.1 |Sever...
#> [91]  7095 MESLVPGFNEKTHVQ...KTTELLFLVMFLLT MN975262.1 |Sever...

相关内容

  • 没有找到相关文章

最新更新