【发布时间】:2015-05-10 14:53:07
【问题描述】:
class ORF_Finder {
public:
void findORFs(string & strand, int sizeOfStrand);
vector<string> orf1Strands;
vector<string> orf2Strands;
vector<string> orf3Strands;
private:
string newStrand;
string newSub;
};
void ORF_Finder::findORFs(string & strand, int sizeOfStrand) {
int pos, pos1, index = 0;
for (int i = 0; i < strand.size(); i++) {
pos = strand.find("ATG");
pos1 = strand.find("TAA");
newSub = strand.substr(pos, pos1);
newStrand.insert(index, newSub);
strand.erase(pos, pos1);
index = index + 3;
if ((pos1 % 3 == 0) && (pos1 >= pos + 21)) {
orf1Strands.push_back(newStrand);
}
else if ((pos1 % 3 == 1) && (pos1 >= pos + 21)) {
orf2Strands.push_back(newStrand);
}
else if ((pos1 % 3 == 2) && (pos1 >= pos + 21)) {
orf3Strands.push_back(newStrand);
}
}
}
^ 假设所有字符串都已声明,并且我正在“使用命名空间 std”。
我的目标是向用户询问导入的 DNA 链(例如:“TCAATGCGCGCTACCATGCGGAGCTCTGGGCCCAAATTTCATCCATAACTGGGGCCCTTTTAAGGGCCCGGGAAATTT”)并查找子字符串以“ATG”开头并以“TAA”、“TAG”或“TGA”结尾的所有实例(为简单起见,我省略了“TAG”和“TGA”)。
子字符串将是这样的:“ATG ... ... ... ... TAA”,然后将其存储到向量中以供以后使用。但是,我想找到每个阅读框的多个实例(ORF1应该从导入链的“T”开始,ORF2应该从导入链的“C”开始,ORF3应该从“A”开始导入的链)并且应该以三元组形式工作,因此在 if 语句中包含 mod 3。 “pos1 >= pos + 21”的目的是使每个子串至少有七个密码子长。
上面的代码是我迄今为止所做的,但很明显,它是不正确的。我试图告诉 pos 找到“ATG”,让 pos1 找到“TAA”。 newSub 是将从“ATG”生成到“TAA”的子字符串,并且将生成 newStrand 以包含该子字符串。然后我会擦除链的一部分(以避免重复)并增加索引。
抱歉,描述太长了,但我一直在强调这个问题,我已经尽我的意志力尝试了一切来解决这个问题。
【问题讨论】:
-
如果子字符串重叠,您想做什么:ATG...ATG...TAA...TAA?你消费了从 ATG 到第一个 TAA 的所有内容,并在 TAA 之后搜索另一个 ATG ?
-
@SergeBallesta 对不起,我提供了一个糟糕的例子。应该是这样的:TCAATGCGCGCTACCCGGAGCTCTGGGCCCAAATTTCATCCTAAACT。本质上,不应该有重叠的子字符串,并且序列会更长。
-
也许您应该将 DNA 序列存储在特定的数据结构中,而不是字符串中。字符串将整个字母表考虑在内,导致内存使用量增加 4 倍...
-
查看此SO Question 以有效选择数据结构。如果你打算继续使用字符串,KMP 是你应该使用的算法。