How to program the colouring of DNA sequence?
I am using Swift for Mac programming and I see that to color all “A”, “T”, “C”, “G” in a long sequence during its editing is quite slow, there is time lag between typing and displaying the colored sequence. I calculate every time new ranges for all “A”, “T”, “C” in the sequence and then loop through the arrays of ranges to add color to “A”, “T”, “C”. How is usually this coloring done in other programming languages which are more often used in bioinformatics ? I guess I am doing it not in effective way in Swift.
• 1,148 views
•
link
0 answers
No answers yet.
Log in to answer this question.
I fear this may be a better question for Stack Overflow since it's going to be pretty much solely programming-related, but I have two theories. First off, Swift is fast, and colouring a string is a linear-time thing, so this should be very very quick. If its slow, you can expect a big bug introducing polynomial complexity. Perhaps:
1) If your colouring involves modifying the string itself to include colour tags, or just for whatever reason does a copy of the string without actually modifying it, that may cause your loop to re-run until nothing is changed. In essence, you run the loop once per coloured character, rather than per change. Test this by seeing if adding 1 letter 10x quicker than pasting in 10 letters at once.
2) If colouring itself is slow, which it shouldnt be but hey, modify the code to start off by finding a difference between the old (coloured) string and the new string, and only try to colour those new indices. All the previous work can then be re-used. But dont go crazy on this approach, since you'll end up implementing diff, and thats a much harder problem than it looks. Instead just try to reuse colouring indices for any shared prefix/suffix only.
John, Thank you for the helpful and detailed explanation! I have checked the code and your first point was in right direction, I have placed in loop setAttributedString and this slowed down the speed. This method should be outside of the loop.
Hello vytarasov!
We believe that this post does not fit the main topic of this site.
As has already been pointed out, this is a programming question, not a bioinformatics one, so it's off-topic for the site I'm afraid!
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!