ivytony Posted May 5, 2010 Share Posted May 5, 2010 I have a sequence that contains many amino acids (e.g. MATQSTDPEGTGSTTS.....), and I want to find both 'ST' and 'TS' in the sequence. I also want to print out the sequence with 'ST' and 'TS' highlighted in color and report the total number of the 'ST' and 'TS' sites found. pls help me a bit to start coding. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/ Share on other sites More sharing options...
Zane Posted May 5, 2010 Share Posted May 5, 2010 str_replace ? Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/#findComment-1053731 Share on other sites More sharing options...
ivytony Posted May 5, 2010 Author Share Posted May 5, 2010 but I also want to count the occurrences in the sequence string. Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/#findComment-1053738 Share on other sites More sharing options...
ignace Posted May 5, 2010 Share Posted May 5, 2010 $count = 0; $text = str_replace($search, $replace, $text, $count); Read the manual and learn. Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/#findComment-1053742 Share on other sites More sharing options...
ivytony Posted May 5, 2010 Author Share Posted May 5, 2010 thanks, I think str_replace works! I also need to search for "SP" and "TP" sites in the protein sequence, how to do the search more efficiently? I want to equalize "S" with "T" in the search. Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/#findComment-1053775 Share on other sites More sharing options...
ignace Posted May 5, 2010 Share Posted May 5, 2010 $search = array( 'ST' => '', 'TS' => '', 'SP' => '', 'TP' => '' ); $count = 0; $text = str_replace(array_keys($search), array_values($search), $text, $count); Quote Link to comment https://forums.phpfreaks.com/topic/200820-search-and-color-characters-in-a-string-help-needed/#findComment-1053839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.