in reply to Re^2: bold color text and export to file
in thread bold color text and export to file

Dear Roboticus and Anonymous Monk

Thank you for your suggestions and directions and I am extremely sorry for any confusion if any.

As you mentioned in your earlier post, that this will not work if the sequences are overlapping and I have found that some of my regions would be overlapping.

I was also thinking if this could be done by an array of range operator and for each array element the sequence will be either bold or colored.

Below is my code which I was trying:

#!/usr/bin/perl #use strict; use warnings; my $filename = "NM_014143.3.fasta"; my @name = split( /\./, $filename ); my $name = $name[0]; my ($infile, @temp); open( $infile, "<", $filename ) || die "Check the $filename $!\n"; while ( my $line = <$infile> ) { chomp $line; if ( $line =~ /^>/ ) { next; } elsif ( $line =~ /^\s*$/ ) { next; } elsif ( $line =~ /^\s*#/ ) { next; } else { $sequence .= $line; } } $sequence =~ s/\n//g; $sequence =~ s/\s+//g; #print "$sequence\n"; close ($infile); my @seq = (1 .. 15, 30 .. 40, 50 .. 60); #this is a range array for (my $pos=1;$pos<=length($sequence);$pos++){ foreach my $ar(@seq){ if($pos == $ar){ push (@temp, "<b>",$sequence, "</b"); } else{ push (@temp, $sequence); } } } my $tmp = join ("", @temp); print "$tmp\n";
Data file: GGCGCAACGCTGAGCAGCTGGCGCGTCCCGCGCGGCCCCAGTTCTGCGCAGCTTCCCGAGGCTCCGCACC + CC +TGCAGGGCATTCCAGAAAGATGAGGATATTTGCTGTCTTTATATTCATGACCATTTGCTGAACGCATT TACTGTCACGGTTCCCAAGGACCTATATGTGGTAGAGTATGGTAGC + AT +GACAATTGAATGCAAATTCCCAGTAGAAAAACAATTAGACCTGGCTGCACTAATTGTCTATTGGG AAATGGAGGATAAGAACATTATTCAATTTGTGCATGGAGAGGAAGACCTGAAGGTTCAGCATAGTAGCTA CAGACAGAGGGCCCGGCTGTTGAAGGACCAGCTCTCCCTGGGAAATGCTGCACTTCAGATCACAGATGTG AAATTGCAGGATGCAGGGGTGTACCGCTGCATGATCAGCTATGGTGGTGCCGACTACAAGCGAATTACTG TGAAAGTCAATGCCCCATACAACAAAATCAACCAAAGAATTTTGGTTGTGGATCCAGTCACCTCTGAACA TGAACTGACATGTCAGGCTGAGGGCTACCCCAAGGCCGAAGTCATCTGGACAAGCAGTGACCATCAAGTC CTGAGTGGTAAGACCACCACCACCAATTCCAAGAGAGAGGAGAAGCTTTTCAATGTGACCAGCACACTGA

Replies are listed 'Best First'.
Re^4: bold color text and export to file
by roboticus (Chancellor) on Sep 23, 2014 at 19:47 UTC

    newtoperlprog:

    If your ranges overlap, there are several strategies you can use. If the overlapping regions are supposed to be highlighted in a single color, then you can simply merge the overlapped regions before applying the edits. If you want to highlight the overlapping region in a different style, then you need to break the ranges up into the non-overlapping and overlapping pieces. Once you've preprocessed your list so that there are no overlaps remaining, you can then apply your edits.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Dear Roboticus

      Thank you for your suggestion. The ranges don't overlap and they are discreet from each other.

      The problem with the code is its not able to demarcate the start and stop of the range (example: 1 till 15 and so on) to which the html tags can be applied. I can understand that my logic in the loop is incorrect and am trying to learn to fix this problem.

      Any help will be greatly appreciated