Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在base R中迭代.txt文件中的多个子字符串_R_Bioinformatics_Biopython_Fasta - Fatal编程技术网

在base R中迭代.txt文件中的多个子字符串

在base R中迭代.txt文件中的多个子字符串,r,bioinformatics,biopython,fasta,R,Bioinformatics,Biopython,Fasta,我的任务是使用base R(无包)计算FASTA文件的GC内容。我的问题是,我不知道如何在存储序列名以及Cs和Gs的数量的同时实际地迭代序列 示例:我可以读入的文件(作为.txt文件): *此处没有引号,但>指定了一个不同的序列 这样我的输出在概念上类似于- T7_promoter: 0.4 (ratio of GC from # of Gs and Cs) T3_promoter: 0.25 非常感谢您的任何帮助。我目前正在使用readLines()传递文件。我尝试对strsplit()自然

我的任务是使用base R(无包)计算FASTA文件的GC内容。我的问题是,我不知道如何在存储序列名以及Cs和Gs的数量的同时实际地迭代序列

示例:我可以读入的文件(作为.txt文件):

*此处没有引号,但>指定了一个不同的序列

这样我的输出在概念上类似于-

T7_promoter: 0.4 (ratio of GC from # of Gs and Cs)
T3_promoter: 0.25
非常感谢您的任何帮助。我目前正在使用
readLines()
传递文件。我尝试对
strsplit()
自然生成的每个元素使用
unlist(strsplit())
来尝试将每个序列作为一个元素存储在列表中。然后,我可以迭代每个元素以获得计算结果,但我的执行没有成功。

您可以使用
dat运行
输出相关的文章“如何计算字符串中的字符”:
T7_promoter: 0.4 (ratio of GC from # of Gs and Cs)
T3_promoter: 0.25
dat$Gs <- lengths(regmatches(lines$V2, gregexpr("G", dat$V2)))
dat$Cs <- lengths(regmatches(lines$V2, gregexpr("C", dat$V2)))