in reply to bold color text and export to file
Dear Roboticus
Greatly appreciate your help. Well I tried your solution and it worked like charm. However, I am trying to do automatic array building but looks like I am not writing proper syntax.
I am trying to make the @highlights by reading a file having the position number and it doesn't seem to work, whereas if I manually put the positions in the code it the output is not as I am trying to get.
Below is my code and data:
#!/usr/bin/perl use strict; use warnings; use Term::ANSIColor; my $file = $ARGV[0]; if (@ARGV < 1){ print STDERR "Usage: $0 input_fasta_file\n"; exit 1; } my ($header, $sequence); open (A, "<", $file) or die "Check the file: $!"; while (my $line = <A>){ chomp $line; if ($line =~ /^(>.*)/){ $header = $1; } else{ $sequence .= $line; } } close (A); $sequence =~s/[\n\s]//; #print "$sequence\n"; =comment my @highlights = ( [ 88, 1, 'bold red' ], [ 101, 1, 'bold red' ], [ 113, 1, 'bold red' ], [ 121, 1, 'bold red' ], [ 124, 1, 'bold red' ], [ 134, 1, 'bold red' ], [ 140, 1, 'bold red' ], [ 146, 1, 'bold red' ], ); =cut my @highlights; my $pos_file = "sorted_position_walk.txt"; open (A, "<", $pos_file) or die "Check the file: $!"; while (my $line = <A>){ chomp $line; my $pos = (split /\t/,$line)[0]; # push(@position, $pos); push(@highlights, "([ $pos, 1, 'bold yellow' ],)"); } #foreach my $pp(@highlights){ # print "[ $pp, 1, 'bold red' ],\n"; #} #print "@highlights\n"; for my $ar (@highlights) { my ($start, $len, $color) = @$ar; $sequence = substr($sequence, 0, $start-1) # fi +rst part . colored(substr($sequence,$start,$len), $color) # colo +red part . substr($sequence,$start+$len); # fina +l part } print $sequence, "\n";
Output with some weird characters: TCTGTCCGCTCG3m1m[0mGGCAT
Regards
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: bold color text and export to file
by roboticus (Chancellor) on Sep 22, 2014 at 20:26 UTC | |
by newtoperlprog (Sexton) on Sep 23, 2014 at 17:42 UTC | |
by roboticus (Chancellor) on Sep 23, 2014 at 19:47 UTC | |
by newtoperlprog (Sexton) on Sep 23, 2014 at 20:58 UTC |