【发布时间】:2012-02-18 01:08:56
【问题描述】:
我是 D 的新手,想解析格式为的生物文件
>name1
acgcgcagagatatagctagatcg
aagctctgctcgcgct
>name2
acgggggcttgctagctcgatagatcga
agctctctttctccttcttcttctagagaga
>name2
gag ggagag
这样我就可以使用相应的“序列”数据捕获“标题”名称 1、名称 2、名称 3,即 ..acgcg... 的东西。
现在我有了这个。但它只会逐行迭代,
import std.stdio;
import std.stream;
import std.regex;
int main(string[] args){
auto filename = args[1];
auto entry_name = regex(r"^>(.*)"); //captures header only
auto fasta_regex = regex(r"(\>.+\n)([^\>]+\n)"); //captures header and correponding sequence
try {
Stream file = new BufferedFile(filename);
foreach(ulong n, char[] line; file) {
auto name_capture = match(line,entry_name);
writeln(name_capture.captures[1]);
}
file.close();
}
catch (FileException xy){
writefln("Error reading the file: ");
}
catch (Exception xx){
writefln("Exception occured: " ~ xx.toString());
}
return 0;
}
我想知道一种提取标题和序列数据的好方法,这样我就可以创建一个关联数组,其中每个项目对应于文件中的一个条目
[name1:acgcgcagagatatagctagatcgaagctctgctcgcgct,name2:acgggggcttgctagctcgatagatcgaagctctctttctccttcttcttctagagaga,.....]
【问题讨论】:
-
D 似乎在生物信息学家中很受欢迎 :)