in reply to Regex problem
The Code is like this:-File 1 looks ilke this:- 12345 14 67890 21 File 2 looks like this:- >gi|12345|ref|OM_2343434|Some text ... ABCDEFANADEFGHIJKLMNOPQRSTVVWXWZ >gi|67890|ref|HM_2338373|Some text ... ABACFHAYJAYAFANJAKALAHUSSGSJISUSSKSOWUWSLSS output should be like this:- 12345 11 FGH 67890 21 ALA Also the File 1 position character should be made bold.
#!/usr/bin/perl use strict; use warnings; my $qfn1 = "File1.txt"; my $qfn2 = "File2.txt"; my %positions; { open(my $fh, '<', $qfn1) or die("Cannot open file \"$qfn1\": $!\n"); while (<$fh>) { my ($key, $pos) = split /\s+/; $positions{$key} = $pos; } } { open(my $fh, '<', $qfn2) or die("Cannot open file \"$qfn2\": $!\n"); for (;;) { defined( my $key = <$fh> ) or last; defined( my $text = <$fh> ) or last; chomp($key); chomp($text); defined( my $pos = $positions{$key} ) or next; $pos = $pos - 1 - 3; $pos >= 0 or next; my ($str) = $text =~ /^.{0,$pos}FAN(.{3})/ or next; print("$key: $str\n"); } }
20081224 Janitored by Corion: Restored content
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting Locations in 3 window size
by ig (Vicar) on Dec 20, 2008 at 17:18 UTC |