in reply to Pattern finding and printing with regex

A more general solution is to write your regex to find the sequence ID rather than removing the '>' character.

$pattern = qr/^(\w*)/; if ($line =~ /$pattern/) { my $id = $1; $I++; print "$i: $id \n"; }

This approach would exclude the optional sequence description if it were included in the fasta file.

UPDATE: AnomalousMonk is correct. I accidentally omitted the '<' from my regex.

Bill

Replies are listed 'Best First'.
Re^2: Pattern finding and printing with regex
by AnomalousMonk (Archbishop) on Oct 22, 2015 at 01:33 UTC

    But  qr/^(\w*)/ won't capture anything — or more precisely, it will match and capture the empty string. Maybe try something like  qr/^>(\w*)/ instead:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $line = '>CATCATCATCAT'; ;; my $pattern = qr/^>(\w*)/; if ($line =~ /$pattern/) { my $id = $1; print qq{got: '$id'}; } " got: 'CATCATCATCAT'


    Give a man a fish:  <%-{-{-{-<