use Tk; $idea = 0; $rawSequence="atggcgacgaaggccgtgtgcgtgctgaagggcgacggcccagtgcagggcatc +atcaatttcgagcagaaggaaagtaatggaccagtgaaggtgtggggaagcattaaaggactgactgaa +ggcctgcatggattccatgttcatgagtttggagataatacagcaggctgtaccagtgcaggtcctcac +tttaatcctctatccagaaaacacggtgggccaaaggatgaagagaggcatgttggagacttgggcaat +gtgactgctgacaaagatggtgtggccgatgtgtctattgaagattctgtgatctcactctcaggagac +cattgcatcattggccgcacactggtggtccatgaaaaagcagatgacttgggcaaaggtggaaatgaa +gaaagtacaaagacaggaaacgctggaagtcgtttggcttgtggtgtaattgggatcgcccaataaaca +ttcccttggatgtagtctgaggcccct"; my $mainWindow = MainWindow->new(); if( $idea) { # Main Window $mainWindow->title("Regex Problem Example 1"); $mainWindow->minsize(qw(500 500)); #Sets Minimum Size - note lack + of comma $mainWindow->geometry('+500+200'); #Sets Position - note lack of +comma $mainWindow->optionAdd('*font'=>'Courier 10'); $ROText = $mainWindow->Scrolled('ROText', -scrollbars=>'osoe'); $formattedSequence = formatSequence($rawSequence); $ROText->Insert($formattedSequence); $ROText->pack; highlightText($ROText, "gca"); } else { # Main Window $mainWindow->title("Regex Problem Example 2"); #Sets Title $mainWindow->minsize(qw(500 500)); #Sets Minimum Size - note lack + of comma $mainWindow->geometry('+500+200'); #Sets Position - note lack of +comma $mainWindow->optionAdd('*font'=>'Courier 10'); $ROText = $mainWindow->Scrolled('ROText', -scrollbars=>'osoe'); $formattedSequence = searchAndFormatSequence($rawSequence); $ROText->Insert($formattedSequence); $ROText->pack; #This works, but I can't make Uppercase->Lowercase #without removing the tags. highlightText2($ROText, "[A-Z]+"); } MainLoop(); sub highlightText { my ($widget, $searchString) = @_; #alter search string - HOW? # Create a tag to configure the text $widget->tagConfigure('foundtag', -foreground => "white", -background => "red"); $widget->FindAll(-regex, -nocase, $searchString); if ($widget->tagRanges('sel')) { my %startfinish = $widget->tagRanges('sel'); foreach(sort keys %startfinish) { $widget->tagAdd("foundtag", $_, $startfinish{$_}); } $widget->tagRemove('sel', '1.0', 'end'); } } sub highlightText2 { my ($widget, $searchString) = @_; #alter search string - HOW? # Create a tag to configure the text $widget->tagConfigure('foundtag', -foreground => "white", -background => "red"); $widget->FindAll(-regex, -case, $searchString); if ($widget->tagRanges('sel')) { my %startfinish = $widget->tagRanges('sel'); foreach(sort keys %startfinish) { $widget->tagAdd("foundtag", $_, $startfinish{$_}); } $widget->tagRemove('sel', '1.0', 'end'); } #UNCOMMENT TO BREAK! Doesn't like a regex in the replace string #$widget->FindAndReplaceAll(-regex, -case, "G", "g"); #$widget->FindAndReplaceAll(-regex, -case, "C", "c"); #$widget->FindAndReplaceAll(-regex, -case, "A", "a"); } sub searchAndFormatSequence { #I search the sequence and change any gca in the sequence to GCA t +hen #format the sequence, the end result of which is return " 1 atggcgacga aggccgtgtg cgtgctgaag ggcgacggcc cagt +GCAggG CAtcatcaat 61 ttcgaGCAga aggaaagtaa tggaccagtg aaggtgtggg gaaGCAttaa aggac +tgact 121 gaaggcctGC Atggattcca tgttcatgag tttggagata atacaGCAgg ctgta +ccagt 181 GCAggtcctc actttaatcc tctatccaga aaacacggtg ggccaaagga tgaag +agagG 241 CAtgttggag acttggGCAa tgtgactgct gacaaagatg gtgtggccga tgtgt +ctatt 301 gaagattctg tgatctcact ctcaggagac cattGCAtca ttggccGCAc actgg +tggtc 361 catgaaaaaG CAgatgactt ggGCAaaggt ggaaatgaag aaagtacaaa gacag +gaaac 421 gctggaagtc gtttggcttg tggtgtaatt gggatcgccc aataaacatt ccctt +ggatg 481 tagtctgagg cccct"; } sub formatSequence { #I do some really neat formatting here the end result of which is. +.. return " 1 atggcgacga aggccgtgtg cgtgctgaag ggcgacggcc cagt +gcaggg catcatcaat 61 ttcgagcaga aggaaagtaa tggaccagtg aaggtgtggg gaagcattaa aggac +tgact 121 gaaggcctgc atggattcca tgttcatgag tttggagata atacagcagg ctgta +ccagt 181 gcaggtcctc actttaatcc tctatccaga aaacacggtg ggccaaagga tgaag +agagg 241 catgttggag acttgggcaa tgtgactgct gacaaagatg gtgtggccga tgtgt +ctatt 301 gaagattctg tgatctcact ctcaggagac cattgcatca ttggccgcac actgg +tggtc 361 catgaaaaag cagatgactt gggcaaaggt ggaaatgaag aaagtacaaa gacag +gaaac 421 gctggaagtc gtttggcttg tggtgtaatt gggatcgccc aataaacatt ccctt +ggatg 481 tagtctgagg cccct"; }
In reply to Re^2: Searching Formatting and Highlighting Text Problem
by janusmccarthy
in thread Searching Formatting and Highlighting Text Problem
by janusmccarthy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |