我想要做的是从 NSString 中获取 3 个字母的单词序列,并将它们更改为相应的单词。EX)AUG =“START”,AGC =“Asparagine”等。我的想法是将 NSString 更改为 NSArray,每个元素包含 3 个字母,然后我可以在 for 循环中引用它们,以创建一个新字符串与结果词。
例子:
NSDictionary *aminoReplaceDict = @{
@"AAA" : @"Lysine",
@"AAC" : @"Asparagine",
@"AAG" : @"Lysine",
@"AAU" : @"Asparagine",
@"ACA" : @"Threonine",
@"ACC" : @"Threonine",
@"ACG" : @"Threonine",
@"ACU" : @"Threonine",
@"AGA" : @"Arginine",
@"AGC" : @"Serine",
@"AGG" : @"Arginine",
@"AGU" : @"Serine",
@"AUA" : @"Isoleucine",
@"AUC" : @"Isoleucine",
@"AUG" : @"START",
@"AUU" : @"Isoleucine",
@"CAA" : @"Glutamine",
@"CAC" : @"Histidine",
@"CAG" : @"Glutamine",
@"CAU" : @"Histidine",
@"CCA" : @"Proline",
@"CCC" : @"Proline",
@"CCG" : @"Proline",
@"CCU" : @"Proline",
@"CGA" : @"Arginine",
@"CGC" : @"Arginine",
@"CGG" : @"Arginine",
@"CGU" : @"Arginine",
@"CUA" : @"Leucine",
@"CUC" : @"Leucine",
@"CUG" : @"Leucine",
@"CUU" : @"Leucine",
@"GAA" : @"Glutamic Acid",
@"GAC" : @"Aspartic Acid",
@"GAG" : @"Glutamic Acid",
@"GAU" : @"Aspartic Acid",
@"GCA" : @"Alanine",
@"GCC" : @"Alanine",
@"GCG" : @"Alanine",
@"GCU" : @"Alanine",
@"GGA" : @"Glycine",
@"GGC" : @"Glycine",
@"GGG" : @"Glycine",
@"GGU" : @"Glycine",
@"GUA" : @"Valine",
@"GUC" : @"Valine",
@"GUG" : @"Valine",
@"GUU" : @"Valine",
@"UAA" : @"STOP",
@"UAC" : @"Tyrosine",
@"UAG" : @"STOP",
@"UAU" : @"Tyrosine",
@"UCA" : @"Serine",
@"UCC" : @"Serine",
@"UCG" : @"Serine",
@"UCU" : @"Serine",
@"UGA" : @"STOP",
@"UGC" : @"Cysteine",
@"UGG" : @"Tryptonphan",
@"UGU" : @"Cysteine",
@"UUA" : @"Leucine",
@"UUC" : @"Phenylalanine",
@"UUG" : @"START",
@"UUU" : @"Phenylalanine",
};
NSMutableString *replaceString = [NSMutableString stringWithString:_trnaOut.text];
for( NSString *replaceWord in [aminoReplaceDict allKeys] )
{
[replaceString replaceOccurrencesOfString:replaceWord withString:aminoReplaceDict[replaceWord] options:NSCaseInsensitiveSearch range:NSMakeRange(0, replaceString.length )];
}
_aminoOut.text = replaceString;
输出: