Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Bioinformatics: Regex loop, no output

by AnomalousMonk (Archbishop)
on Nov 16, 2015 at 00:39 UTC ( [id://1147767]=note: print w/replies, xml ) Need Help??


in reply to Re: Bioinformatics: Regex loop, no output
in thread Bioinformatics: Regex loop, no output

As BrowserUk pointed out here, there is no  ! regex metacharacter/operator (presumably meaning "not-followed-by-the-following-pattern"). What is probably meant is  (?!pattern) (see Look-Around Assertions in perlre; also see perlretut).

This may be what TamaDP was looking for (there are some other good solutions):

c:\@Work\Perl\monks>perl -wMstrict -le "my @proteins = qw( DAAAAATTLTTTAMTTTTTTCKMMFRPPPPPGGGGGGGGGGGG ALTAMCMNVWEITYHKGSDVNRRASFAQPPPQPPPPLLAIKPASDASD AAAKAAA AAAKAAA XXXXXX ); ;; my @new_peptides; for my $protein (@proteins) { if ($protein =~ s{ (?<= [KR]) (?! P) }{=}xmsg) { push @new_peptides, split ('=', $protein); } } ;; for my $peptide (@new_peptides) { print qq{Peptide is '$peptide'}; } " Peptide is 'DAAAAATTLTTTAMTTTTTTCK' Peptide is 'MMFRPPPPPGGGGGGGGGGGG' Peptide is 'ALTAMCMNVWEITYHK' Peptide is 'GSDVNR' Peptide is 'R' Peptide is 'ASFAQPPPQPPPPLLAIKPASDASD' Peptide is 'AAAK' Peptide is 'AAA' Peptide is 'AAAK' Peptide is 'AAA'
Un-s///-ubstituted input proteins are not split and push-ed into the output array.

Yet another solution might be:

c:\@Work\Perl\monks>perl -wMstrict -le "my @proteins = qw( DAAAAATTLTTTAMTTTTTTCKMMFRPPPPPGGGGGGGGGGGG ALTAMCMNVWEITYHKGSDVNRRASFAQPPPQPPPPLLAIKPASDASD AAAKAAA AAAKAAA XXXXXX ); ;; my $cleave = qr{ (?<= [KR]) (?! P) }xms; ;; my @peptides = map split($cleave), grep m{ $cleave }xms, @proteins ; ;; print qq{Peptide is '$_'} for @peptides; " Peptide is 'DAAAAATTLTTTAMTTTTTTCK' Peptide is 'MMFRPPPPPGGGGGGGGGGGG' Peptide is 'ALTAMCMNVWEITYHK' Peptide is 'GSDVNR' Peptide is 'R' Peptide is 'ASFAQPPPQPPPPLLAIKPASDASD' Peptide is 'AAAK' Peptide is 'AAA' Peptide is 'AAAK' Peptide is 'AAA'
in which the central process might be documented (with the steps of the statement being taken right-to-left, bottom-to-top) as:
my @peptides = # 4. and the pieces are peptides. map split($cleave), # 3. split at each cleavage point... grep m{ $cleave }xms, # 2. that can be cleaved, ... @proteins # 1. for each protein... ;

Update: After sober consideration, I changed the code example above to its present form. The previous code contained
    my $cleave = qr{ [KR] (?! P) }xms;
    ...
      map  split(m{ (?<= $cleave) }xms),
      grep m{ $cleave }xms,
      ...
which doesn't really respect the DRY principle, which is what I was aiming to exemplify.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147767]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found